cleanup
This commit is contained in:
@@ -5,7 +5,7 @@ using Shogi.Api.Extensions;
|
|||||||
using Shogi.Api.Identity;
|
using Shogi.Api.Identity;
|
||||||
using Shogi.Api.Repositories;
|
using Shogi.Api.Repositories;
|
||||||
using Shogi.Api.Repositories.Dto;
|
using Shogi.Api.Repositories.Dto;
|
||||||
using Shogi.Contracts.Api;
|
using Shogi.Contracts.Api.Commands;
|
||||||
using Shogi.Domain.Aggregates;
|
using Shogi.Domain.Aggregates;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Shogi.Api.Application;
|
using Shogi.Api.Application;
|
||||||
using Shogi.Api.Extensions;
|
using Shogi.Api.Extensions;
|
||||||
using Shogi.Api.Repositories;
|
using Shogi.Api.Repositories;
|
||||||
using Shogi.Contracts.Api;
|
using Shogi.Contracts.Api.Commands;
|
||||||
using Shogi.Contracts.Types;
|
using Shogi.Contracts.Types;
|
||||||
|
|
||||||
namespace Shogi.Api.Controllers;
|
namespace Shogi.Api.Controllers;
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ public static class ContractsExtensions
|
|||||||
public static Dictionary<string, Piece?> ToContract(this ReadOnlyDictionary<string, Domain.ValueObjects.Piece?> boardState) =>
|
public static Dictionary<string, Piece?> ToContract(this ReadOnlyDictionary<string, Domain.ValueObjects.Piece?> boardState) =>
|
||||||
boardState.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToContract());
|
boardState.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToContract());
|
||||||
|
|
||||||
public static Domain.ValueObjects.WhichPiece? ToDomain(this WhichPiece? piece) => piece.HasValue ? piece.Value.ToDomain() : null;
|
|
||||||
public static Domain.ValueObjects.WhichPiece ToDomain(this WhichPiece piece)
|
public static Domain.ValueObjects.WhichPiece ToDomain(this WhichPiece piece)
|
||||||
{
|
{
|
||||||
return piece switch
|
return piece switch
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
using System.Net.WebSockets;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Shogi.Api.Extensions
|
|
||||||
{
|
|
||||||
public static class WebSocketExtensions
|
|
||||||
{
|
|
||||||
public static async Task SendTextAsync(this WebSocket self, string message)
|
|
||||||
{
|
|
||||||
await self.SendAsync(Encoding.UTF8.GetBytes(message), WebSocketMessageType.Text, true, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<string> ReceiveTextAsync(this WebSocket self)
|
|
||||||
{
|
|
||||||
var buffer = new ArraySegment<byte>(new byte[2048]);
|
|
||||||
var receive = await self.ReceiveAsync(buffer, CancellationToken.None);
|
|
||||||
return Encoding.UTF8.GetString(buffer.Slice(0, receive.Count));
|
|
||||||
// TODO: Make this robust to multi-frame messages.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Shogi.Api.Repositories.Dto;
|
using Shogi.Api.Repositories.Dto;
|
||||||
using Shogi.Contracts.Api;
|
using Shogi.Contracts.Api.Commands;
|
||||||
using Shogi.Domain.Aggregates;
|
using Shogi.Domain.Aggregates;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Shogi.Contracts.Api;
|
namespace Shogi.Contracts.Api.Commands;
|
||||||
|
|
||||||
public class MovePieceCommand : IValidatableObject
|
public partial class MovePieceCommand : IValidatableObject
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For serialization.
|
/// For serialization.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MovePieceCommand()
|
public MovePieceCommand()
|
||||||
{
|
{
|
||||||
this.To = string.Empty;
|
To = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -20,9 +20,9 @@ public class MovePieceCommand : IValidatableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MovePieceCommand(string from, string to, bool isPromotion)
|
public MovePieceCommand(string from, string to, bool isPromotion)
|
||||||
{
|
{
|
||||||
this.From = from;
|
From = from;
|
||||||
this.To = to;
|
To = to;
|
||||||
this.IsPromotion = isPromotion;
|
IsPromotion = isPromotion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,8 +30,8 @@ public class MovePieceCommand : IValidatableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MovePieceCommand(WhichPiece pieceFromHand, string to)
|
public MovePieceCommand(WhichPiece pieceFromHand, string to)
|
||||||
{
|
{
|
||||||
this.PieceFromHand = pieceFromHand;
|
PieceFromHand = pieceFromHand;
|
||||||
this.To = to;
|
To = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,7 +39,7 @@ public class MovePieceCommand : IValidatableObject
|
|||||||
/// Set this property to indicate moving a piece from the hand onto the board.
|
/// Set this property to indicate moving a piece from the hand onto the board.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WhichPiece? PieceFromHand { get; set; }
|
public WhichPiece? PieceFromHand { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Board position notation, like A3 or G1
|
/// Board position notation, like A3 or G1
|
||||||
/// Mutually exclusive with <see cref="PieceFromHand"/>.
|
/// Mutually exclusive with <see cref="PieceFromHand"/>.
|
||||||
@@ -52,26 +52,29 @@ public class MovePieceCommand : IValidatableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
[Required]
|
||||||
public string To { get; set; }
|
public string To { get; set; }
|
||||||
|
|
||||||
public bool? IsPromotion { get; set; }
|
public bool? IsPromotion { get; set; }
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
if (this.PieceFromHand.HasValue && !string.IsNullOrWhiteSpace(this.From))
|
if (PieceFromHand.HasValue && !string.IsNullOrWhiteSpace(From))
|
||||||
{
|
{
|
||||||
yield return new ValidationResult($"{nameof(this.PieceFromHand)} and {nameof(this.From)} are mutually exclusive properties.");
|
yield return new ValidationResult($"{nameof(PieceFromHand)} and {nameof(From)} are mutually exclusive properties.");
|
||||||
}
|
}
|
||||||
if (this.PieceFromHand.HasValue && this.IsPromotion.HasValue)
|
if (PieceFromHand.HasValue && IsPromotion.HasValue)
|
||||||
{
|
{
|
||||||
yield return new ValidationResult($"{nameof(this.PieceFromHand)} and {nameof(this.IsPromotion)} are mutually exclusive properties.");
|
yield return new ValidationResult($"{nameof(PieceFromHand)} and {nameof(IsPromotion)} are mutually exclusive properties.");
|
||||||
}
|
}
|
||||||
if (!Regex.IsMatch(this.To, "[A-I][1-9]"))
|
if (!BoardNotationRegex().IsMatch(To))
|
||||||
{
|
{
|
||||||
yield return new ValidationResult($"{nameof(this.To)} must be a valid board position, between A1 and I9");
|
yield return new ValidationResult($"{nameof(To)} must be a valid board position, between A1 and I9");
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(this.From) && !Regex.IsMatch(this.From, "[A-I][1-9]"))
|
if (!string.IsNullOrEmpty(From) && !BoardNotationRegex().IsMatch(From))
|
||||||
{
|
{
|
||||||
yield return new ValidationResult($"{nameof(this.From)} must be a valid board position, between A1 and I9");
|
yield return new ValidationResult($"{nameof(From)} must be a valid board position, between A1 and I9");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex("[A-I][1-9]")]
|
||||||
|
private static partial Regex BoardNotationRegex();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Session
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Email
|
/// Email
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Player1 { get; set; }
|
public string Player1 { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Email. Null if no second player exists.
|
/// Email. Null if no second player exists.
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Shogi.Contracts.Types
|
namespace Shogi.Contracts.Types;
|
||||||
|
|
||||||
|
public class SessionMetadata
|
||||||
{
|
{
|
||||||
public class SessionMetadata
|
public Guid SessionId { get; set; }
|
||||||
{
|
public string Player1 { get; set; } = string.Empty;
|
||||||
public Guid SessionId { get; set; }
|
public string Player2 { get; set; } = string.Empty;
|
||||||
public string Player1 { get; set; } = string.Empty;
|
|
||||||
public string Player2 { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
namespace Shogi.Contracts.Types
|
namespace Shogi.Contracts.Types;
|
||||||
|
|
||||||
|
public enum WhichPlayer
|
||||||
{
|
{
|
||||||
public enum WhichPlayer
|
Player1,
|
||||||
{
|
Player2
|
||||||
Player1,
|
|
||||||
Player2
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
namespace Shogi.Contracts.Types
|
namespace Shogi.Contracts.Types;
|
||||||
|
|
||||||
|
public enum WhichPiece
|
||||||
{
|
{
|
||||||
public enum WhichPiece
|
King,
|
||||||
{
|
GoldGeneral,
|
||||||
King,
|
SilverGeneral,
|
||||||
GoldGeneral,
|
Bishop,
|
||||||
SilverGeneral,
|
Rook,
|
||||||
Bishop,
|
Knight,
|
||||||
Rook,
|
Lance,
|
||||||
Knight,
|
Pawn
|
||||||
Lance,
|
|
||||||
Pawn
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Shogi.Contracts.Api;
|
using Shogi.Contracts.Api.Commands;
|
||||||
using Shogi.Contracts.Types;
|
using Shogi.Contracts.Types;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
|||||||
Reference in New Issue
Block a user