forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/model/dto"
|
||||
)
|
||||
|
||||
// ChatsCreate resolves the caller, validates the proposed chat and persists it atomically.
|
||||
func (s *Service) ChatsCreate(ctx context.Context, request dto.ChatsCreateRequestDTO) (dto.ChatDTO, error) {
|
||||
caller, err := s.requireUserID(ctx, request.UserID)
|
||||
if err != nil {
|
||||
return dto.ChatDTO{}, err
|
||||
}
|
||||
chat, err := prepareChat(request, caller)
|
||||
if err != nil {
|
||||
return dto.ChatDTO{}, err
|
||||
}
|
||||
if err := s.requireExistingMembers(ctx, chat.MemberIDs); err != nil {
|
||||
return dto.ChatDTO{}, err
|
||||
}
|
||||
created, err := s.repo.CreateChat(ctx, chat)
|
||||
return created, normalizeStoreError(err)
|
||||
}
|
||||
|
||||
// ChatsGetByID returns a chat only to a current member, hiding its existence otherwise.
|
||||
func (s *Service) ChatsGetByID(ctx context.Context, userID, chatID string) (dto.ChatDTO, error) {
|
||||
_, chat, err := s.requireChatMember(ctx, userID, chatID)
|
||||
return chat, err
|
||||
}
|
||||
|
||||
// ChatsGetPage authorizes the caller, loads a page and prepares its continuation.
|
||||
func (s *Service) ChatsGetPage(ctx context.Context, request dto.PageRequestDTO) (dto.ChatPageDTO, error) {
|
||||
caller, err := s.requireUserID(ctx, request.UserID)
|
||||
if err != nil {
|
||||
return dto.ChatPageDTO{}, err
|
||||
}
|
||||
page, err := s.parsePage(request, chatListResource(caller))
|
||||
if err != nil {
|
||||
return dto.ChatPageDTO{}, err
|
||||
}
|
||||
items, err := s.repo.Chats(ctx, caller, page.position, page.fetchLimit())
|
||||
if err != nil {
|
||||
return dto.ChatPageDTO{}, normalizeStoreError(err)
|
||||
}
|
||||
return s.chatPage(items, page)
|
||||
}
|
||||
Reference in New Issue
Block a user