Line data Source code
1 : // Package license は 資格・免許 に関するユースケース(アプリケーションロジック)を提供します
2 : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で利用可能なビジネスフローを実装します
3 : package license
4 :
5 : import (
6 : "context"
7 :
8 : "resume/internal/shared/apperr"
9 : "resume/internal/shared/valerr"
10 : )
11 :
12 : // ReorderUserLicense は ユーザーの資格・免許 を 取得 するためのユースケースを定義します
13 : func (uc *Interactor) ReorderUserLicense(
14 : ctx context.Context,
15 : in ReorderUserLicenseInput,
16 0 : ) (ReorderUserLicenseOutput, error) {
17 0 : if err := uc.tx.Do(ctx, func(txCtx context.Context) error {
18 0 : ownedList, err := uc.ulRepo.ListByUserID(txCtx, in.UserID)
19 0 : if err != nil {
20 0 : return err
21 0 : }
22 0 : ownedIPMap := make(map[uint64]bool)
23 0 : for _, ul := range ownedList {
24 0 : ownedIPMap[ul.ID] = true
25 0 : }
26 0 : for _, reqID := range in.IDs {
27 0 : if !ownedIPMap[reqID] {
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": reqID,
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 : return uc.ulRepo.UpdateOrder(txCtx, in.UserID, in.IDs)
45 0 : }); err != nil {
46 0 : return ReorderUserLicenseOutput{}, err
47 0 : }
48 0 : return ReorderUserLicenseOutput{}, nil
49 : }
|