Line data Source code
1 : // Package contact は 連絡先 に関するユースケース(アプリケーションロジック)を提供します。
2 : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で再利用可能なビジネスフローを実装します。
3 : package contact
4 :
5 : import (
6 : "context"
7 :
8 : "resume/internal/shared/apperr"
9 : "resume/internal/shared/valerr"
10 : )
11 :
12 : // ReorderUserContact は 連絡先の並び順 を 変更 します
13 : func (uc *Interactor) ReorderUserContact(
14 : ctx context.Context,
15 : in ReorderUserContactInput,
16 0 : ) (ReorderUserContactOutput, error) {
17 0 : if err := uc.tx.Do(ctx, func(txCtx context.Context) error {
18 0 : ownedList, err := uc.ucRepo.ListByUserID(txCtx, in.UserID)
19 0 : if err != nil {
20 0 : return err
21 0 : }
22 0 : ownedIDMap := make(map[uint64]bool)
23 0 : for _, con := range ownedList {
24 0 : ownedIDMap[con.ID] = true
25 0 : }
26 0 : for _, reqID := range in.IDs {
27 0 : if !ownedIDMap[reqID] {
28 0 : ve := valerr.New()
29 0 : ve.Add(
30 0 : "domain.userContact.id",
31 0 : "validation.rules.invalid",
32 0 : map[string]any{
33 0 : "field": "domain.userContact.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.ucRepo.UpdateOrder(txCtx, in.UserID, in.IDs)
45 0 : }); err != nil {
46 0 : return ReorderUserContactOutput{}, err
47 0 : }
48 0 : return ReorderUserContactOutput{}, nil
49 : }
|