Line data Source code
1 : package user
2 :
3 : import (
4 : "context"
5 :
6 : "resume/internal/domain/repository"
7 : "resume/internal/shared/apperr"
8 : ucshared "resume/internal/usecase/shared"
9 : )
10 :
11 : type interactor struct {
12 : repo repository.UserRepository
13 : }
14 :
15 : // NewUsecase はユーザユースケースの実装を生成します。
16 0 : func NewUsecase(repo repository.UserRepository) Usecase {
17 0 : return &interactor{repo: repo}
18 0 : }
19 :
20 0 : func (i *interactor) GetByID(ctx context.Context, in GetUserInput) (*UserOutput, error) {
21 0 : u, err := i.repo.FindByID(ctx, in.ID)
22 0 : if err != nil {
23 0 : return nil, ucshared.MapInfraError(err) // 既存の共通マッパに委譲
24 0 : }
25 0 : if u == nil {
26 0 : return nil, apperr.New(apperr.CodeNotFound, "user not found", map[string]any{"id": in.ID})
27 0 : }
28 0 : return &UserOutput{
29 0 : ID: u.ID,
30 0 : UID: u.UID,
31 0 : Email: u.Email,
32 0 : EmailVerified: u.EmailVerified,
33 0 : DisplayName: u.DisplayName,
34 0 : PhotoURL: u.PhotoURL,
35 0 : Disabled: u.Disabled,
36 0 : LastLoginAt: u.LastLoginAt,
37 0 : CreatedAt: u.CreatedAt,
38 0 : UpdatedAt: u.UpdatedAt,
39 0 : DeletedAt: u.DeletedAt,
40 0 : }, nil
41 : }
|