LCOV - code coverage report
Current view: top level - usecase/contact - delete_user_contact_interactor.go Coverage Total Hit
Test: coverage.lcov Lines: 0.0 % 52 0
Test Date: 2026-04-14 06:42:22 Functions: - 0 0

            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              : // DeleteUserContact は 連絡先 を削除します
      13              : func (uc *Interactor) DeleteUserContact(
      14              :         ctx context.Context,
      15              :         in DeleteUserContactInput,
      16            0 : ) (DeleteUserContactOutput, error) {
      17            0 :         if err := uc.tx.Do(ctx, func(txCtx context.Context) error {
      18            0 : 
      19            0 :                 con, err := uc.ucRepo.FindByID(txCtx, in.ID)
      20            0 :                 if err != nil {
      21            0 :                         return err
      22            0 :                 }
      23            0 :                 if con == nil {
      24            0 :                         return apperr.New(
      25            0 :                                 apperr.CodeNotFound,
      26            0 :                                 "user contact is not found",
      27            0 :                                 map[string]any{
      28            0 :                                         "id": in.ID,
      29            0 :                                 },
      30            0 :                         )
      31            0 :                 }
      32            0 :                 if con.UserID != in.UserID {
      33            0 :                         ve := valerr.New()
      34            0 :                         ve.Add(
      35            0 :                                 "domain.userContact.id",
      36            0 :                                 "validation.rules.invalid",
      37            0 :                                 map[string]any{
      38            0 :                                         "field": "domain.userContact.id",
      39            0 :                                         "value": in.ID,
      40            0 :                                 },
      41            0 :                         )
      42            0 :                         return apperr.New(
      43            0 :                                 apperr.CodeUnprocessable,
      44            0 :                                 "The Request contains semantically invalid data.",
      45            0 :                                 ve.ToDetails(),
      46            0 :                         )
      47            0 :                 }
      48              : 
      49            0 :                 if err := uc.ucRepo.Delete(txCtx, in.ID); err != nil {
      50            0 :                         return err
      51            0 :                 }
      52            0 :                 remainingList, err := uc.ucRepo.ListByUserID(txCtx, in.UserID)
      53            0 :                 if err != nil {
      54            0 :                         return err
      55            0 :                 }
      56              : 
      57            0 :                 var newOrderIDs []uint64
      58            0 :                 for _, con := range remainingList {
      59            0 :                         newOrderIDs = append(newOrderIDs, con.ID)
      60            0 :                 }
      61              : 
      62            0 :                 if len(newOrderIDs) > 0 {
      63            0 :                         if err := uc.ucRepo.UpdateOrder(txCtx, in.UserID, newOrderIDs); err != nil {
      64            0 :                                 return err
      65            0 :                         }
      66              :                 }
      67            0 :                 return nil
      68            0 :         }); err != nil {
      69            0 :                 return DeleteUserContactOutput{}, err
      70            0 :         }
      71            0 :         return DeleteUserContactOutput{}, nil
      72              : }
        

Generated by: LCOV version 2.3.1-1