-
Notifications
You must be signed in to change notification settings - Fork 4
/
user_service.go
34 lines (28 loc) · 909 Bytes
/
user_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package service
import (
"context"
"github.com/7oh2020/connect-tasklist/backend/domain"
"github.com/7oh2020/connect-tasklist/backend/domain/object/entity"
"github.com/7oh2020/connect-tasklist/backend/domain/object/value"
"github.com/7oh2020/connect-tasklist/backend/domain/repository"
)
// ユーザーのドメインロジック
type IUserService interface {
FindUserByID(ctx context.Context, id string) (*entity.User, error)
}
type UserService struct {
repository.IUserRepository
}
func NewUserService(repo repository.IUserRepository) *UserService {
return &UserService{repo}
}
func (s *UserService) FindUserByID(ctx context.Context, id string) (*entity.User, error) {
if err := value.NewID(id).Validate(); err != nil {
return nil, err
}
user, err := s.IUserRepository.FindUserByID(ctx, id)
if err != nil {
return nil, &domain.ErrNotFound{Msg: "user not found"}
}
return user, nil
}