mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
Add core models, DTOs, and services for EchoHub chat application
- Created User, Channel, Message, and ServerInfo models with necessary properties. - Added DTOs for user profiles, server information, and message handling. - Implemented JWT authentication service for user login and token generation. - Developed Entity Framework Core DbContext for database interactions. - Introduced SignalR ChatHub for real-time messaging and presence tracking. - Implemented file storage and image to ASCII conversion services. - Set up CORS and middleware for API endpoints. - Created launch settings and development configuration for server and web projects.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
namespace EchoHub.Core.Constants;
|
||||
|
||||
public static class HubConstants
|
||||
{
|
||||
public const string ChatHubPath = "/hubs/chat";
|
||||
public const string DefaultChannel = "general";
|
||||
public const int DefaultHistoryCount = 50;
|
||||
public const int MaxMessageLength = 2000;
|
||||
public const int MaxFileSizeBytes = 10 * 1024 * 1024; // 10 MB
|
||||
public const int MaxAvatarSizeBytes = 2 * 1024 * 1024; // 2 MB
|
||||
public const int AsciiArtWidth = 80;
|
||||
public const int AsciiArtHeight = 40;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using EchoHub.Core.DTOs;
|
||||
|
||||
namespace EchoHub.Core.Contracts;
|
||||
|
||||
/// <summary>
|
||||
/// Methods the server can invoke on connected clients.
|
||||
/// </summary>
|
||||
public interface IEchoHubClient
|
||||
{
|
||||
Task ReceiveMessage(MessageDto message);
|
||||
Task UserJoined(string channelName, string username);
|
||||
Task UserLeft(string channelName, string username);
|
||||
Task ChannelUpdated(ChannelDto channel);
|
||||
Task UserStatusChanged(UserPresenceDto presence);
|
||||
Task Error(string message);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace EchoHub.Core.DTOs;
|
||||
|
||||
public record RegisterRequest(string Username, string Password, string? DisplayName = null);
|
||||
|
||||
public record LoginRequest(string Username, string Password);
|
||||
|
||||
public record LoginResponse(string Token, string Username, string? DisplayName, string? NicknameColor);
|
||||
@@ -0,0 +1,31 @@
|
||||
using EchoHub.Core.Models;
|
||||
|
||||
namespace EchoHub.Core.DTOs;
|
||||
|
||||
public record MessageDto(
|
||||
Guid Id,
|
||||
string Content,
|
||||
string SenderUsername,
|
||||
string? SenderNicknameColor,
|
||||
string ChannelName,
|
||||
MessageType Type,
|
||||
string? AttachmentUrl,
|
||||
string? AttachmentFileName,
|
||||
DateTimeOffset SentAt);
|
||||
|
||||
public record ChannelDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Topic,
|
||||
int MessageCount,
|
||||
DateTimeOffset CreatedAt);
|
||||
|
||||
public record UserDto(
|
||||
Guid Id,
|
||||
string Username,
|
||||
string? DisplayName,
|
||||
string? NicknameColor,
|
||||
UserStatus Status,
|
||||
DateTimeOffset LastSeenAt);
|
||||
|
||||
public record SendMessageRequest(string ChannelName, string Content);
|
||||
@@ -0,0 +1,31 @@
|
||||
using EchoHub.Core.Models;
|
||||
|
||||
namespace EchoHub.Core.DTOs;
|
||||
|
||||
public record UserProfileDto(
|
||||
Guid Id,
|
||||
string Username,
|
||||
string? DisplayName,
|
||||
string? Bio,
|
||||
string? NicknameColor,
|
||||
string? AvatarAscii,
|
||||
UserStatus Status,
|
||||
string? StatusMessage,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset LastSeenAt);
|
||||
|
||||
public record UpdateProfileRequest(
|
||||
string? DisplayName = null,
|
||||
string? Bio = null,
|
||||
string? NicknameColor = null);
|
||||
|
||||
public record UpdateStatusRequest(
|
||||
UserStatus Status,
|
||||
string? StatusMessage = null);
|
||||
|
||||
public record UserPresenceDto(
|
||||
string Username,
|
||||
string? DisplayName,
|
||||
string? NicknameColor,
|
||||
UserStatus Status,
|
||||
string? StatusMessage);
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace EchoHub.Core.DTOs;
|
||||
|
||||
public record ServerInfoDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Description,
|
||||
string Url,
|
||||
int OnlineUsers,
|
||||
int TotalChannels,
|
||||
bool IsOnline,
|
||||
DateTimeOffset LastPingAt);
|
||||
|
||||
public record RegisterServerRequest(string Name, string Url, string? Description = null);
|
||||
|
||||
public record ServerStatusDto(string Name, string? Description, int OnlineUsers, int TotalChannels);
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public class Channel
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public string? Topic { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public Guid CreatedByUserId { get; set; }
|
||||
|
||||
public List<Message> Messages { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public class Message
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Content { get; set; }
|
||||
public MessageType Type { get; set; } = MessageType.Text;
|
||||
public string? AttachmentUrl { get; set; }
|
||||
public string? AttachmentFileName { get; set; }
|
||||
public DateTimeOffset SentAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
|
||||
public Guid ChannelId { get; set; }
|
||||
public Channel? Channel { get; set; }
|
||||
|
||||
public Guid SenderUserId { get; set; }
|
||||
public required string SenderUsername { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public enum MessageType
|
||||
{
|
||||
Text,
|
||||
Image,
|
||||
File
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public class ServerInfo
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public required string Url { get; set; }
|
||||
public int OnlineUsers { get; set; }
|
||||
public int TotalChannels { get; set; }
|
||||
public DateTimeOffset RegisteredAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset LastPingAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public bool IsOnline { get; set; } = true;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Username { get; set; }
|
||||
public required string PasswordHash { get; set; }
|
||||
public string? DisplayName { get; set; }
|
||||
public string? Bio { get; set; }
|
||||
public string? NicknameColor { get; set; }
|
||||
public string? AvatarAscii { get; set; }
|
||||
public UserStatus Status { get; set; } = UserStatus.Online;
|
||||
public string? StatusMessage { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset LastSeenAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace EchoHub.Core.Models;
|
||||
|
||||
public enum UserStatus
|
||||
{
|
||||
Online,
|
||||
Away,
|
||||
DoNotDisturb,
|
||||
Invisible
|
||||
}
|
||||
Reference in New Issue
Block a user