package service import ( "context" "github.com/aykhans/oh-my-chat/internal/core/domain" "github.com/aykhans/oh-my-chat/internal/core/port" "github.com/google/uuid" ) type MessageService struct { producer port.MessageProducer consumer port.MessageConsumer repo port.MessageRepository } func NewMessageService( producerService port.MessageProducer, consumerService port.MessageConsumer, repo port.MessageRepository, ) *MessageService { return &MessageService{ producerService, consumerService, repo, } } func (chatServie *MessageService) SendMessage( ctx context.Context, message *domain.Message, ) error { message.ChatID = "chat_" + message.ChatID return chatServie.producer.ProduceMessage(ctx, message) } func (chatServie *MessageService) ReceiveMessage( ctx context.Context, userID uuid.UUID, message chan<- *domain.StreamMessage, ) error { return chatServie.consumer.ConsumeMessage( ctx, userID.String(), func() []string { return []string{"chat_1", "chat_5", "chat_9"} }, message, ) } func (chatServie *MessageService) CreateMessage( ctx context.Context, message *domain.Message, ) (*domain.Message, error) { return chatServie.repo.CreateMessage(ctx, message) }