@@ -7,39 +7,48 @@ import (
77)
88
99type Subject struct {
10- ID string `gorm:"type:uuid;primaryKey"`
11- Name string `gorm:"type:text;not null"`
12- FacultyID string `gorm:"type:uuid;not null"`
13- Faculty Faculty `gorm:"foreignKey:FacultyID"`
14- Semester string `gorm:"type:text;not null"`
15- SyllabusID string `gorm:"type:text;not null"`
16- DayOfWeekTimetableSlots []DayOfWeekTimetableSlot `gorm:"many2many:subject_day_of_week_timetable_slots;"`
17- Categories []SubjectCategory `gorm:"many2many:subject_categories_subjects;"`
18- EligibleAttributes []SubjectEligibleAttribute `gorm:"foreignKey:SubjectID"`
19- Requirements []SubjectRequirement `gorm:"foreignKey:SubjectID"`
20- CreatedAt time.Time
21- UpdatedAt time.Time
10+ ID string `gorm:"type:uuid;primaryKey"`
11+ Name string `gorm:"not null"`
12+ Year int `gorm:"not null"`
13+ Semester string `gorm:"not null"`
14+ Credit int `gorm:"not null"`
15+ SyllabusID string `gorm:"not null;uniqueIndex"`
16+ Syllabus * Syllabus `gorm:"foreignKey:SyllabusID"`
17+ Faculties []SubjectFaculty `gorm:"foreignKey:SubjectID"`
18+ EligibleAttributes []SubjectEligibleAttribute `gorm:"foreignKey:SubjectID"`
19+ Requirements []SubjectRequirement `gorm:"foreignKey:SubjectID"`
20+ CreatedAt time.Time
21+ UpdatedAt time.Time
22+ }
23+
24+ type SubjectFaculty struct {
25+ ID string `gorm:"type:uuid;primaryKey"`
26+ SubjectID string `gorm:"type:uuid;not null;index"`
27+ FacultyID string `gorm:"type:uuid;not null"`
28+ IsPrimary bool `gorm:"not null"`
2229}
2330
2431type SubjectEligibleAttribute struct {
25- ID string `gorm:"type:uuid;primaryKey"`
26- SubjectID string `gorm:"type:uuid;not null;index"`
27- Grade string `gorm:"type:text; not null"`
28- Class * string `gorm:"type:text"`
32+ ID string `gorm:"type:uuid;primaryKey"`
33+ SubjectID string `gorm:"type:uuid;not null;index"`
34+ Grade string `gorm:"not null"`
35+ Class * string
2936}
3037
3138type SubjectRequirement struct {
3239 ID string `gorm:"type:uuid;primaryKey"`
3340 SubjectID string `gorm:"type:uuid;not null;index"`
34- CourseID string `gorm:"type:uuid;not null"`
35- Course Course `gorm:"foreignKey:CourseID"`
36- RequirementType string `gorm:"type:text;not null"`
41+ Course string `gorm:"not null"`
42+ RequirementType string `gorm:"not null"`
3743}
3844
3945func SubjectToDomain (m Subject ) domain.Subject {
40- slots := make ([]domain.DayOfWeekTimetableSlot , len (m .DayOfWeekTimetableSlots ))
41- for i , s := range m .DayOfWeekTimetableSlots {
42- slots [i ] = DayOfWeekTimetableSlotToDomain (s )
46+ faculties := make ([]domain.SubjectFaculty , len (m .Faculties ))
47+ for i , f := range m .Faculties {
48+ faculties [i ] = domain.SubjectFaculty {
49+ FacultyID : f .FacultyID ,
50+ IsPrimary : f .IsPrimary ,
51+ }
4352 }
4453
4554 eligible := make ([]domain.SubjectTargetClass , len (m .EligibleAttributes ))
@@ -57,33 +66,31 @@ func SubjectToDomain(m Subject) domain.Subject {
5766 requirements := make ([]domain.SubjectRequirement , len (m .Requirements ))
5867 for i , r := range m .Requirements {
5968 requirements [i ] = domain.SubjectRequirement {
60- Course : CourseToDomain (r .Course ),
69+ Course : domain . CourseType (r .Course ),
6170 RequirementType : domain .SubjectRequirementType (r .RequirementType ),
6271 }
6372 }
6473
65- categories := make ([]domain.SubjectCategory , len (m .Categories ))
66- for i , c := range m .Categories {
67- categories [i ] = SubjectCategoryToDomain (c )
68- }
69-
7074 return domain.Subject {
71- ID : m .ID ,
72- Name : m .Name ,
73- Faculty : FacultyToDomain ( m . Faculty ) ,
74- Semester : domain . CourseSemester ( m . Semester ) ,
75- DayOfWeekTimetableSlots : slots ,
76- EligibleAttributes : eligible ,
77- Requirements : requirements ,
78- Categories : categories ,
79- SyllabusID : m .SyllabusID ,
75+ ID : m .ID ,
76+ Name : m .Name ,
77+ Faculties : faculties ,
78+ Year : m . Year ,
79+ Semester : domain . CourseSemester ( m . Semester ) ,
80+ Credit : m . Credit ,
81+ EligibleAttributes : eligible ,
82+ Requirements : requirements ,
83+ SyllabusID : m .SyllabusID ,
8084 }
8185}
8286
8387func SubjectFromDomain (d domain.Subject ) Subject {
84- slots := make ([]DayOfWeekTimetableSlot , len (d .DayOfWeekTimetableSlots ))
85- for i , s := range d .DayOfWeekTimetableSlots {
86- slots [i ] = DayOfWeekTimetableSlotFromDomain (s )
88+ faculties := make ([]SubjectFaculty , len (d .Faculties ))
89+ for i , f := range d .Faculties {
90+ faculties [i ] = SubjectFaculty {
91+ FacultyID : f .FacultyID ,
92+ IsPrimary : f .IsPrimary ,
93+ }
8794 }
8895
8996 eligible := make ([]SubjectEligibleAttribute , len (d .EligibleAttributes ))
@@ -101,27 +108,20 @@ func SubjectFromDomain(d domain.Subject) Subject {
101108 requirements := make ([]SubjectRequirement , len (d .Requirements ))
102109 for i , r := range d .Requirements {
103110 requirements [i ] = SubjectRequirement {
104- CourseID : r .Course .ID ,
105- Course : CourseFromDomain (r .Course ),
111+ Course : string (r .Course ),
106112 RequirementType : string (r .RequirementType ),
107113 }
108114 }
109115
110- categories := make ([]SubjectCategory , len (d .Categories ))
111- for i , c := range d .Categories {
112- categories [i ] = SubjectCategoryFromDomain (c )
113- }
114-
115116 return Subject {
116- ID : d .ID ,
117- Name : d .Name ,
118- FacultyID : d .Faculty .ID ,
119- Faculty : FacultyFromDomain (d .Faculty ),
120- Semester : string (d .Semester ),
121- SyllabusID : d .SyllabusID ,
122- DayOfWeekTimetableSlots : slots ,
123- Categories : categories ,
124- EligibleAttributes : eligible ,
125- Requirements : requirements ,
117+ ID : d .ID ,
118+ Name : d .Name ,
119+ Year : d .Year ,
120+ Semester : string (d .Semester ),
121+ Credit : d .Credit ,
122+ SyllabusID : d .SyllabusID ,
123+ Faculties : faculties ,
124+ EligibleAttributes : eligible ,
125+ Requirements : requirements ,
126126 }
127127}
0 commit comments