Line data Source code
1 : // Package education は ユーザーの学歴情報に関するユースケースを提供します。
2 : // このファイルは、ドメインエンティティを出力用データ構造やレスポンスDTOに変換するアセンブラ定義を含みます。
3 : package education
4 :
5 : import (
6 : "resume/internal/adapter/http/dto/response"
7 : "resume/internal/domain/entity"
8 : "resume/internal/shared/util"
9 : )
10 :
11 0 : func educationStatusKey(educationStatusID uint64) string {
12 0 : var key string
13 0 : switch educationStatusID {
14 0 : case entity.EducationStatusEnrolled:
15 0 : key = entity.EducationStatusCodeEnrolled
16 0 : case entity.EducationStatusLeaveOfAbsence:
17 0 : key = entity.EducationStatusCodeLeaveOfAbsence
18 0 : case entity.EducationStatusGraduated:
19 0 : key = entity.EducationStatusCodeGraduated
20 0 : case entity.EducationStatusCompleted:
21 0 : key = entity.EducationStatusCodeCompleted
22 0 : case entity.EducationStatusGraduationProspect:
23 0 : key = entity.EducationStatusCodeGraduationProspect
24 0 : case entity.EducationStatusWithdrawn:
25 0 : key = entity.EducationStatusCodeWithdrawn
26 0 : case entity.EducationStatusExpelled:
27 0 : key = entity.EducationStatusCodeExpelled
28 0 : default:
29 0 : key = entity.EducationStatusCodeEntrance
30 : }
31 0 : return "master.educationStatus." + util.ToCamel(key)
32 : }
33 :
34 0 : func degreeTypeKey(degreeTypeID uint64) string {
35 0 : var key string
36 0 : switch degreeTypeID {
37 0 : case entity.DegreeTypeHighSchool:
38 0 : key = entity.DegreeTypeCodeHighSchool
39 0 : case entity.DegreeTypeVocational:
40 0 : key = entity.DegreeTypeCodeVocational
41 0 : case entity.DegreeTypeJuniorCollege:
42 0 : key = entity.DegreeTypeCodeJuniorCollege
43 0 : case entity.DegreeTypeBachelor:
44 0 : key = entity.DegreeTypeCodeBachelor
45 0 : case entity.DegreeTypeMaster:
46 0 : key = entity.DegreeTypeCodeMaster
47 0 : case entity.DegreeTypeDoctor:
48 0 : key = entity.DegreeTypeCodeDoctor
49 0 : default:
50 0 : key = entity.DegreeTypeCodeOther
51 : }
52 0 : return "master.degreeType." + util.ToCamel(key)
53 : }
54 :
55 : // ToUserEducationRes は エンティティをレスポンスDTOに変換する
56 0 : func ToUserEducationRes(e *entity.UserEducation) response.UserEducationResponse {
57 0 : return response.UserEducationResponse{
58 0 : ID: e.ID,
59 0 : UserID: e.UserID,
60 0 : InstitutionName: e.InstitutionName,
61 0 : FacultyName: e.FacultyName,
62 0 : DepartmentName: e.DepartmentName,
63 0 : DegreeTypeID: e.DegreeTypeID,
64 0 : DegreeType: degreeTypeKey(e.DegreeTypeID),
65 0 : EducationStatusID: e.EducationStatusID,
66 0 : EducationStatus: educationStatusKey(e.EducationStatusID),
67 0 : EventDate: e.EventDate.Format("2006-01"),
68 0 : Description: e.Description,
69 0 : SortOrder: e.SortOrder,
70 0 : IsPublic: e.IsPublic,
71 0 : CreatedAt: e.CreatedAt,
72 0 : UpdatedAt: e.UpdatedAt,
73 0 : }
74 0 : }
75 :
76 : // ToUserEducationResponses は 学歴エンティティ配列をレスポンスDTOに変換する
77 0 : func ToUserEducationResponses(es []*entity.UserEducation) []response.UserEducationResponse {
78 0 : out := make([]response.UserEducationResponse, 0, len(es))
79 0 : for _, e := range es {
80 0 : out = append(out, ToUserEducationRes(e))
81 0 : }
82 0 : return out
83 : }
84 :
85 : // assembleHasUserEducation は存在有無のプリミティブを出力 DTO に変換します。
86 0 : func assembleHasUserEducation(exists bool) HasEducationOutput {
87 0 : return HasEducationOutput{
88 0 : Exists: exists,
89 0 : }
90 0 : }
|