squash a bunch of commits
This commit is contained in:
49
Shogi.Sockets/Repositories/CouchModels/BoardStateDocument.cs
Normal file
49
Shogi.Sockets/Repositories/CouchModels/BoardStateDocument.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Shogi.Domain;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class BoardStateDocument : CouchDocument
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A dictionary where the key is a board-notation position, like D3.
|
||||
/// </summary>
|
||||
public Dictionary<string, Piece?> Board { get; set; }
|
||||
|
||||
public Piece[] Player1Hand { get; set; }
|
||||
|
||||
public Piece[] Player2Hand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Move is null for first BoardState of a session - before anybody has made moves.
|
||||
/// </summary>
|
||||
public Move? Move { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor and setters are for deserialization.
|
||||
/// </summary>
|
||||
public BoardStateDocument() : base(WhichDocumentType.BoardState)
|
||||
{
|
||||
Name = string.Empty;
|
||||
Board = new Dictionary<string, Piece?>(81, StringComparer.OrdinalIgnoreCase);
|
||||
Player1Hand = Array.Empty<Piece>();
|
||||
Player2Hand = Array.Empty<Piece>();
|
||||
}
|
||||
|
||||
public BoardStateDocument(string sessionName, Session shogi)
|
||||
: base($"{sessionName}-{DateTime.Now:O}", WhichDocumentType.BoardState)
|
||||
{
|
||||
static Piece MapPiece(Domain.ValueObjects.Piece piece)
|
||||
{
|
||||
return new Piece { IsPromoted = piece.IsPromoted, Owner = piece.Owner, WhichPiece = piece.WhichPiece };
|
||||
}
|
||||
|
||||
Name = sessionName;
|
||||
Board = shogi.BoardState.State.ToDictionary(kvp => kvp.Key, kvp => kvp.Value == null ? null : MapPiece(kvp.Value));
|
||||
|
||||
Player1Hand = shogi.BoardState.Player1Hand.Select(piece => MapPiece(piece)).ToArray();
|
||||
Player2Hand = shogi.BoardState.Player2Hand.Select(piece => MapPiece(piece)).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Shogi.Sockets/Repositories/CouchModels/CouchCreatedResult.cs
Normal file
15
Shogi.Sockets/Repositories/CouchModels/CouchCreatedResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class CouchCreateResult
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public bool Ok { get; set; }
|
||||
public string Rev { get; set; }
|
||||
|
||||
public CouchCreateResult()
|
||||
{
|
||||
Id = string.Empty;
|
||||
Rev = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Shogi.Sockets/Repositories/CouchModels/CouchDocument.cs
Normal file
26
Shogi.Sockets/Repositories/CouchModels/CouchDocument.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Shogi.Api.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; }
|
||||
|
||||
public CouchDocument(WhichDocumentType documentType)
|
||||
: this(string.Empty, documentType, DateTimeOffset.UtcNow) { }
|
||||
|
||||
public CouchDocument(string id, WhichDocumentType documentType)
|
||||
: this(id, documentType, DateTimeOffset.UtcNow) { }
|
||||
|
||||
public CouchDocument(string id, WhichDocumentType documentType, DateTimeOffset createdDate)
|
||||
{
|
||||
Id = id;
|
||||
DocumentType = documentType;
|
||||
CreatedDate = createdDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Shogi.Sockets/Repositories/CouchModels/CouchFindResult.cs
Normal file
16
Shogi.Sockets/Repositories/CouchModels/CouchFindResult.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
internal class CouchFindResult<T>
|
||||
{
|
||||
public T[] docs;
|
||||
public string warning;
|
||||
|
||||
public CouchFindResult()
|
||||
{
|
||||
docs = Array.Empty<T>();
|
||||
warning = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Shogi.Sockets/Repositories/CouchModels/CouchViewResult.cs
Normal file
28
Shogi.Sockets/Repositories/CouchModels/CouchViewResult.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace Shogi.Api.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!;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Shogi.Sockets/Repositories/CouchModels/Move.cs
Normal file
32
Shogi.Sockets/Repositories/CouchModels/Move.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Shogi.Domain;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class Move
|
||||
{
|
||||
/// <summary>
|
||||
/// A board coordinate, like A3 or G6. When null, look for PieceFromHand to exist.
|
||||
/// </summary>
|
||||
public string? From { get; set; }
|
||||
|
||||
public bool IsPromotion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The piece placed from the player's hand.
|
||||
/// </summary>
|
||||
public WhichPiece? PieceFromHand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A board coordinate, like A3 or G6.
|
||||
/// </summary>
|
||||
public string To { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor and setters are for deserialization.
|
||||
/// </summary>
|
||||
public Move()
|
||||
{
|
||||
To = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Shogi.Sockets/Repositories/CouchModels/Piece.cs
Normal file
11
Shogi.Sockets/Repositories/CouchModels/Piece.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Shogi.Domain;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class Piece
|
||||
{
|
||||
public bool IsPromoted { get; set; }
|
||||
public WhichPlayer Owner { get; set; }
|
||||
public WhichPiece WhichPiece { get; set; }
|
||||
}
|
||||
}
|
||||
28
Shogi.Sockets/Repositories/CouchModels/SessionDocument.cs
Normal file
28
Shogi.Sockets/Repositories/CouchModels/SessionDocument.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Shogi.Contracts.Types;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class SessionDocument : CouchDocument
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Player1Id { get; set; }
|
||||
public string? Player2Id { get; set; }
|
||||
public bool IsPrivate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor and setters are for deserialization.
|
||||
/// </summary>
|
||||
public SessionDocument() : base(WhichDocumentType.Session)
|
||||
{
|
||||
Name = string.Empty;
|
||||
Player1Id = string.Empty;
|
||||
Player2Id = string.Empty;
|
||||
}
|
||||
|
||||
public SessionDocument(SessionMetadata sessionMetaData)
|
||||
: base(sessionMetaData.Name, WhichDocumentType.Session)
|
||||
{
|
||||
Name = sessionMetaData.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Shogi.Sockets/Repositories/CouchModels/UserDocument.cs
Normal file
27
Shogi.Sockets/Repositories/CouchModels/UserDocument.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Shogi.Api.Models;
|
||||
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public class UserDocument : CouchDocument
|
||||
{
|
||||
public string DisplayName { get; set; }
|
||||
public WhichLoginPlatform Platform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for JSON deserializing.
|
||||
/// </summary>
|
||||
public UserDocument() : base(WhichDocumentType.User)
|
||||
{
|
||||
DisplayName = string.Empty;
|
||||
}
|
||||
|
||||
public UserDocument(
|
||||
string id,
|
||||
string displayName,
|
||||
WhichLoginPlatform platform) : base(id, WhichDocumentType.User)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
Platform = platform;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Shogi.Api.Repositories.CouchModels
|
||||
{
|
||||
public enum WhichDocumentType
|
||||
{
|
||||
User,
|
||||
Session,
|
||||
BoardState
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user