@@ -15,28 +15,46 @@ public class SubjectInCurriculumService : ISubjectInCurriculumService
1515 {
1616 private readonly IUnitOfWork _unitOfWork ;
1717 private readonly ISubjectInCurriculumRepository _subjectInCurriculumRepository ;
18- /// <summary>
18+ private readonly ISubjectRepository _subjectRepository ;
1919 /// Initializes a new instance of the SubjectInCurriculumService class.
2020 /// </summary>
2121 /// <param name="unitOfWork">The unit of work</param>
2222 /// <param name="subjectInCurriculumRepository">The subject in curriculum repository</param>
23- public SubjectInCurriculumService ( IUnitOfWork unitOfWork , ISubjectInCurriculumRepository subjectInCurriculumRepository )
23+ /// <param name="subjectRepository">The subject repository</param>
24+ public SubjectInCurriculumService (
25+ IUnitOfWork unitOfWork ,
26+ ISubjectInCurriculumRepository subjectInCurriculumRepository ,
27+ ISubjectRepository subjectRepository )
2428 {
2529 _unitOfWork = unitOfWork ?? throw new ArgumentNullException ( nameof ( unitOfWork ) ) ;
2630 _subjectInCurriculumRepository = subjectInCurriculumRepository ?? throw new ArgumentNullException ( nameof ( subjectInCurriculumRepository ) ) ;
31+ _subjectRepository = subjectRepository ?? throw new ArgumentNullException ( nameof ( subjectRepository ) ) ;
2732 }
2833
2934 /// <summary>
3035 /// Maps a SubjectInCurriculum entity to its DTO representation.
3136 /// </summary>
3237 /// <param name="entity">The SubjectInCurriculum entity</param>
3338 /// <returns>A mapped SubjectInCurriculumDto object</returns>
34- private static SubjectInCurriculumDto MapToDto ( SubjectInCurriculum entity ) => new ( )
39+ private async Task < SubjectInCurriculumDto > MapToDtoAsync ( SubjectInCurriculum entity )
3540 {
36- Id = entity . Id ,
37- CurriculumId = entity . CurriculumId ,
38- SubjectId = entity . SubjectId
39- } ;
41+ var dto = new SubjectInCurriculumDto
42+ {
43+ Id = entity . Id ,
44+ CurriculumId = entity . CurriculumId ,
45+ SubjectId = entity . SubjectId
46+ } ;
47+
48+ // Fetch the subject details
49+ var subject = await _subjectRepository . GetByIdAsync ( entity . SubjectId . ToString ( ) ) ;
50+ if ( subject != null && ! subject . DelFlg )
51+ {
52+ dto . SubjectCode = subject . SubjectCode ;
53+ dto . SubjectName = subject . SubjectName ;
54+ }
55+
56+ return dto ;
57+ }
4058
4159 /// <summary>
4260 /// Creates a new mapping between a subject and a curriculum.
@@ -62,7 +80,7 @@ public async Task<SubjectInCurriculumDto> CreateMappingAsync(CreateSubjectInCurr
6280 await _subjectInCurriculumRepository . InsertAsync ( mapping ) ;
6381 await _unitOfWork . SaveAsync ( ) ;
6482
65- return MapToDto ( mapping ) ;
83+ return await MapToDtoAsync ( mapping ) ;
6684 }
6785
6886 /// <summary>
@@ -125,7 +143,7 @@ public async Task<SubjectInCurriculumDto> GetMappingByIdAsync(Guid id)
125143 throw new KeyNotFoundException ( $ "Subject-Curriculum mapping with ID { id } not found.") ;
126144 }
127145
128- return MapToDto ( mapping ) ;
146+ return await MapToDtoAsync ( mapping ) ;
129147 }
130148
131149 /// <summary>
@@ -135,7 +153,14 @@ public async Task<SubjectInCurriculumDto> GetMappingByIdAsync(Guid id)
135153 public async Task < List < SubjectInCurriculumDto > > GetAllMappingsAsync ( )
136154 {
137155 var mappings = await _subjectInCurriculumRepository . FilterByAsync ( m => ! m . DelFlg ) ;
138- return mappings . Select ( MapToDto ) . ToList ( ) ;
156+ var result = new List < SubjectInCurriculumDto > ( ) ;
157+
158+ foreach ( var mapping in mappings )
159+ {
160+ result . Add ( await MapToDtoAsync ( mapping ) ) ;
161+ }
162+
163+ return result ;
139164 }
140165
141166 /// <summary>
@@ -146,7 +171,14 @@ public async Task<List<SubjectInCurriculumDto>> GetAllMappingsAsync()
146171 public async Task < List < SubjectInCurriculumDto > > GetMappingsByCurriculumIdAsync ( Guid curriculumId )
147172 {
148173 var mappings = await _subjectInCurriculumRepository . GetByCurriculumIdAsync ( curriculumId ) ;
149- return mappings . Select ( MapToDto ) . ToList ( ) ;
174+ var result = new List < SubjectInCurriculumDto > ( ) ;
175+
176+ foreach ( var mapping in mappings )
177+ {
178+ result . Add ( await MapToDtoAsync ( mapping ) ) ;
179+ }
180+
181+ return result ;
150182 }
151183
152184 /// <summary>
@@ -157,7 +189,14 @@ public async Task<List<SubjectInCurriculumDto>> GetMappingsByCurriculumIdAsync(G
157189 public async Task < List < SubjectInCurriculumDto > > GetMappingsBySubjectIdAsync ( Guid subjectId )
158190 {
159191 var mappings = await _subjectInCurriculumRepository . GetBySubjectIdAsync ( subjectId ) ;
160- return mappings . Select ( MapToDto ) . ToList ( ) ;
192+ var result = new List < SubjectInCurriculumDto > ( ) ;
193+
194+ foreach ( var mapping in mappings )
195+ {
196+ result . Add ( await MapToDtoAsync ( mapping ) ) ;
197+ }
198+
199+ return result ;
161200 }
162201
163202 /// <summary>
0 commit comments