Line data Source code
1 : // Package presenter は、ユースケース層の出力データを API レスポンス用 DTO に変換する責務を持ちます。
2 : // ドメインロジックや永続化層の構造をクライアントへ直接公開しないための中間変換レイヤです。
3 : package presenter
4 :
5 : import (
6 : "resume/internal/adapter/http/dto/response"
7 : "resume/internal/shared/util"
8 : "resume/internal/usecase/profile"
9 : )
10 :
11 : // PresentUserProfile は、ユースケース層の UserProfileOutput を HTTP レスポンス用の
12 : // UserProfileResponse DTO に変換します。
13 : // 生年月日のフォーマット変換や年齢グループ算出など、表示専用の補正処理を行います。
14 0 : func PresentUserProfile(out profile.UserProfileOutput) response.UserProfileResponse {
15 0 : var birthStr *string
16 0 : if out.BirthDate != nil {
17 0 : birthStr = util.FormatDatePtr(out.BirthDate)
18 0 : }
19 :
20 0 : var ageGroup *int
21 0 :
22 0 : if out.Age != nil {
23 0 : g := util.CalcAgeGroup(*out.Age) // 25 -> 20, 38 -> 30 など
24 0 : if g > 0 {
25 0 : ageGroup = &g
26 0 : }
27 : }
28 :
29 0 : return response.UserProfileResponse{
30 0 : UserID: out.UserID,
31 0 : FamilyName: out.FamilyName,
32 0 : GivenName: out.GivenName,
33 0 : FamilyNameKana: out.FamilyNameKana,
34 0 : GivenNameKana: out.GivenNameKana,
35 0 : LegalName: out.LegalName,
36 0 : LegalNameKana: out.LegalNameKana,
37 0 : BirthDate: birthStr,
38 0 : Age: out.Age,
39 0 : AgeGroup: ageGroup,
40 0 : GenderID: out.GenderID,
41 0 : GenderLabelKey: out.GenderLabelKey,
42 0 : Initial: out.Initial,
43 0 : }
44 : }
|