cleanup
This commit is contained in:
@@ -5,7 +5,7 @@ using Shogi.Api.Extensions;
|
||||
using Shogi.Api.Identity;
|
||||
using Shogi.Api.Repositories;
|
||||
using Shogi.Api.Repositories.Dto;
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Api.Commands;
|
||||
using Shogi.Domain.Aggregates;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Shogi.Api.Application;
|
||||
using Shogi.Api.Extensions;
|
||||
using Shogi.Api.Repositories;
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Api.Commands;
|
||||
using Shogi.Contracts.Types;
|
||||
|
||||
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) =>
|
||||
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)
|
||||
{
|
||||
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 Shogi.Api.Repositories.Dto;
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Api.Commands;
|
||||
using Shogi.Domain.Aggregates;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
@@ -3,16 +3,16 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Shogi.Contracts.Api;
|
||||
namespace Shogi.Contracts.Api.Commands;
|
||||
|
||||
public class MovePieceCommand : IValidatableObject
|
||||
public partial class MovePieceCommand : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// For serialization.
|
||||
/// </summary>
|
||||
public MovePieceCommand()
|
||||
{
|
||||
this.To = string.Empty;
|
||||
To = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -20,9 +20,9 @@ public class MovePieceCommand : IValidatableObject
|
||||
/// </summary>
|
||||
public MovePieceCommand(string from, string to, bool isPromotion)
|
||||
{
|
||||
this.From = from;
|
||||
this.To = to;
|
||||
this.IsPromotion = isPromotion;
|
||||
From = from;
|
||||
To = to;
|
||||
IsPromotion = isPromotion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -30,8 +30,8 @@ public class MovePieceCommand : IValidatableObject
|
||||
/// </summary>
|
||||
public MovePieceCommand(WhichPiece pieceFromHand, string to)
|
||||
{
|
||||
this.PieceFromHand = pieceFromHand;
|
||||
this.To = to;
|
||||
PieceFromHand = pieceFromHand;
|
||||
To = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,21 +57,24 @@ public class MovePieceCommand : IValidatableObject
|
||||
|
||||
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>
|
||||
/// Email
|
||||
/// </summary>
|
||||
public string Player1 { get; set; }
|
||||
public string Player1 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Email. Null if no second player exists.
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Shogi.Contracts.Types
|
||||
{
|
||||
namespace Shogi.Contracts.Types;
|
||||
|
||||
public class SessionMetadata
|
||||
{
|
||||
public Guid SessionId { get; set; }
|
||||
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
|
||||
{
|
||||
Player1,
|
||||
Player2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Shogi.Contracts.Types
|
||||
{
|
||||
namespace Shogi.Contracts.Types;
|
||||
|
||||
public enum WhichPiece
|
||||
{
|
||||
King,
|
||||
@@ -11,4 +11,3 @@
|
||||
Lance,
|
||||
Pawn
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Api.Commands;
|
||||
using Shogi.Contracts.Types;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
Reference in New Issue
Block a user