This commit is contained in:
15
server/AyaNova/ControllerHelpers/LocaleIdFromContext.cs
Normal file
15
server/AyaNova/ControllerHelpers/LocaleIdFromContext.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
internal static class LocaleIdFromContext
|
||||
{
|
||||
internal static long Id(IDictionary<object, object> HttpContextItems)
|
||||
{
|
||||
long? l = (long?)HttpContextItems["AY_LOCALE_ID"];
|
||||
if (l == null)
|
||||
return AyaNova.Util.ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
return (long)l;
|
||||
}
|
||||
}
|
||||
}//eons
|
||||
@@ -1,10 +1,7 @@
|
||||
using EnumsNET;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
|
||||
|
||||
internal static class UserIdFromContext
|
||||
{
|
||||
internal static long Id(IDictionary<object, object> HttpContextItems)
|
||||
@@ -16,6 +13,4 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
return (long)l;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}//eons
|
||||
@@ -210,6 +210,7 @@ namespace AyaNova.Api.Controllers
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
||||
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -286,6 +287,7 @@ namespace AyaNova.Api.Controllers
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
||||
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -300,9 +302,6 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||
}
|
||||
|
||||
@@ -353,6 +352,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//Log now that we have the Id
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
|
||||
Search.ProcessNewObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//return success and link
|
||||
@@ -406,7 +406,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//Log
|
||||
EventLogProcessor.DeleteObject(biz.userId, AyaType.Widget, dbObj.Id, dbObj.Name, ct);
|
||||
|
||||
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.Widget);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Delete children / attached objects
|
||||
|
||||
@@ -21,10 +21,28 @@ namespace AyaNova.Biz
|
||||
//ProcessKeywords into database
|
||||
|
||||
#region ProcessKeywords into Database
|
||||
|
||||
public static void ProcessNewObjectKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, string name, params string[] text)
|
||||
{
|
||||
ProcessKeywords(ct, localeId, objectID, objectType, true, name, text);
|
||||
}
|
||||
|
||||
public static void ProcessUpdatedObjectKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, string name, params string[] text)
|
||||
{
|
||||
ProcessKeywords(ct, localeId, objectID, objectType, false, name, text);
|
||||
}
|
||||
|
||||
public static void ProcessDeletedObjectKeywords(AyContext ct, long objectID, AyaType objectType)
|
||||
{
|
||||
throw new System.NotImplementedException("Search::ProcessDeletedObjectKeywords NOT CODED YET");
|
||||
//ProcessKeywords(ct, localeId, objectID, objectType, false, name, text);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Process the keywords into the dictionary
|
||||
/// </summary>
|
||||
public static void ProcessKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, bool newRecord, string keyWords, string name)
|
||||
private static void ProcessKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, bool newRecord, string name, params string[] text)
|
||||
{
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace AyaNova.Biz
|
||||
//do stuff with widget
|
||||
Widget outObj = inObj;
|
||||
outObj.OwnerId = userId;
|
||||
//SearchHelper(break down text fields, save to db)
|
||||
|
||||
//TagHelper(collection of tags??)
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
return outObj;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AyaNova.Models
|
||||
public AuthorizationRoles Roles { get; set; }
|
||||
public DateTime? StartDate { get; set; }
|
||||
public DateTime? EndDate { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.Util
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
|
||||
private const int DESIRED_SCHEMA_LEVEL = 9;
|
||||
|
||||
internal const long EXPECTED_COLUMN_COUNT = 98;
|
||||
internal const long EXPECTED_COLUMN_COUNT = 99;
|
||||
internal const long EXPECTED_INDEX_COUNT = 20;
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace AyaNova.Util
|
||||
//too little is bad if search takes a dogs age to find anything
|
||||
|
||||
exec("CREATE TABLE asearchdictionary (id BIGSERIAL PRIMARY KEY, word varchar(255) not null)");
|
||||
// exec("CREATE UNIQUE INDEX tagname_idx ON atag (name);");
|
||||
// exec("CREATE UNIQUE INDEX tagname_idx ON atag (name);");
|
||||
exec("CREATE TABLE asearchkey (id BIGSERIAL PRIMARY KEY, wordid bigint not null REFERENCES asearchdictionary (id), objectid bigint not null, objecttype integer not null, inname bool not null)");
|
||||
|
||||
//create locale text tables
|
||||
@@ -190,7 +190,7 @@ namespace AyaNova.Util
|
||||
//Add widget table
|
||||
//id, text, longtext, boolean, currency,
|
||||
exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null, " +
|
||||
"startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4)");
|
||||
"startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, notes text)");
|
||||
|
||||
setSchemaLevel(++currentSchema);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace raven_integration
|
||||
|
||||
public class WidgetCrud
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test all CRUD routes for a widget
|
||||
/// </summary>
|
||||
@@ -30,6 +30,7 @@ namespace raven_integration
|
||||
w1.dollarAmount = 1.11m;
|
||||
w1.active = true;
|
||||
w1.roles = 0;
|
||||
w1.notes = "The quick brown fox jumped over the six lazy dogs!";
|
||||
|
||||
ApiResponse r1 = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w1.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r1);
|
||||
@@ -41,8 +42,9 @@ namespace raven_integration
|
||||
w2.dollarAmount = 2.22m;
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
w2.notes = "What is the frequency Kenneth?";
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
|
||||
@@ -50,9 +52,11 @@ namespace raven_integration
|
||||
//RETRIEVE
|
||||
|
||||
//Get one
|
||||
ApiResponse r3 = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse r3 = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateDataReturnResponseOk(r3);
|
||||
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
r3.ObjectResponse["result"]["notes"].Value<string>().Should().Be(w2.notes.ToString());
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -63,11 +67,11 @@ namespace raven_integration
|
||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST WIDGET");
|
||||
w2.OwnerId = 1;
|
||||
w2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||
|
||||
//check PUT worked
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse checkPUTWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
||||
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
@@ -75,21 +79,21 @@ namespace raven_integration
|
||||
//PATCH
|
||||
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST WIDGET");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
||||
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
||||
|
||||
//check PATCH worked
|
||||
ApiResponse checkPATCHWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse checkPATCHWorked = await Util.GetAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
||||
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
|
||||
|
||||
//DELETE
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +105,7 @@ namespace raven_integration
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 404, api error code 2010
|
||||
ApiResponse a = await Util.GetAsync("Widget/999999", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse a = await Util.GetAsync("Widget/999999", await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateResponseNotFound(a);
|
||||
}
|
||||
|
||||
@@ -113,7 +117,7 @@ namespace raven_integration
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("Widget/2q2", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse a = await Util.GetAsync("Widget/2q2", await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateBadModelStateResponse(a, "id");
|
||||
}
|
||||
|
||||
@@ -126,7 +130,7 @@ namespace raven_integration
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("Widget/exception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse a = await Util.GetAsync("Widget/exception", await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
@@ -140,7 +144,7 @@ namespace raven_integration
|
||||
{
|
||||
//Get non existant
|
||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
||||
ApiResponse a = await Util.GetAsync("Widget/altexception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
||||
ApiResponse a = await Util.GetAsync("Widget/altexception", await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||
Util.ValidateServerExceptionResponse(a);
|
||||
}
|
||||
|
||||
@@ -162,7 +166,7 @@ namespace raven_integration
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
@@ -175,7 +179,7 @@ namespace raven_integration
|
||||
w2.name = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATE VIA PUT ");
|
||||
w2.OwnerId = 1;
|
||||
w2.concurrencyToken = OriginalConcurrencyToken - 1;//bad token
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
ApiResponse PUTTestResponse = await Util.PutAsync("Widget/" + w2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateConcurrencyError(PUTTestResponse);
|
||||
|
||||
|
||||
@@ -199,7 +203,7 @@ namespace raven_integration
|
||||
w2.active = true;
|
||||
w2.roles = 0;
|
||||
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
||||
ApiResponse r2 = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w2.ToString());
|
||||
Util.ValidateDataReturnResponseOk(r2);
|
||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||
uint OriginalConcurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||
@@ -208,7 +212,7 @@ namespace raven_integration
|
||||
//PATCH
|
||||
var newName = Util.Uniquify("PutConcurrencyViolationShouldFail UPDATED VIA PATCH");
|
||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("Widget/" + w2Id.ToString() + "/" + (OriginalConcurrencyToken - 1).ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
||||
Util.ValidateConcurrencyError(PATCHTestResponse);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user