diff options
author | vnugent <public@vaughnnugent.com> | 2024-04-09 17:35:13 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-04-09 17:35:13 -0400 |
commit | 56e0a38b2ca246e8beeaef3c6c4b9c0ce7d0f09b (patch) | |
tree | 5ba2556e42510cbbdf9c287f67041c1b1eb46206 /back-end/src/Endpoints/BookmarkEndpoint.cs | |
parent | 0945210c0492dd8a8de99ccd8e5e66cf05e3a1c1 (diff) |
chore(app): Update deps, login spinner, curl msg, view prep
Diffstat (limited to 'back-end/src/Endpoints/BookmarkEndpoint.cs')
-rw-r--r-- | back-end/src/Endpoints/BookmarkEndpoint.cs | 26 |
1 files changed, 16 insertions, 10 deletions
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"; |