checkpoint

This commit is contained in:
2021-11-10 18:46:29 -06:00
parent 2a3b7b32b4
commit 20f44c8b90
26 changed files with 519 additions and 407 deletions

View File

@@ -1,5 +1,4 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using Gameboard.ShogiUI.Sockets.Utilities;
using Gameboard.ShogiUI.Sockets.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@@ -6,6 +6,7 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
public abstract class CouchDocument
{
[JsonProperty("_id")] public string Id { get; set; }
[JsonProperty("_rev")] public string? RevisionId { get; set; }
public WhichDocumentType DocumentType { get; }
public DateTimeOffset CreatedDate { get; set; }

View File

@@ -0,0 +1,28 @@
using System;
namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
{
public class CouchViewResult<T> where T : class
{
public int total_rows;
public int offset;
public CouchViewResultRow<T>[] rows;
public CouchViewResult()
{
rows = Array.Empty<CouchViewResultRow<T>>();
}
}
public class CouchViewResultRow<T>
{
public string id;
public T doc;
public CouchViewResultRow()
{
id = string.Empty;
doc = default!;
}
}
}

View File

@@ -5,8 +5,8 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
public class SessionDocument : CouchDocument
{
public string Name { get; set; }
public string Player1 { get; set; }
public string? Player2 { get; set; }
public string Player1Id { get; set; }
public string? Player2Id { get; set; }
public bool IsPrivate { get; set; }
public IList<BoardStateDocument> History { get; set; }
@@ -16,8 +16,8 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
public SessionDocument() : base(WhichDocumentType.Session)
{
Name = string.Empty;
Player1 = string.Empty;
Player2 = string.Empty;
Player1Id = string.Empty;
Player2Id = string.Empty;
History = new List<BoardStateDocument>(0);
}
@@ -25,8 +25,8 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
: base(session.Name, WhichDocumentType.Session)
{
Name = session.Name;
Player1 = session.Player1;
Player2 = session.Player2;
Player1Id = session.Player1.Id;
Player2Id = session.Player2?.Id;
IsPrivate = session.IsPrivate;
History = new List<BoardStateDocument>(0);
}
@@ -35,14 +35,10 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
: base(sessionMetaData.Name, WhichDocumentType.Session)
{
Name = sessionMetaData.Name;
Player1 = sessionMetaData.Player1;
Player2 = sessionMetaData.Player2;
Player1Id = sessionMetaData.Player1.Id;
Player2Id = sessionMetaData.Player2?.Id;
IsPrivate = sessionMetaData.IsPrivate;
History = new List<BoardStateDocument>(0);
}
public Models.Session ToDomainModel(Models.Shogi shogi) => new(Name, IsPrivate, shogi, Player1, Player2);
public Models.SessionMetadata ToDomainModel() => new(Name, IsPrivate, Player1, Player2);
}
}

View File

@@ -1,34 +1,27 @@
using Gameboard.ShogiUI.Sockets.Models;
using System;
namespace Gameboard.ShogiUI.Sockets.Repositories.CouchModels
{
public class UserDocument : CouchDocument
{
public string Name { get; set; }
public string DisplayName { get; set; }
public WhichLoginPlatform Platform { get; set; }
/// <summary>
/// The browser session ID saved via Set-Cookie headers.
/// Only used with guest accounts.
/// </summary>
public Guid? WebSessionId { get; set; }
/// <summary>
/// Constructor for JSON deserializing.
/// </summary>
public UserDocument() : base(WhichDocumentType.User)
{
Name = string.Empty;
DisplayName = string.Empty;
}
public UserDocument(string name, Guid? webSessionId = null) : base($"org.couchdb.user:{name}", WhichDocumentType.User)
public UserDocument(
string id,
string displayName,
WhichLoginPlatform platform) : base(id, WhichDocumentType.User)
{
Name = name;
WebSessionId = webSessionId;
Platform = WebSessionId.HasValue
? WhichLoginPlatform.Guest
: WhichLoginPlatform.Microsoft;
DisplayName = displayName;
Platform = platform;
}
}
}