feat: update chat schedule
This commit is contained in:
parent
e672daaede
commit
5f10073f8d
|
|
@ -111,13 +111,17 @@ func (m *ChatScheduleMapper) ToFileResponse(file *entity.ChatScheduleFiles) *res
|
|||
// ToEntity - Convert request to entity
|
||||
func (m *ChatScheduleMapper) ToEntity(req request.ChatScheduleCreateRequest) *entity.ChatSchedules {
|
||||
schedule := &entity.ChatSchedules{
|
||||
ChatSessionID: req.ChatSessionID,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Summary: req.Summary,
|
||||
ScheduledAt: req.ScheduledAt,
|
||||
Duration: req.Duration,
|
||||
Status: "scheduled",
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Summary: req.Summary,
|
||||
ScheduledAt: req.ScheduledAt,
|
||||
Duration: req.Duration,
|
||||
Status: "scheduled",
|
||||
}
|
||||
|
||||
// Handle ChatSessionID pointer
|
||||
if req.ChatSessionID != nil {
|
||||
schedule.ChatSessionID = *req.ChatSessionID
|
||||
}
|
||||
|
||||
// Files will be attached separately using file IDs
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// ChatScheduleCreateRequest - Request for creating chat schedule
|
||||
type ChatScheduleCreateRequest struct {
|
||||
ChatSessionID uint `json:"chat_session_id" validate:"required"`
|
||||
ChatSessionID *uint `json:"chat_session_id" validate:"omitempty"` // Optional - if empty, will create new chat session
|
||||
Title string `json:"title" validate:"required,min=3,max=255"`
|
||||
Description string `json:"description" validate:"max=1000"`
|
||||
Summary string `json:"summary" validate:"max=2000"`
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
type chatScheduleService struct {
|
||||
chatScheduleRepository repository.ChatScheduleRepository
|
||||
chatRepository repository.ChatRepository
|
||||
chatService ChatService
|
||||
chatScheduleMapper *mapper.ChatScheduleMapper
|
||||
Log zerolog.Logger
|
||||
UsersRepo usersRepository.UsersRepository
|
||||
|
|
@ -39,12 +40,14 @@ type ChatScheduleService interface {
|
|||
func NewChatScheduleService(
|
||||
chatScheduleRepository repository.ChatScheduleRepository,
|
||||
chatRepository repository.ChatRepository,
|
||||
chatService ChatService,
|
||||
log zerolog.Logger,
|
||||
usersRepo usersRepository.UsersRepository,
|
||||
) ChatScheduleService {
|
||||
return &chatScheduleService{
|
||||
chatScheduleRepository: chatScheduleRepository,
|
||||
chatRepository: chatRepository,
|
||||
chatService: chatService,
|
||||
chatScheduleMapper: mapper.NewChatScheduleMapper(),
|
||||
Log: log,
|
||||
UsersRepo: usersRepo,
|
||||
|
|
@ -64,18 +67,40 @@ func (_i *chatScheduleService) CreateChatSchedule(authToken string, req request.
|
|||
return nil, errors.New("scheduled time must be in the future")
|
||||
}
|
||||
|
||||
// Check if user is participant in the chat session
|
||||
isParticipant, err := _i.chatRepository.CheckUserInChatSession(userID, req.ChatSessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var chatSessionID uint
|
||||
|
||||
if !isParticipant {
|
||||
return nil, errors.New("user is not a participant in this chat session")
|
||||
// If ChatSessionID is not provided, create a new chat session
|
||||
if req.ChatSessionID == nil {
|
||||
// Create a new personal chat session for the schedule
|
||||
chatSessionReq := request.ChatSessionCreateRequest{
|
||||
Name: &req.Title, // Use schedule title as chat session name
|
||||
Type: "group", // Default to group chat for schedules
|
||||
UserIDs: []uint{}, // Empty for now, can be populated later
|
||||
}
|
||||
|
||||
chatSession, err := _i.chatService.CreateChatSession(authToken, chatSessionReq)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to create chat session: " + err.Error())
|
||||
}
|
||||
|
||||
chatSessionID = chatSession.ID
|
||||
} else {
|
||||
chatSessionID = *req.ChatSessionID
|
||||
|
||||
// Check if user is participant in the existing chat session
|
||||
isParticipant, err := _i.chatRepository.CheckUserInChatSession(userID, chatSessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isParticipant {
|
||||
return nil, errors.New("user is not a participant in this chat session")
|
||||
}
|
||||
}
|
||||
|
||||
// Convert request to entity
|
||||
schedule := _i.chatScheduleMapper.ToEntity(req)
|
||||
schedule.ChatSessionID = chatSessionID
|
||||
schedule.CreatedBy = userID
|
||||
|
||||
// Create schedule
|
||||
|
|
|
|||
Loading…
Reference in New Issue