@@ -2,32 +2,68 @@ import { Injectable, NotFoundException } from '@nestjs/common';
22import { CreateCourseDto } from './dto/create-course.dto' ;
33import { UpdateCourseDto } from './dto/update-course.dto' ;
44
5+ /**
6+ * CoursesService
7+ *
8+ * Contains the business logic for managing courses (CRUD operations).
9+ * Currently uses stub/placeholder logic; real persistence (e.g. via a
10+ * repository or ORM) still needs to be implemented.
11+ */
512@Injectable ( )
613export class CoursesService {
14+ /**
15+ * Creates a new course.
16+ * TODO: persist the course via a repository instead of just returning it.
17+ */
718 create ( dto : CreateCourseDto ) {
819 // TODO: persist via repository
20+ // Temporary: fake an id using the current timestamp
921 return { ...dto , id : Date . now ( ) } ;
1022 }
1123
24+ /**
25+ * Retrieves all courses.
26+ * TODO: fetch the list from a repository/database.
27+ */
1228 findAll ( ) {
1329 // TODO: query repository
30+ // Temporary: no data source yet, so return an empty array
1431 return [ ] ;
1532 }
1633
34+ /**
35+ * Retrieves a single course by id.
36+ * TODO: fetch the course from a repository/database.
37+ * Throws a NotFoundException if the course doesn't exist.
38+ */
1739 findOne ( id : number ) {
1840 // TODO: query repository
41+ // Temporary: no data source yet, so this is always null
1942 const course = null ;
43+
44+ // Guard clause: bail out with a 404-style error if nothing was found
2045 if ( ! course ) throw new NotFoundException ( `Course #${ id } not found` ) ;
46+
2147 return course ;
2248 }
2349
50+ /**
51+ * Updates an existing course by id.
52+ * TODO: look up the existing course, then persist the merged changes.
53+ */
2454 update ( id : number , dto : UpdateCourseDto ) {
2555 // TODO: query then persist
56+ // Temporary: just echo back the id and updated fields
2657 return { id, ...dto } ;
2758 }
2859
60+ /**
61+ * Removes a course by id.
62+ * TODO: actually delete the record from the repository/database.
63+ */
2964 remove ( id : number ) {
3065 // TODO: delete from repository
66+ // Temporary: just acknowledge the deletion request
3167 return { deleted : id } ;
3268 }
33- }
69+ }
0 commit comments