feat: update chat schedule
This commit is contained in:
parent
e672daaede
commit
5f10073f8d
|
|
@ -111,7 +111,6 @@ func (m *ChatScheduleMapper) ToFileResponse(file *entity.ChatScheduleFiles) *res
|
||||||
// ToEntity - Convert request to entity
|
// ToEntity - Convert request to entity
|
||||||
func (m *ChatScheduleMapper) ToEntity(req request.ChatScheduleCreateRequest) *entity.ChatSchedules {
|
func (m *ChatScheduleMapper) ToEntity(req request.ChatScheduleCreateRequest) *entity.ChatSchedules {
|
||||||
schedule := &entity.ChatSchedules{
|
schedule := &entity.ChatSchedules{
|
||||||
ChatSessionID: req.ChatSessionID,
|
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Summary: req.Summary,
|
Summary: req.Summary,
|
||||||
|
|
@ -120,6 +119,11 @@ func (m *ChatScheduleMapper) ToEntity(req request.ChatScheduleCreateRequest) *en
|
||||||
Status: "scheduled",
|
Status: "scheduled",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle ChatSessionID pointer
|
||||||
|
if req.ChatSessionID != nil {
|
||||||
|
schedule.ChatSessionID = *req.ChatSessionID
|
||||||
|
}
|
||||||
|
|
||||||
// Files will be attached separately using file IDs
|
// Files will be attached separately using file IDs
|
||||||
|
|
||||||
return schedule
|
return schedule
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// ChatScheduleCreateRequest - Request for creating chat schedule
|
// ChatScheduleCreateRequest - Request for creating chat schedule
|
||||||
type ChatScheduleCreateRequest struct {
|
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"`
|
Title string `json:"title" validate:"required,min=3,max=255"`
|
||||||
Description string `json:"description" validate:"max=1000"`
|
Description string `json:"description" validate:"max=1000"`
|
||||||
Summary string `json:"summary" validate:"max=2000"`
|
Summary string `json:"summary" validate:"max=2000"`
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
type chatScheduleService struct {
|
type chatScheduleService struct {
|
||||||
chatScheduleRepository repository.ChatScheduleRepository
|
chatScheduleRepository repository.ChatScheduleRepository
|
||||||
chatRepository repository.ChatRepository
|
chatRepository repository.ChatRepository
|
||||||
|
chatService ChatService
|
||||||
chatScheduleMapper *mapper.ChatScheduleMapper
|
chatScheduleMapper *mapper.ChatScheduleMapper
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
UsersRepo usersRepository.UsersRepository
|
UsersRepo usersRepository.UsersRepository
|
||||||
|
|
@ -39,12 +40,14 @@ type ChatScheduleService interface {
|
||||||
func NewChatScheduleService(
|
func NewChatScheduleService(
|
||||||
chatScheduleRepository repository.ChatScheduleRepository,
|
chatScheduleRepository repository.ChatScheduleRepository,
|
||||||
chatRepository repository.ChatRepository,
|
chatRepository repository.ChatRepository,
|
||||||
|
chatService ChatService,
|
||||||
log zerolog.Logger,
|
log zerolog.Logger,
|
||||||
usersRepo usersRepository.UsersRepository,
|
usersRepo usersRepository.UsersRepository,
|
||||||
) ChatScheduleService {
|
) ChatScheduleService {
|
||||||
return &chatScheduleService{
|
return &chatScheduleService{
|
||||||
chatScheduleRepository: chatScheduleRepository,
|
chatScheduleRepository: chatScheduleRepository,
|
||||||
chatRepository: chatRepository,
|
chatRepository: chatRepository,
|
||||||
|
chatService: chatService,
|
||||||
chatScheduleMapper: mapper.NewChatScheduleMapper(),
|
chatScheduleMapper: mapper.NewChatScheduleMapper(),
|
||||||
Log: log,
|
Log: log,
|
||||||
UsersRepo: usersRepo,
|
UsersRepo: usersRepo,
|
||||||
|
|
@ -64,8 +67,28 @@ func (_i *chatScheduleService) CreateChatSchedule(authToken string, req request.
|
||||||
return nil, errors.New("scheduled time must be in the future")
|
return nil, errors.New("scheduled time must be in the future")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is participant in the chat session
|
var chatSessionID uint
|
||||||
isParticipant, err := _i.chatRepository.CheckUserInChatSession(userID, req.ChatSessionID)
|
|
||||||
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +96,11 @@ func (_i *chatScheduleService) CreateChatSchedule(authToken string, req request.
|
||||||
if !isParticipant {
|
if !isParticipant {
|
||||||
return nil, errors.New("user is not a participant in this chat session")
|
return nil, errors.New("user is not a participant in this chat session")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Convert request to entity
|
// Convert request to entity
|
||||||
schedule := _i.chatScheduleMapper.ToEntity(req)
|
schedule := _i.chatScheduleMapper.ToEntity(req)
|
||||||
|
schedule.ChatSessionID = chatSessionID
|
||||||
schedule.CreatedBy = userID
|
schedule.CreatedBy = userID
|
||||||
|
|
||||||
// Create schedule
|
// Create schedule
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue