This commit is contained in:
2020-05-14 14:35:37 +00:00
parent 848b5afc53
commit 0333db82f2
4 changed files with 46 additions and 5 deletions

View File

@@ -2,7 +2,8 @@ PRIORITY - ALWAYS Lowest level stuff first
=-=-=-=- =-=-=-=-
todo: switch to Identity column from serial column as it's the proper way to do autoid in postgres now todo: switch to Identity column from serial column as it's the proper way to do autoid in postgres now
todo: uint isn't very big, maybe I should use long in it's place everywhere (concurrency token??)
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types
todo: AUTO ID GENERATOR todo: AUTO ID GENERATOR
change to a dedicated spot in global rather than inferring as it is not right practically for reasons change to a dedicated spot in global rather than inferring as it is not right practically for reasons
Get the auto-id most recent values at boot time Get the auto-id most recent values at boot time

View File

@@ -157,6 +157,30 @@ namespace AyaNova.Api.Controllers
} }
/// <summary>
/// Reset serial number
///
/// </summary>
/// <param name="newSerial">Next starting value for auto generated serial numbers</param>
/// <param name="apiVersion">From route path</param>
/// <returns>Widget</returns>
[HttpPost("reset-serial/{newSerial}")]
public async Task<IActionResult> ResetSerial([FromRoute] long newSerial, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
bool result=await biz.ResetSerial(newSerial);
if (!result)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return NoContent();
}
/////////////////////////////////////////////// ///////////////////////////////////////////////
//TEST ROUTES //TEST ROUTES
// //

View File

@@ -170,6 +170,22 @@ namespace AyaNova.Biz
} }
} }
////////////////////////////////////////////////////////////////////////////////////////////////
//RESET SERIAL
//
internal async Task<bool> ResetSerial(long newSerial)
{
await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.ResetSerial,newSerial.ToString()), ct);
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//SEARCH //SEARCH
// //

View File

@@ -229,8 +229,8 @@ namespace AyaNova.Util
//query for most recently used serial number //query for most recently used serial number
//(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time //(note, can't query for highest serial as it can and likely will reset or be changed manually from time to time
// so the algorithm is to keep the most recent sequence going on startup of the server) // so the algorithm is to keep the most recent sequence going on startup of the server)
var serializedObject = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault(); // var serializedObject = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault();
WIDGET_SERIAL = new AutoId(serializedObject == null ? 0 : serializedObject.Serial); // WIDGET_SERIAL = new AutoId(serializedObject == null ? 0 : serializedObject.Serial);
// var MostRecentWidget = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault(); // var MostRecentWidget = ct.Widget.AsNoTracking().OrderByDescending(x => x.Id).FirstOrDefault();
// uint MaxWidgetId = 0; // uint MaxWidgetId = 0;