From 56e0a38b2ca246e8beeaef3c6c4b9c0ce7d0f09b Mon Sep 17 00:00:00 2001 From: vnugent Date: Tue, 9 Apr 2024 17:35:13 -0400 Subject: chore(app): Update deps, login spinner, curl msg, view prep --- back-end/src/Endpoints/BookmarkEndpoint.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'back-end/src/Endpoints') diff --git a/back-end/src/Endpoints/BookmarkEndpoint.cs b/back-end/src/Endpoints/BookmarkEndpoint.cs index 001a41b..19f5118 100644 --- a/back-end/src/Endpoints/BookmarkEndpoint.cs +++ b/back-end/src/Endpoints/BookmarkEndpoint.cs @@ -243,20 +243,26 @@ namespace SimpleBookmark.Endpoints return VirtualClose(entity, webm, HttpStatusCode.UnprocessableEntity); } - //See if the uses has reached their quota - long count = await Bookmarks.GetUserRecordCountAsync(entity.Session.UserID, entity.EventCancellation); + /* + * Add the new entry to the database if the user is below their quota + * and the entry does not already exist by the desired url. + */ + int result = await Bookmarks.AddSingleIfNotExists( + entity.Session.UserID, + newBookmark, + entity.RequestedTimeUtc.DateTime, + BmConfig.PerPersonQuota, + entity.EventCancellation + ); - if(webm.Assert(count <= BmConfig.PerPersonQuota, "You have reached your bookmark quota")) + if (webm.Assert(result > -1, "You have reached your bookmark quota")) { - return VirtualClose(entity, webm, HttpStatusCode.OK); - } - - //Try to create the record - ERRNO result = await Bookmarks.CreateUserRecordAsync(newBookmark, entity.Session.UserID, entity.EventCancellation); + return VirtualOk(entity, webm); + } - if (webm.Assert(result > 0, "Failed to create new bookmark")) + if (webm.Assert(result > 0, "Bookmark with the same url alreay exists")) { - return VirtualClose(entity, webm, HttpStatusCode.OK); + return VirtualOk(entity, webm); } webm.Result = "Successfully created bookmark"; -- cgit