1- using AskAMuslimAPI . Enums ;
1+ using AskAMuslimAPI . DTOs . CourseDTOs ;
2+ using AskAMuslimAPI . Enums ;
23using AutoMapper ;
34using EdufyAPI . DTOs ;
45using EdufyAPI . DTOs . CourseDTOs ;
@@ -81,14 +82,14 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetCourses()
8182 /// <param name="id">The unique identifier of the course.</param>
8283 /// <returns>The course details if found; otherwise, NotFound.</returns>
8384 [ HttpGet ( "{id}" ) ]
84- public async Task < ActionResult < CourseReadDTO > > GetCourseById ( string id )
85+ public async Task < ActionResult < CourseReadByIdDTO > > GetCourseById ( string id )
8586 {
8687 const string cacheKeyPrefix = "course_" ; // Cache prefix for individual course.
8788 var cacheKey = $ "{ cacheKeyPrefix } { id } ";
8889
8990 try
9091 {
91- var courseDto = await _memoryCache . GetDataAsync < CourseReadDTO > ( cacheKey ) ;
92+ var courseDto = await _memoryCache . GetDataAsync < CourseReadByIdDTO > ( cacheKey ) ;
9293
9394 if ( courseDto == null )
9495 {
@@ -97,7 +98,7 @@ public async Task<ActionResult<CourseReadDTO>> GetCourseById(string id)
9798 if ( course == null )
9899 return NotFound ( "Course not found." ) ;
99100
100- courseDto = _mapper . Map < CourseReadDTO > ( course ) ;
101+ courseDto = _mapper . Map < CourseReadByIdDTO > ( course ) ;
101102 courseDto . ThumbnailUrl = ConstructFileUrlHelper . ConstructFileUrl ( Request , ThumbnailsFolderName , courseDto . ThumbnailUrl ) ;
102103
103104 await _memoryCache . SetDataAsync ( cacheKey , courseDto , DateTimeOffset . Now . AddMinutes ( 5 ) ) ;
@@ -115,14 +116,14 @@ public async Task<ActionResult<CourseReadDTO>> GetCourseById(string id)
115116 }
116117
117118 [ HttpGet ( "ByName/{categoryName}" ) ]
118- public async Task < ActionResult < IEnumerable < CourseReadDTO > > > GetCourseByCategoryName ( string categoryName )
119+ public async Task < ActionResult < IEnumerable < CourseReadByIdDTO > > > GetCourseByCategoryName ( string categoryName )
119120 {
120121 const string cacheKeyPrefix = "course_category_name_" ;
121122 var cacheKey = $ "{ cacheKeyPrefix } { categoryName . ToLower ( ) } ";
122123
123124 try
124125 {
125- var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadDTO > > ( cacheKey ) ;
126+ var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadByIdDTO > > ( cacheKey ) ;
126127 if ( courseDtos == null )
127128 {
128129 if ( ! Enum . TryParse ( typeof ( CourseCategory ) , categoryName , true , out var categoryEnum ) )
@@ -134,9 +135,9 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetCourseByCategoryN
134135 . GetByCondition ( c => c . Category == category ) ;
135136
136137 if ( ! courses . Any ( ) )
137- return Ok ( Enumerable . Empty < CourseReadDTO > ( ) ) ;
138+ return Ok ( Enumerable . Empty < CourseReadByIdDTO > ( ) ) ;
138139
139- courseDtos = _mapper . Map < IEnumerable < CourseReadDTO > > ( courses ) ;
140+ courseDtos = _mapper . Map < IEnumerable < CourseReadByIdDTO > > ( courses ) ;
140141
141142 foreach ( var courseDto in courseDtos )
142143 {
@@ -159,14 +160,14 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetCourseByCategoryN
159160
160161 // Get Courses by its Level
161162 [ HttpGet ( "ByLevelName/{levelName}" ) ]
162- public async Task < ActionResult < IEnumerable < CourseReadDTO > > > GetCourseByLevelName ( string levelName )
163+ public async Task < ActionResult < IEnumerable < CourseReadByIdDTO > > > GetCourseByLevelName ( string levelName )
163164 {
164165 const string cacheKeyPrefix = "course_level_name_" ;
165166 var cacheKey = $ "{ cacheKeyPrefix } { levelName . ToLower ( ) } ";
166167
167168 try
168169 {
169- var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadDTO > > ( cacheKey ) ;
170+ var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadByIdDTO > > ( cacheKey ) ;
170171 if ( courseDtos == null )
171172 {
172173 if ( ! Enum . TryParse ( typeof ( CourseLevel ) , levelName , true , out var levelEnum ) )
@@ -178,9 +179,9 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetCourseByLevelName
178179 . GetByCondition ( c => c . Level == level ) ;
179180
180181 if ( ! courses . Any ( ) )
181- return Ok ( Enumerable . Empty < CourseReadDTO > ( ) ) ;
182+ return Ok ( Enumerable . Empty < CourseReadByIdDTO > ( ) ) ;
182183
183- courseDtos = _mapper . Map < IEnumerable < CourseReadDTO > > ( courses ) ;
184+ courseDtos = _mapper . Map < IEnumerable < CourseReadByIdDTO > > ( courses ) ;
184185
185186 foreach ( var courseDto in courseDtos )
186187 {
@@ -207,12 +208,12 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetCourseByLevelName
207208 /// <param name="instructorId">The unique identifier of the instructor.</param>
208209 /// <returns>A list of courses assigned to the instructor.</returns>
209210 [ HttpGet ( "{instructorId}" ) ]
210- public async Task < ActionResult < IEnumerable < CourseReadDTO > > > GetInstructorCourses ( string instructorId )
211+ public async Task < ActionResult < IEnumerable < CourseReadByIdDTO > > > GetInstructorCourses ( string instructorId )
211212 {
212213 const string cacheKeyPrefix = "instructor_courses_" ; // Cache prefix for courses by instructor.
213214 var cacheKey = $ "{ cacheKeyPrefix } { instructorId } ";
214215
215- var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadDTO > > ( cacheKey ) ;
216+ var courseDtos = await _memoryCache . GetDataAsync < IEnumerable < CourseReadByIdDTO > > ( cacheKey ) ;
216217
217218 try
218219 {
@@ -221,9 +222,9 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetInstructorCourses
221222 // Cache is empty, so retrieve from database.
222223 var courses = await _unitOfWork . CourseRepository . GetByCondition ( c => c . InstructorId == instructorId ) ;
223224 if ( ! courses . Any ( ) )
224- return Ok ( Enumerable . Empty < CourseReadDTO > ( ) ) ;
225+ return Ok ( Enumerable . Empty < CourseReadByIdDTO > ( ) ) ;
225226
226- courseDtos = _mapper . Map < IEnumerable < CourseReadDTO > > ( courses ) ;
227+ courseDtos = _mapper . Map < IEnumerable < CourseReadByIdDTO > > ( courses ) ;
227228 foreach ( var courseDto in courseDtos )
228229 {
229230 courseDto . ThumbnailUrl = ConstructFileUrlHelper . ConstructFileUrl ( Request , ThumbnailsFolderName , courseDto . ThumbnailUrl ) ;
@@ -249,7 +250,7 @@ public async Task<ActionResult<IEnumerable<CourseReadDTO>>> GetInstructorCourses
249250 /// <param name="courseCreateDto">The course creation request object.</param>
250251 /// <returns>The created course details.</returns>
251252 [ HttpPost ]
252- public async Task < ActionResult < CourseReadDTO > > CreateCourse ( [ FromForm ] CourseCreateDTO courseCreateDto )
253+ public async Task < ActionResult < CourseReadByIdDTO > > CreateCourse ( [ FromForm ] CourseCreateDTO courseCreateDto )
253254 {
254255 if ( ! ModelState . IsValid ) return BadRequest ( ModelState ) ;
255256
@@ -263,7 +264,7 @@ public async Task<ActionResult<CourseReadDTO>> CreateCourse([FromForm] CourseCre
263264 course . ThumbnailUrl = imageUrl ;
264265 await _unitOfWork . CourseRepository . AddAsync ( course ) ;
265266 await _unitOfWork . SaveChangesAsync ( ) ;
266- var courseReadDto = _mapper . Map < CourseReadDTO > ( course ) ;
267+ var courseReadDto = _mapper . Map < CourseReadByIdDTO > ( course ) ;
267268
268269 // Invalidate the cache for all courses after a new course is created.
269270 await _memoryCache . RemoveDataAsync ( "all_courses" ) ;
@@ -308,7 +309,7 @@ public async Task<IActionResult> UpdateCourse(string id, [FromForm] CourseUpdate
308309 // Invalidate the cache for all courses after an update.
309310 await _memoryCache . RemoveDataAsync ( "all_courses" ) ;
310311
311- return Ok ( _mapper . Map < CourseReadDTO > ( course ) ) ;
312+ return Ok ( _mapper . Map < CourseReadByIdDTO > ( course ) ) ;
312313 }
313314 catch ( Exception ex )
314315 {
0 commit comments