Line data Source code
1 : // Package license は 資格・免許 に関するユースケース(アプリケーションロジック)を提供します
2 : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で利用可能なビジネスフローを実装します
3 : package license
4 :
5 : import (
6 : "context"
7 :
8 : "resume/internal/domain/entity"
9 : "resume/internal/shared/apperr"
10 : "resume/internal/shared/valerr"
11 : )
12 :
13 : // UpdateUserLicense は ユーザーの資格・免許 を 更新 します
14 : func (uc *Interactor) UpdateUserLicense(
15 : ctx context.Context,
16 : in UpdateUserLicenseInput,
17 0 : ) (UpdateUserLicenseOutput, error) {
18 0 : var updated *entity.UserLicense
19 0 :
20 0 : err := uc.tx.Do(ctx, func(txCtx context.Context) error {
21 0 :
22 0 : current, err := uc.ulRepo.FindByID(txCtx, in.ID)
23 0 : if err != nil {
24 0 : return err
25 0 : }
26 :
27 0 : if current == nil {
28 0 : ve := valerr.New()
29 0 : ve.Add(
30 0 : "domain.userLicense.id",
31 0 : "validation.rules.invalid",
32 0 : map[string]any{
33 0 : "field": "domain.userLicense.id",
34 0 : "value": in.ID,
35 0 : },
36 0 : )
37 0 : return apperr.New(
38 0 : apperr.CodeUnprocessable,
39 0 : "The request contains semantically invalid data.",
40 0 : ve.ToDetails(),
41 0 : )
42 0 : }
43 :
44 0 : if current.UserID != in.UserID {
45 0 : ve := valerr.New()
46 0 : ve.Add(
47 0 : "domain.userLicense.id",
48 0 : "validation.rules.invalid",
49 0 : map[string]any{
50 0 : "field": "domain.userLicense.id",
51 0 : "value": in.ID,
52 0 : },
53 0 : )
54 0 : return apperr.New(
55 0 : apperr.CodeUnprocessable,
56 0 : "The request contains semantically invalid data.",
57 0 : ve.ToDetails(),
58 0 : )
59 0 : }
60 :
61 0 : current.Name = in.Name
62 0 : current.EventDate = in.EventDate
63 0 :
64 0 : res, err := uc.ulRepo.Update(txCtx, current)
65 0 : if err != nil {
66 0 : return err
67 0 : }
68 0 : updated = res
69 0 : return nil
70 : })
71 0 : if err != nil {
72 0 : return UpdateUserLicenseOutput{}, err
73 0 : }
74 0 : return UpdateUserLicenseOutput{ID: updated.ID}, nil
75 : }
|