Skip to content

Commit

Permalink
collection expressions everywhere!
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Aug 29, 2024
1 parent d02417c commit 59d7857
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 117 deletions.
38 changes: 19 additions & 19 deletions src/shared/Jordnaer.Shared/Chat/ChatDto.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
namespace Jordnaer.Shared;

public class ChatDto
{
public Guid Id { get; init; }

/// <summary>
/// The display name of the chat.
/// <para>
/// This defaults to a concatenated string of recipient names.
/// </para>
/// </summary>
public string? DisplayName { get; init; }

public int UnreadMessageCount { get; set; }

public List<ChatMessageDto> Messages { get; set; } = new();
public List<UserSlim> Recipients { get; init; } = new();

public DateTime LastMessageSentUtc { get; init; }
public DateTime StartedUtc { get; init; } = DateTime.UtcNow;
public bool HasUnreadMessages => UnreadMessageCount > 0;
{
public Guid Id { get; init; }

/// <summary>
/// The display name of the chat.
/// <para>
/// This defaults to a concatenated string of recipient names.
/// </para>
/// </summary>
public string? DisplayName { get; init; }

public int UnreadMessageCount { get; set; }

public List<ChatMessageDto> Messages { get; set; } = [];
public List<UserSlim> Recipients { get; init; } = [];

public DateTime LastMessageSentUtc { get; init; }
public DateTime StartedUtc { get; init; } = DateTime.UtcNow;
public bool HasUnreadMessages => UnreadMessageCount > 0;
}
8 changes: 4 additions & 4 deletions src/shared/Jordnaer.Shared/Chat/ChatMessageResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Jordnaer.Shared;

public class ChatMessageResult
{
public List<ChatMessageDto> ChatMessages { get; init; } = new();

public int TotalCount { get; init; }
{
public List<ChatMessageDto> ChatMessages { get; init; } = [];

public int TotalCount { get; init; }
}
8 changes: 4 additions & 4 deletions src/shared/Jordnaer.Shared/Chat/ChatResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Jordnaer.Shared;

public class ChatResult
{
public List<ChatDto> Chats { get; init; } = new();

public int TotalCount { get; init; }
{
public List<ChatDto> Chats { get; init; } = [];

public int TotalCount { get; init; }
}
38 changes: 19 additions & 19 deletions src/shared/Jordnaer.Shared/Database/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

namespace Jordnaer.Shared;

[Index(nameof(LastMessageSentUtc), IsDescending = new[] { true })]
[Index(nameof(LastMessageSentUtc), IsDescending = [true])]
public class Chat
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

/// <summary>
/// The display name of the chat.
/// <para>
/// If set to <c>null</c>, this defaults to a concatenated string of recipient names.
/// </para>
/// </summary>
public string? DisplayName { get; set; }

public List<ChatMessage> Messages { get; set; } = new();
public List<UserProfile> Recipients { get; set; } = new();

public DateTime LastMessageSentUtc { get; set; }
public DateTime StartedUtc { get; set; } = DateTime.UtcNow;
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

/// <summary>
/// The display name of the chat.
/// <para>
/// If set to <c>null</c>, this defaults to a concatenated string of recipient names.
/// </para>
/// </summary>
public string? DisplayName { get; set; }

public List<ChatMessage> Messages { get; set; } = [];
public List<UserProfile> Recipients { get; set; } = [];

public DateTime LastMessageSentUtc { get; set; }
public DateTime StartedUtc { get; set; } = DateTime.UtcNow;
}

38 changes: 19 additions & 19 deletions src/shared/Jordnaer.Shared/Database/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

namespace Jordnaer.Shared;

[Index(nameof(SentUtc), IsDescending = new[] { true })]
[Index(nameof(SentUtc), IsDescending = [true])]
public class ChatMessage
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

public UserProfile Sender { get; set; } = null!;

[ForeignKey(nameof(UserProfile))]
public required string SenderId { get; set; }

[ForeignKey(nameof(Chat))]
public Guid ChatId { get; set; }

public required string Text { get; set; }

public DateTime SentUtc { get; set; }

public string? AttachmentUrl { get; set; }
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }

public UserProfile Sender { get; set; } = null!;

[ForeignKey(nameof(UserProfile))]
public required string SenderId { get; set; }

[ForeignKey(nameof(Chat))]
public Guid ChatId { get; set; }

public required string Text { get; set; }

public DateTime SentUtc { get; set; }

public string? AttachmentUrl { get; set; }
}
6 changes: 3 additions & 3 deletions src/shared/Jordnaer.Shared/Database/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class Group
[MaxLength(4000, ErrorMessage = "Gruppens beskrivelse må højest være 4000 karakterer lang.")]
public string? Description { get; set; }

public List<UserProfile> Members { get; set; } = new();
public List<GroupMembership> Memberships { get; set; } = new();
public List<Category> Categories { get; set; } = new();
public List<UserProfile> Members { get; set; } = [];
public List<GroupMembership> Memberships { get; set; } = [];
public List<Category> Categories { get; set; } = [];

public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
}
30 changes: 15 additions & 15 deletions src/shared/Jordnaer.Shared/Extensions/ChatExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace Jordnaer.Shared;

public static class ChatExtensions
{
public static ChatDto ToChatDto(this Chat chat) =>
new()
{
DisplayName = chat.DisplayName,
Id = chat.Id,
LastMessageSentUtc = chat.LastMessageSentUtc,
StartedUtc = chat.StartedUtc,
Recipients = chat.Recipients.Count == 0
? new List<UserSlim>()
: chat.Recipients.Select(recipient => recipient.ToUserSlim()).ToList(),
Messages = chat.Messages.Count == 0
? new List<ChatMessageDto>()
: chat.Messages.Select(chatMessage => chatMessage.ToChatMessageDto()).ToList()
};
{
public static ChatDto ToChatDto(this Chat chat) =>
new()
{
DisplayName = chat.DisplayName,
Id = chat.Id,
LastMessageSentUtc = chat.LastMessageSentUtc,
StartedUtc = chat.StartedUtc,
Recipients = chat.Recipients.Count == 0
? []
: chat.Recipients.Select(recipient => recipient.ToUserSlim()).ToList(),
Messages = chat.Messages.Count == 0
? []
: chat.Messages.Select(chatMessage => chatMessage.ToChatMessageDto()).ToList()
};
}
46 changes: 23 additions & 23 deletions src/shared/Jordnaer.Shared/Profile/DTO/ProfileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ namespace Jordnaer.Shared;

public class ProfileDto
{
public required string Id { get; set; }
public required string Id { get; set; }

public string? FirstName { get; set; }
public string? FirstName { get; set; }

public string? LastName { get; set; }
public string? LastName { get; set; }

public string? UserName { get; set; }
public string? UserName { get; set; }

public string? PhoneNumber { get; set; }
public string? PhoneNumber { get; set; }

public string? Address { get; set; }
public string? Address { get; set; }

public int? ZipCode { get; set; }
public int? ZipCode { get; set; }

public string? City { get; set; }
public string? City { get; set; }

public string? Description { get; set; }
public string? Description { get; set; }

public List<Category> Categories { get; set; } = new();
public List<Category> Categories { get; set; } = [];

public List<ChildProfileDto> ChildProfiles { get; set; } = new();
public List<ChildProfileDto> ChildProfiles { get; set; } = [];

public DateTime? DateOfBirth { get; set; }
public DateTime? DateOfBirth { get; set; }

public string ProfilePictureUrl { get; set; } = null!;
public string ProfilePictureUrl { get; set; } = null!;

public int? Age { get; set; }
public int? Age { get; set; }

public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;

public string DisplayLocation => ZipCode is not null && City is not null
? $"{ZipCode}, {City}"
: ZipCode is not null
? ZipCode.ToString()!
: City ?? "Område ikke angivet";
public string DisplayLocation => ZipCode is not null && City is not null
? $"{ZipCode}, {City}"
: ZipCode is not null
? ZipCode.ToString()!
: City ?? "Område ikke angivet";

public string DisplayName => FirstName is not null
? $"{FirstName} {LastName}"
: LastName ?? string.Empty;
public string DisplayName => FirstName is not null
? $"{FirstName} {LastName}"
: LastName ?? string.Empty;
}
22 changes: 11 additions & 11 deletions src/shared/Jordnaer.Shared/UserSearch/UserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ namespace Jordnaer.Shared;

public class UserDto
{
public string? UserName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public int? ZipCode { get; set; }
public string? City { get; set; }
public required string ProfilePictureUrl { get; set; }
public List<string> Categories { get; set; } = new();
public List<ChildDto> Children { get; set; } = new();
public string? UserName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public int? ZipCode { get; set; }
public string? City { get; set; }
public required string ProfilePictureUrl { get; set; }
public List<string> Categories { get; set; } = [];
public List<ChildDto> Children { get; set; } = [];

public string? DisplayName => FirstName is not null
? $"{FirstName} {LastName}"
: LastName;
public string? DisplayName => FirstName is not null
? $"{FirstName} {LastName}"
: LastName;
}

0 comments on commit 59d7857

Please sign in to comment.