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

            Line data    Source code
       1              : // Package profile は、ユーザープロフィールに関するユースケース(アプリケーションロジック)を提供します。
       2              : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で再利用可能なビジネスフローを実装します。
       3              : package profile
       4              : 
       5              : import (
       6              :         "context"
       7              : 
       8              :         "resume/internal/shared/util"
       9              : )
      10              : 
      11              : // GetUserProfile は、指定されたユーザーIDに紐づくプロフィール情報を取得します。
      12              : // トランザクション内で UserProfileRepository を参照し、該当ユーザーが存在しない場合は空の DTO を返します。
      13              : // 取得したデータに対して年齢計算やラベルキー組み立てなどの補助的処理も行います。
      14            0 : func (uc *Interactor) GetUserProfile(ctx context.Context, in UserInput) (UserProfileOutput, error) {
      15            0 :         if in.UserID == 0 {
      16            0 :                 return UserProfileOutput{}, errUnauthorized()
      17            0 :         }
      18              : 
      19            0 :         var out UserProfileOutput
      20            0 :         // すべて tx.Do の中に閉じ込める
      21            0 :         if err := uc.tx.Do(ctx, func(txCtx context.Context) error {
      22            0 :                 up, err := uc.upRepo.FindByUserID(txCtx, in.UserID)
      23            0 :                 if err != nil {
      24            0 :                         return err
      25            0 :                 }
      26              :                 // レコードなし → 空 DTO でOK(HTTP層で 200 + null / {} / [] にするかは presenter で調整)
      27            0 :                 if up == nil {
      28            0 :                         out = UserProfileOutput{}
      29            0 :                         return nil
      30            0 :                 }
      31              : 
      32              :                 // 年齢計算(例)
      33            0 :                 var age *int
      34            0 :                 if up.BirthDate != nil {
      35            0 :                         a := util.CalcAge(up.BirthDate)
      36            0 :                         age = &a
      37            0 :                 }
      38              : 
      39              :                 // Genderの辞書キーを組み立てる
      40            0 :                 var genderLabelKey *string
      41            0 :                 if up.Gender != nil && up.Gender.Code != "" {
      42            0 :                         s := util.Fmt("master.gender.%s", up.Gender.Code)
      43            0 :                         genderLabelKey = &s
      44            0 :                 }
      45              : 
      46              :                 // DTO 詰め替え
      47            0 :                 out = UserProfileOutput{
      48            0 :                         UserID:         up.UserID,
      49            0 :                         FamilyName:     up.FamilyName,
      50            0 :                         GivenName:      up.GivenName,
      51            0 :                         FamilyNameKana: up.FamilyNameKana,
      52            0 :                         GivenNameKana:  up.GivenNameKana,
      53            0 :                         LegalName:      up.LegalName,
      54            0 :                         LegalNameKana:  up.LegalNameKana,
      55            0 :                         //BirthDate:      util.FormatDatePtr(up.BirthDate), // *time.Time -> *string にする util 想定
      56            0 :                         BirthDate:      up.BirthDate, // *time.Time -> *string にする util 想定
      57            0 :                         Age:            age,
      58            0 :                         GenderID:       up.GenderID,
      59            0 :                         GenderLabelKey: genderLabelKey,
      60            0 :                         Initial:        up.Initial,
      61            0 :                 }
      62            0 :                 return nil
      63            0 :         }); err != nil {
      64            0 :                 return UserProfileOutput{}, err
      65            0 :         }
      66              : 
      67            0 :         return out, nil
      68              : }
        

Generated by: LCOV version 2.3.1-1