From bb1d2c491c23e0fec5c07d05b9c9f918f3bb126a Mon Sep 17 00:00:00 2001 From: Lucas Morgan Date: Sun, 1 Aug 2021 20:09:11 -0500 Subject: [PATCH] yep --- CouchDB/CouchDB.csproj | 4 ++- CouchDB/Selectors/CouchQuery.cs | 27 ------------------- CouchDB/Selectors/Equals.cs | 18 ------------- .../Controllers/GameController.cs | 2 +- .../Managers/GameboardManager.cs | 6 ++--- .../Repositories/GameboardRepository.cs | 8 ++++-- 6 files changed, 13 insertions(+), 52 deletions(-) delete mode 100644 CouchDB/Selectors/CouchQuery.cs delete mode 100644 CouchDB/Selectors/Equals.cs diff --git a/CouchDB/CouchDB.csproj b/CouchDB/CouchDB.csproj index 83f1b25..168228b 100644 --- a/CouchDB/CouchDB.csproj +++ b/CouchDB/CouchDB.csproj @@ -5,7 +5,9 @@ - + + + diff --git a/CouchDB/Selectors/CouchQuery.cs b/CouchDB/Selectors/CouchQuery.cs deleted file mode 100644 index 7bd7b29..0000000 --- a/CouchDB/Selectors/CouchQuery.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; - -namespace CouchDB.Selectors -{ - public class CouchQuery - { - public static CouchQuery Select => new(); - - private readonly List equals; - protected CouchQuery() - { - equals = new List(); - } - - public CouchQuery WithEqual(string key, string value) - { - equals.Add(new Equals(key, value)); - return this; - } - - public override string ToString() - { - var selector = string.Join(",", equals); - return $"{{ \"selector\": {selector}"; - } - } -} diff --git a/CouchDB/Selectors/Equals.cs b/CouchDB/Selectors/Equals.cs deleted file mode 100644 index 418f547..0000000 --- a/CouchDB/Selectors/Equals.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace CouchDB.Selectors -{ - public class Equals - { - private readonly string key; - private readonly string value; - internal Equals(string key, string value) - { - this.key = key; - this.value = value; - } - - public override string ToString() - { - return $"{{ \"{key}\": {{ \"$eq\": {value}}} }}"; - } - } -} diff --git a/Gameboard.ShogiUI.Sockets/Controllers/GameController.cs b/Gameboard.ShogiUI.Sockets/Controllers/GameController.cs index bb17546..57fb268 100644 --- a/Gameboard.ShogiUI.Sockets/Controllers/GameController.cs +++ b/Gameboard.ShogiUI.Sockets/Controllers/GameController.cs @@ -100,7 +100,7 @@ namespace Gameboard.ShogiUI.Sockets.Controllers PlayerName = user.Name, Move = moveModel.ToServiceModel() }, session.Player1, session.Player2); - return Ok(); + return Created(string.Empty, null); } throw new InvalidOperationException("Illegal move."); } diff --git a/Gameboard.ShogiUI.Sockets/Managers/GameboardManager.cs b/Gameboard.ShogiUI.Sockets/Managers/GameboardManager.cs index 17e3de1..365722f 100644 --- a/Gameboard.ShogiUI.Sockets/Managers/GameboardManager.cs +++ b/Gameboard.ShogiUI.Sockets/Managers/GameboardManager.cs @@ -34,11 +34,11 @@ namespace Gameboard.ShogiUI.Sockets.Managers while (count < MaxTries) { count++; - var clientId = $"Guest-{Guid.NewGuid()}"; - var isCreated = await repository.CreateGuestUser(clientId, webSessionId); + var userName = $"Guest-{Guid.NewGuid()}"; + var isCreated = await repository.CreateUser(new User(userName, webSessionId)); if (isCreated) { - return clientId; + return userName; } } throw new OperationCanceledException($"Failed to create guest user after {count} tries."); diff --git a/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs b/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs index c519e4f..fce2aaa 100644 --- a/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs +++ b/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs @@ -241,8 +241,12 @@ namespace Gameboard.ShogiUI.Sockets.Repositories logger.LogError(new InvalidOperationException(result.warning), result.warning); return null; } - - return new Models.User(result.docs.Single().Name); + var userDocument = result.docs.SingleOrDefault(); + if (userDocument != null) + { + return new Models.User(userDocument.Name); + } + return null; } } }