This commit is contained in:
2020-12-15 01:25:55 +00:00
parent 10c168006f
commit 9c65341b49
4 changed files with 66 additions and 40 deletions

View File

@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using AyaNova.Models; using AyaNova.Models;
using AyaNova.Api.ControllerHelpers; using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
@@ -43,7 +45,7 @@ namespace AyaNova.Api.Controllers
/// <param name="apiVersion">From route path</param> /// <param name="apiVersion">From route path</param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<IActionResult> PostMemo([FromBody] Memo newObject, ApiVersion apiVersion) public async Task<IActionResult> PostMemo([FromBody] SendMemo newObject, ApiVersion apiVersion)
{ {
if (!serverState.IsOpen) if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -52,13 +54,36 @@ namespace AyaNova.Api.Controllers
return StatusCode(403, new ApiNotAuthorizedResponse()); return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
Memo o = await biz.CreateAsync(newObject); var RouteUserId = UserIdFromContext.Id(HttpContext.Items);
if (o == null) foreach (long lUserId in newObject.Users)
return BadRequest(new ApiErrorResponse(biz.Errors)); {
else Memo newMemo = new Memo();
return CreatedAtAction(nameof(MemoController.GetMemo), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o)); AyaNova.Util.CopyObject.Copy(newObject.Memo, newMemo);
newMemo.ToId = lUserId;
newMemo.FromId = RouteUserId;
Memo o = await biz.CreateAsync(newMemo);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
}
//return nothing but ok
return Accepted();
} }
public class SendMemo
{
public SendMemo()
{
Users = new List<long>();
}
[Required]
public Memo Memo { get; set; }
[Required]
public List<long> Users { get; set; }
}
//------------
//NO DUPLICATING MEMOS //NO DUPLICATING MEMOS
// /// <summary> // /// <summary>

View File

@@ -8,7 +8,6 @@ using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;

View File

@@ -396,7 +396,7 @@ namespace AyaNova.Api.Controllers
ApiUploadProcessor.DeleteTempUploadFile(uploadFormData); ApiUploadProcessor.DeleteTempUploadFile(uploadFormData);
} }
//Return the list of attachment ids and filenames //Return nothing
return Accepted(); return Accepted();
} }

View File

@@ -60,38 +60,40 @@ namespace AyaNova.Biz
} }
} }
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE
// // ////////////////////////////////////////////////////////////////////////////////////////////////
internal async Task<Memo> DuplicateAsync(long id) // //DUPLICATE
{ // //
Memo dbObject = await GetAsync(id, false); // internal async Task<Memo> DuplicateAsync(long id)
if (dbObject == null) // {
{ // Memo dbObject = await GetAsync(id, false);
AddError(ApiErrorCode.NOT_FOUND, "id"); // if (dbObject == null)
return null; // {
} // AddError(ApiErrorCode.NOT_FOUND, "id");
Memo newObject = new Memo(); // return null;
CopyObject.Copy(dbObject, newObject, "Wiki"); // }
string newUniqueName = string.Empty; // Memo newObject = new Memo();
bool NotUnique = true; // CopyObject.Copy(dbObject, newObject, "Wiki");
long l = 1; // string newUniqueName = string.Empty;
do // bool NotUnique = true;
{ // long l = 1;
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255); // do
NotUnique = await ct.Memo.AnyAsync(m => m.Name == newUniqueName); // {
} while (NotUnique); // newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
newObject.Name = newUniqueName; // NotUnique = await ct.Memo.AnyAsync(m => m.Name == newUniqueName);
newObject.Id = 0; // } while (NotUnique);
newObject.Concurrency = 0; // newObject.Name = newUniqueName;
await ct.Memo.AddAsync(newObject); // newObject.Id = 0;
await ct.SaveChangesAsync(); // newObject.Concurrency = 0;
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); // await ct.Memo.AddAsync(newObject);
await SearchIndexAsync(newObject, true); // await ct.SaveChangesAsync();
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject); // await SearchIndexAsync(newObject, true);
return newObject; // await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
} // await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
// return newObject;
// }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//GET //GET