Skip to content

Commit

Permalink
Merge pull request #44 from spacecowboy-app/fix-nullable-issues/1
Browse files Browse the repository at this point in the history
Fix remaining issues after enabling nullability support
  • Loading branch information
rolfmichelsen committed Aug 26, 2023
2 parents 5f7d7d8 + 924c587 commit a50fccb
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 219 deletions.
18 changes: 12 additions & 6 deletions service/src/Controllers/DTO/AddDeckRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,43 @@
limitations under the License.
*/

using System.ComponentModel.DataAnnotations;

namespace Spacecowboy.Service.Controllers.DTO
{
/// <summary>
/// Add a deck of cards to a session
/// </summary>
public class AddDeckRequest
public record AddDeckRequest
{
/// <summary>
/// Cards in this deck
/// </summary>
public CreateCardRequest[] Cards { get; set; }
[Required]
public required CreateCardRequest[] Cards { get; init; }

/// <summary>
/// A card used when no vote has been cast
/// </summary>
public CreateCardRequest NoVote { get; set; }
[Required]
public required CreateCardRequest NoVote { get; init; }

/// <summary>
/// A card representing a vote that has not yet been revealed
/// </summary>
public CreateCardRequest NotRevealed { get; set; }
[Required]
public required CreateCardRequest NotRevealed { get; init; }

/// <summary>
/// The name of the deck
/// </summary>
public string Name { get; set; }
[Required]
public required string Name { get; init; }

/// <summary>
/// The type of deck
/// </summary>
public string Type { get; set; }
[Required]
public required string Type { get; init; }
}
}
11 changes: 6 additions & 5 deletions service/src/Controllers/DTO/CardResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Spacecowboy.Service.Controllers.DTO
/// <summary>
/// A card that can be used for casing a vote
/// </summary>
// TODO Convert this class to a record.
public class CardResponse
{
/// <summary>
Expand All @@ -33,28 +34,28 @@ public class CardResponse
/// <summary>
/// Card value
/// </summary>
public string Value { get; set; }
public string? Value { get; set; }

/// <summary>
/// Reference to an image representing the card
/// </summary>
public string Image { get; set; }
public string? Image { get; set; }

/// <summary>
/// Reference to a color for the card
/// </summary>
public string Color { get; set; }
public string? Color { get; set; }

/// <summary>
/// Reference to card font
/// </summary>
public string Font { get; set; }
public string? Font { get; set; }


/// <summary>
/// Card style identifier
/// </summary>
public string Style { get; set; }
public string? Style { get; set; }

/// <summary>
/// Default constructor
Expand Down
12 changes: 6 additions & 6 deletions service/src/Controllers/DTO/CreateCardRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ namespace Spacecowboy.Service.Controllers.DTO
/// <summary>
/// Create a card in a session
/// </summary>
public class CreateCardRequest
public record CreateCardRequest
{
/// <summary>
/// Card value
/// </summary>
public string Value { get; set; }
public string? Value { get; init; }

/// <summary>
/// Reference to an image representing the card
/// </summary>
public string Image { get; set; }
public string? Image { get; init; }

/// <summary>
/// Reference to a color for the card
/// </summary>
public string Color { get; set; }
public string? Color { get; init; }

/// <summary>
/// Reference to a font for the card
/// </summary>
public string Font { get; set; }
public string? Font { get; init; }

/// <summary>
/// Card style identifier
/// </summary>
public string Style { get; set; }
public string? Style { get; init; }
}
}
8 changes: 4 additions & 4 deletions service/src/Controllers/DTO/CreateParticipantRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Spacecowboy.Service.Controllers.DTO
{
public class CreateParticipantRequest
public record CreateParticipantRequest
{
/// <summary>
/// Participant name
Expand All @@ -29,7 +29,7 @@ public class CreateParticipantRequest
/// displayed nick or name associated with the participant.
/// </remarks>
[Required]
public string Name { get; set; }
public required string Name { get; init; }


/// <summary>
Expand All @@ -39,13 +39,13 @@ public class CreateParticipantRequest
/// The service does not use this property for anything. It is intended for the client to use as a reference to
/// the participant's avatar. It is up to the client to define the format of this reference.
/// </remarks>
public string Avatar { get; set; }
public string? Avatar { get; init; }


/// <summary>
/// Avatar color
/// </summary>
public string Color { get; set; }
public string? Color { get; init; }

}
}
17 changes: 9 additions & 8 deletions service/src/Controllers/DTO/CreateSessionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,35 @@ namespace Spacecowboy.Service.Controllers.DTO
/// <summary>
/// Information about the session to be created
/// </summary>
public class CreateSessionRequest
public record CreateSessionRequest
{
/// <summary>
/// Globally unique session identifier
/// </summary>
[Required]
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// List of session participants
/// </summary>
public CreateParticipantRequest[] Participants { get; set; }
public CreateParticipantRequest[]? Participants { get; init; }


/// <summary>
/// List of session cards
/// </summary>
public CreateCardRequest[] Cards { get; set; }
public CreateCardRequest[]? Cards { get; init; }

/// <summary>
/// A card used to represent a vote that has not yet been cast
/// </summary>
public Card NoVote { get; set; }
public Card? NoVote { get; init; }

/// <summary>
/// A card used to represent a vote that has not yet been revealed
/// </summary>
public Card NotRevealed { get; set; }
public Card? NotRevealed { get; init; }


// TODO: This method should be replaced with a proper Automapper configuration
public Session GetSession()
Expand All @@ -62,7 +63,7 @@ public Session GetSession()
}


private void AddParticipants(Session session, CreateParticipantRequest[] participants)
private void AddParticipants(Session session, CreateParticipantRequest[]? participants)
{
if (participants != null)
{
Expand All @@ -74,7 +75,7 @@ private void AddParticipants(Session session, CreateParticipantRequest[] partici
}


private void AddCards(Session session, CreateCardRequest[] cards)
private void AddCards(Session session, CreateCardRequest[]? cards)
{
if (cards != null)
{
Expand Down
15 changes: 8 additions & 7 deletions service/src/Controllers/DTO/ParticipantResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@

namespace Spacecowboy.Service.Controllers.DTO
{
public class ParticipantResponse
public record ParticipantResponse
{
/// <summary>
/// Globally unique participant identifier
/// </summary>
public Guid Id { get; set; }
public Guid Id { get; init; }

/// <summary>
/// Participant name
/// </summary>
public string Name { get; set; }
public string Name { get; init; }


/// <summary>
/// Participant avatar
/// </summary>
public string Avatar { get; set; }
public string? Avatar { get; init; }


/// <summary>
/// Participant color
/// </summary>
public string Color { get; set; }
public string? Color { get; init; }


/// <summary>
/// Participant idle time (in seconds)
/// </summary>
public double Idle { get; set; }
public double Idle { get; init; }


/// <summary>
Expand All @@ -58,12 +58,13 @@ public class ParticipantResponse
/// This ID will always reference a card that exists in the session. It can be the novote or notrevealed cards.
/// It can be <c>null</c> if cards have not been defined for the session, yet.
/// </remarks>
public Guid? Vote { get; set; }
public Guid? Vote { get; init; }


/// <summary>
/// Create a ParticipantReponse from Participant, adding an explicit vote
/// </summary>
// TODO Consider removing the constructor and use initializers instead.
public ParticipantResponse(Participant participant, Guid? vote)
{
Id = participant.Id;
Expand Down
22 changes: 11 additions & 11 deletions service/src/Controllers/DTO/SessionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@

namespace Spacecowboy.Service.Controllers.DTO
{
public class SessionResponse
public record SessionResponse
{
/// <summary>
/// Globally unique session identifier
/// </summary>
public string Id { get; set; }
public string Id { get; init; }

/// <summary>
/// Participants registered in session
/// </summary>
public ParticipantResponse[] Participants { get; set; }
public ParticipantResponse[]? Participants { get; init; }

/// <summary>
/// Cards registered in session
/// </summary>
public CardResponse[] Cards { get; set; }
public CardResponse[]? Cards { get; init; }

/// <summary>
/// A card used to represent a vote that has not yet been cast
/// </summary>
public CardResponse NoVote { get; set; }
public CardResponse? NoVote { get; init; }

/// <summary>
/// A card used to represent a vote that has not yet been revealed
/// </summary>
public CardResponse NotRevealed { get; set; }
public CardResponse? NotRevealed { get; init; }

/// <summary>
/// Time when this session was created
/// </summary>
public DateTime CreateTime { get; set; }
public DateTime CreateTime { get; init; }

/// <summary>
/// Time when the session was last updated
/// </summary>
public DateTime UpdateTime { get; set; }
public DateTime UpdateTime { get; init; }

/// <summary>
/// Generation counter
Expand All @@ -65,13 +65,13 @@ public class SessionResponse
/// The generation counter is a monotonically increasing value that is automatically updated every time the session object is updated.
/// It can be used to quickly check for a changed session.
/// </remarks>
public int Generation { get; private set; }
public int Generation { get; private init; }


/// <summary>
/// Indicates that all participants have cast their vote and that voting is thus completed
/// </summary>
public bool VotingCompleted { get; private set; }
public bool VotingCompleted { get; private init; }


/// <summary>
Expand All @@ -84,7 +84,7 @@ public SessionResponse(Session session, Guid? participantId = null)
UpdateTime = session.UpdateTime;
Generation = session.Generation;

NoVote = session.NotRevealed == null ? null : new CardResponse(session.NoVote);
NoVote = session.NoVote == null ? null : new CardResponse(session.NoVote);
NotRevealed = session.NotRevealed == null ? null : new CardResponse(session.NotRevealed);
Cards = session.GetCards()?.Select(c => new CardResponse(c)).ToArray();
Participants = session.GetParticipantsVotes(false, participantId).Select(v => new ParticipantResponse(v.Participant, v.Card.Id)).ToArray();
Expand Down
20 changes: 10 additions & 10 deletions service/src/Controllers/DTO/VotesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public enum VoteStatus
Revealed = 2,
}

public class VoteResponse
public record VoteResponse
{
public string ParticipantName { get; set; }
public string ParticipantAvatar { get; set; }
public VoteStatus VoteStatus { get; set; }
public Guid? CardId { get; set; }
public string CardValue { get; set; }
public string CardImage { get; set; }

internal VoteResponse(Participant participant, VoteStatus voteStatus, Card card)
public string ParticipantName { get; init; }
public string? ParticipantAvatar { get; init; }
public VoteStatus VoteStatus { get; init; }
public Guid? CardId { get; init; }
public string? CardValue { get; init; }
public string? CardImage { get; init; }

internal VoteResponse(Participant participant, VoteStatus voteStatus, Card? card)
{
VoteStatus = voteStatus;
ParticipantName = participant.Name;
ParticipantAvatar = participant.Avatar;
if (voteStatus == VoteStatus.Revealed)
if (card != null && voteStatus == VoteStatus.Revealed)
{
CardId = card.Id;
CardValue = card.Value;
Expand Down
Loading

0 comments on commit a50fccb

Please sign in to comment.