This commit is contained in:
2018-10-04 20:56:40 +00:00
parent 179cc0a522
commit 7ea5c911aa
6 changed files with 24 additions and 18 deletions

View File

@@ -28,10 +28,6 @@ Once that is done then can steam ahead on the biz objects but until I have the c
IMMEDIATE ITEMS:
================
- Search and search text indexing
- Update all the other routes to include search indexing (attachments, tags, taggroup)
- see if any other callers to name fetcher are in tight loops and could benefit from using the new Direct version
- Schema: clean up all the LOOKAT items and verify the indexes are being used

View File

@@ -73,9 +73,7 @@ namespace AyaNova.Api.Controllers
public async Task<IActionResult> GetDownloadToken()
{
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
long lUserId = UserIdFromContext.Id(HttpContext.Items);
var u = await ct.User.FirstOrDefaultAsync(a => a.Id == lUserId);
@@ -127,22 +125,15 @@ namespace AyaNova.Api.Controllers
{
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
var returnList = new List<NameIdItem>();
try
{
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "FileUploadAttempt", $"Expected a multipart request, but got {Request.ContentType}"));
}
var uploadFormData = await ApiUploadProcessor.ProcessAttachmentUpload(HttpContext);
@@ -238,9 +229,13 @@ namespace AyaNova.Api.Controllers
Id = v.Id
});
//Log
//EVENT LOG
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
ct.SaveChanges();
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName, v.DisplayFileName, v.Notes, v.StoredFileName);
}
}
}
@@ -305,9 +300,13 @@ namespace AyaNova.Api.Controllers
//this handles removing the file if there are no refs left and also the db record for the attachment
FileUtil.deleteFileAttachment(dbObj, ct);
//Log
//Event log process delete
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct);
ct.SaveChanges();
//Delete search index
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.FileAttachment);
return NoContent();
}

View File

@@ -30,14 +30,15 @@ namespace AyaNova.Biz
Locale = 13,
UserOptions = 14,
TagGroup = 15,
TagGroupMap = 16
TagGroupMap = 16,
FileAttachment = 17
//NOTE: New objects added here need to also be added to the following classes:
//AyaNova.Biz.BizObjectExistsInDatabase
//AyaNova.Biz.BizObjectFactory
//AyaNova.Biz.BizRoles
//AyaNova.Biz.BizObjectNameFetcher
//AyaNova.Biz.BizObjectNameFetcher && BizObjectNameFetcherDIRECT
}

View File

@@ -43,6 +43,9 @@ namespace AyaNova.Biz
return ct.Tag.Any(m => m.Id == id);
case AyaType.TagGroup:
return ct.TagGroup.Any(m => m.Id == id);
case AyaType.FileAttachment:
return ct.FileAttachment.Any(m => m.Id == id);

View File

@@ -63,6 +63,8 @@ namespace AyaNova.Biz
return ct.Tag.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
case AyaType.TagGroup:
return ct.TagGroup.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
case AyaType.FileAttachment:
return ct.FileAttachment.AsNoTracking().Where(m => m.Id == id).Select(m => m.DisplayFileName).FirstOrDefault();
default:
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");

View File

@@ -28,6 +28,7 @@ namespace AyaNova.Biz
internal static string Name(AyaType aytype, long id, System.Data.Common.DbCommand cmd)
{
string TABLE = string.Empty;
string COLUMN = "name";
switch (aytype)
{
case AyaType.User:
@@ -42,10 +43,14 @@ namespace AyaNova.Biz
case AyaType.TagGroup:
TABLE = "ataggroup";
break;
case AyaType.FileAttachment:
TABLE = "afileattachment";
COLUMN = "displayfilename";
break;
default:
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
}
cmd.CommandText = $"SELECT m.name FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1";
cmd.CommandText = $"SELECT m.{COLUMN} FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1";
using (var dr = cmd.ExecuteReader())
return dr.Read() ? dr.GetString(0) : "UNKNOWN";
}