cleanup
This commit is contained in:
@@ -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>
|
||||
@@ -39,7 +39,7 @@ public class MovePieceCommand : IValidatableObject
|
||||
/// Set this property to indicate moving a piece from the hand onto the board.
|
||||
/// </summary>
|
||||
public WhichPiece? PieceFromHand { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Board position notation, like A3 or G1
|
||||
/// Mutually exclusive with <see cref="PieceFromHand"/>.
|
||||
@@ -52,26 +52,29 @@ public class MovePieceCommand : IValidatableObject
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string To { get; set; }
|
||||
|
||||
|
||||
public bool? IsPromotion { get; set; }
|
||||
|
||||
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 class SessionMetadata
|
||||
{
|
||||
public Guid SessionId { get; set; }
|
||||
public string Player1 { get; set; } = string.Empty;
|
||||
public string Player2 { get; set; } = string.Empty;
|
||||
}
|
||||
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
|
||||
{
|
||||
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,
|
||||
SilverGeneral,
|
||||
Bishop,
|
||||
Rook,
|
||||
Knight,
|
||||
Lance,
|
||||
Pawn
|
||||
}
|
||||
King,
|
||||
GoldGeneral,
|
||||
SilverGeneral,
|
||||
Bishop,
|
||||
Rook,
|
||||
Knight,
|
||||
Lance,
|
||||
Pawn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user