mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: extract channel management to IChannelService and implement CRUD operations
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using EchoHub.Core.DTOs;
|
||||
|
||||
namespace EchoHub.Core.Contracts;
|
||||
|
||||
public interface IChannelService
|
||||
{
|
||||
// Channel CRUD
|
||||
Task<PaginatedResponse<ChannelDto>> GetChannelsAsync(Guid userId, int offset, int limit);
|
||||
Task<ChannelOperationResult> CreateChannelAsync(Guid creatorUserId, string name, string? topic, bool isPublic);
|
||||
Task<ChannelOperationResult> UpdateTopicAsync(Guid callerUserId, string channelName, string? topic);
|
||||
Task<ChannelOperationResult> DeleteChannelAsync(Guid callerUserId, string channelName);
|
||||
|
||||
// Channel queries
|
||||
Task<(string? Topic, bool Exists)> GetChannelTopicAsync(string channelName);
|
||||
Task<List<ChannelListItem>> GetChannelListAsync();
|
||||
Task<ChannelDto?> GetChannelByNameAsync(string channelName);
|
||||
|
||||
// Membership
|
||||
Task<(bool Success, string? Error)> EnsureChannelMembershipAsync(Guid userId, string channelName);
|
||||
}
|
||||
|
||||
public record ChannelListItem(string Name, string? Topic, int OnlineCount);
|
||||
@@ -25,12 +25,8 @@ public interface IChatService
|
||||
Task BroadcastMessageAsync(string channelName, MessageDto message);
|
||||
Task BroadcastChannelUpdatedAsync(ChannelDto channel, string? channelName = null);
|
||||
|
||||
// Query operations (used by IRC gateway for WHOIS, TOPIC, LIST, AUTH)
|
||||
// Query operations (used by IRC gateway for WHOIS, AUTH)
|
||||
Task<UserProfileDto?> GetUserProfileAsync(string username);
|
||||
Task<(string? Topic, bool Exists)> GetChannelTopicAsync(string channelName);
|
||||
Task<List<ChannelListItem>> GetChannelListAsync();
|
||||
Task<List<string>> GetChannelsForUserAsync(string username);
|
||||
Task<(Guid UserId, string Username)?> AuthenticateUserAsync(string username, string password);
|
||||
}
|
||||
|
||||
public record ChannelListItem(string Name, string? Topic, int OnlineCount);
|
||||
|
||||
@@ -3,3 +3,20 @@ namespace EchoHub.Core.DTOs;
|
||||
public record ErrorResponse(string Error, string? Detail = null);
|
||||
|
||||
public record PaginatedResponse<T>(List<T> Items, int Total, int Offset, int Limit);
|
||||
|
||||
public enum ChannelError
|
||||
{
|
||||
ValidationFailed,
|
||||
AlreadyExists,
|
||||
NotFound,
|
||||
Forbidden,
|
||||
Protected
|
||||
}
|
||||
|
||||
public record ChannelOperationResult(ChannelDto? Channel, ChannelError? Error, string? ErrorMessage)
|
||||
{
|
||||
public bool IsSuccess => Error is null;
|
||||
|
||||
public static ChannelOperationResult Success(ChannelDto channel) => new(channel, null, null);
|
||||
public static ChannelOperationResult Fail(ChannelError error, string message) => new(null, error, message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user