squash a bunch of commits

This commit is contained in:
2022-10-30 12:03:16 -05:00
parent 09b72c1858
commit 93027e8c57
222 changed files with 6157 additions and 3201 deletions

View 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();
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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 = "";
}
}
}

View 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!;
}
}
}

View 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;
}
}
}

View 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; }
}
}

View 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;
}
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,9 @@
namespace Shogi.Api.Repositories.CouchModels
{
public enum WhichDocumentType
{
User,
Session,
BoardState
}
}