merch-api/internal/user/service.go

62 lines
1.4 KiB
Go
Raw Permalink Normal View History

2026-03-02 17:29:43 +03:00
package user
import (
2026-03-04 17:02:11 +03:00
"context"
2026-03-02 17:29:43 +03:00
"errors"
2026-04-01 17:49:36 +03:00
"merch-api/internal/common"
2026-03-02 17:29:43 +03:00
"merch-api/pkg/utils"
)
type service struct {
2026-04-01 17:49:36 +03:00
repo Repository
utils utils.Utils
authDP common.AuthDataProvider
2026-03-02 17:29:43 +03:00
}
2026-04-01 17:49:36 +03:00
func newService(repo Repository, utils utils.Utils, adp common.AuthDataProvider) *service {
2026-03-02 17:29:43 +03:00
return &service{
2026-04-01 17:49:36 +03:00
repo: repo,
utils: utils,
authDP: adp,
2026-03-02 17:29:43 +03:00
}
}
2026-03-06 19:07:33 +03:00
func (s *service) GetUserId(ctx context.Context, userUuid string) (int64, error) {
2026-03-02 17:29:43 +03:00
if userUuid == "" {
2026-03-06 19:07:33 +03:00
return 0, errors.New("user uuid is empty")
2026-03-02 17:29:43 +03:00
}
2026-03-04 17:02:11 +03:00
return s.repo.getUserId(ctx, userUuid)
2026-03-02 17:29:43 +03:00
}
2026-03-20 16:09:12 +03:00
func (s *service) createUser(ctx context.Context, userUuid string) error {
now := s.utils.TimeNowUTC()
return s.repo.addUser(ctx, &userModel{
CreatedAt: now,
UpdatedAt: s.utils.NullTimeFromNow(now),
DeletedAt: s.utils.DeletedNullTime(),
Uuid: userUuid,
})
}
func (s *service) deleteUser(ctx context.Context, userUuid string) error {
return s.repo.deleteUser(ctx, userUuid, s.utils.NullTimeNowUTC())
}
2026-03-26 20:29:58 +03:00
func (s *service) getUser(ctx context.Context, userUuid string) (*MeDTO, error) {
if userUuid == "" {
return nil, errors.New("user uuid is empty")
}
return s.repo.getUser(ctx, userUuid)
}
2026-04-01 17:49:36 +03:00
func (s *service) getPersonalData(ctx context.Context, userUuid string) (*common.PersonalDTO, error) {
if userUuid == "" {
return nil, errors.New("user uuid is empty")
}
return s.authDP.GetPersonalData(ctx, userUuid)
}