Line data Source code
1 : // Package profile は、ユーザープロフィールに関するユースケース(アプリケーションロジック)を提供します。
2 : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で再利用可能なビジネスフローを実装します。
3 : package profile
4 :
5 : import "context"
6 :
7 : // HasUserProfile は、指定されたユーザーIDに紐づくプロフィール情報の有無を取得します。
8 : // トランザクション内で UserProfileRepository を参照し、真偽値の DTO を返します。
9 0 : func (uc *Interactor) HasUserProfile(ctx context.Context, in UserInput) (HasUserProfileOutput, error) {
10 0 : if in.UserID == 0 {
11 0 : return HasUserProfileOutput{}, errUnauthorized()
12 0 : }
13 :
14 0 : var exists bool
15 0 : if err := uc.tx.Do(ctx, func(txCtx context.Context) error {
16 0 :
17 0 : up, err := uc.upRepo.FindByUserID(txCtx, in.UserID)
18 0 : if err != nil {
19 0 : return err // ← エラーの場合は返して OK
20 0 : }
21 :
22 0 : exists = up != nil
23 0 :
24 0 : return nil // ← ココが重要
25 0 : }); err != nil {
26 0 : return HasUserProfileOutput{}, err
27 0 : }
28 :
29 0 : return HasUserProfileOutput{
30 0 : Exists: exists,
31 0 : }, nil
32 : }
|