11using FPTStella . Application . Common . Interfaces . Services ;
22using FPTStella . Contracts . DTOs . CLOs ;
3- using Microsoft . AspNetCore . Http ;
43using Microsoft . AspNetCore . Mvc ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Threading . Tasks ;
57
68namespace FPTStella . API . Controllers
79{
@@ -11,43 +13,101 @@ public class CLOController : BaseController
1113 {
1214 private readonly ICLOService _cloService ;
1315
16+ /// <summary>
17+ /// Initializes a new instance of the CLOController class.
18+ /// </summary>
19+ /// <param name="cloService">The CLO service</param>
1420 public CLOController ( ICLOService cloService )
1521 {
1622 _cloService = cloService ;
1723 }
1824
25+ /// <summary>
26+ /// Creates a new CLO.
27+ /// </summary>
28+ /// <param name="createCloDto">DTO containing CLO creation data</param>
29+ /// <returns>The created CLO</returns>
1930 [ HttpPost ]
2031 public async Task < IActionResult > CreateCLO ( [ FromBody ] CreateCLODto createCloDto )
2132 {
2233 try
2334 {
24- var cloId = await _cloService . CreateCloAsync ( createCloDto ) ;
25- return Ok ( new { Id = cloId } ) ;
35+ var clo = await _cloService . CreateCLOAsync ( createCloDto ) ;
36+ return CreatedAtAction ( nameof ( GetCLOById ) , new { id = clo . Id } , clo ) ;
2637 }
27- catch ( ArgumentNullException ex )
38+ catch ( Exception ex )
39+ {
40+ return HandleException ( ex ) ;
41+ }
42+ }
43+
44+ /// <summary>
45+ /// Gets all active CLOs.
46+ /// </summary>
47+ /// <returns>List of all active CLOs</returns>
48+ [ HttpGet ]
49+ public async Task < IActionResult > GetAllCLOs ( )
50+ {
51+ try
2852 {
29- return BadRequest ( new { message = ex . Message } ) ;
53+ var clos = await _cloService . GetAllCLOsAsync ( ) ;
54+ return Ok ( clos ) ;
3055 }
31- catch ( KeyNotFoundException ex )
56+ catch ( Exception ex )
3257 {
33- return NotFound ( new { message = ex . Message } ) ;
58+ return HandleException ( ex ) ;
3459 }
35- catch ( InvalidOperationException ex )
60+ }
61+
62+ /// <summary>
63+ /// Gets a CLO by ID.
64+ /// </summary>
65+ /// <param name="id">CLO ID</param>
66+ /// <returns>CLO with the specified ID</returns>
67+ [ HttpGet ( "{id}" ) ]
68+ public async Task < IActionResult > GetCLOById ( Guid id )
69+ {
70+ try
3671 {
37- return Conflict ( new { message = ex . Message } ) ;
72+ var clo = await _cloService . GetCLOByIdAsync ( id ) ;
73+ return Ok ( clo ) ;
3874 }
3975 catch ( Exception ex )
4076 {
4177 return HandleException ( ex ) ;
4278 }
4379 }
4480
81+ /// <summary>
82+ /// Gets all CLOs for a specific subject.
83+ /// </summary>
84+ /// <param name="subjectId">Subject ID</param>
85+ /// <returns>List of CLOs for the subject</returns>
4586 [ HttpGet ( "subject/{subjectId}" ) ]
4687 public async Task < IActionResult > GetCLOsBySubjectId ( Guid subjectId )
4788 {
4889 try
4990 {
50- var clos = await _cloService . GetClosBySubjectIdAsync ( subjectId ) ;
91+ var clos = await _cloService . GetCLOsBySubjectIdAsync ( subjectId ) ;
92+ return Ok ( clos ) ;
93+ }
94+ catch ( Exception ex )
95+ {
96+ return HandleException ( ex ) ;
97+ }
98+ }
99+
100+ /// <summary>
101+ /// Gets CLOs by a list of subject IDs.
102+ /// </summary>
103+ /// <param name="subjectIds">List of subject IDs</param>
104+ /// <returns>List of CLOs for the subjects</returns>
105+ [ HttpGet ( "subjects" ) ]
106+ public async Task < IActionResult > GetCLOsBySubjectIds ( [ FromQuery ] List < Guid > subjectIds )
107+ {
108+ try
109+ {
110+ var clos = await _cloService . GetCLOsBySubjectIdsAsync ( subjectIds ) ;
51111 return Ok ( clos ) ;
52112 }
53113 catch ( Exception ex )
@@ -56,12 +116,56 @@ public async Task<IActionResult> GetCLOsBySubjectId(Guid subjectId)
56116 }
57117 }
58118
119+ /// <summary>
120+ /// Updates an existing CLO.
121+ /// </summary>
122+ /// <param name="id">CLO ID</param>
123+ /// <param name="updateCLODto">DTO containing update data</param>
124+ /// <returns>NoContent on successful update</returns>
125+ [ HttpPut ( "{id}" ) ]
126+ public async Task < IActionResult > UpdateCLO ( Guid id , [ FromBody ] UpdateCLODto updateCLODto )
127+ {
128+ try
129+ {
130+ await _cloService . UpdateCLOAsync ( id , updateCLODto ) ;
131+ return NoContent ( ) ;
132+ }
133+ catch ( Exception ex )
134+ {
135+ return HandleException ( ex ) ;
136+ }
137+ }
138+
139+ /// <summary>
140+ /// Deletes a CLO by ID.
141+ /// </summary>
142+ /// <param name="id">CLO ID</param>
143+ /// <returns>NoContent on successful deletion</returns>
144+ [ HttpDelete ( "{id}" ) ]
145+ public async Task < IActionResult > DeleteCLO ( Guid id )
146+ {
147+ try
148+ {
149+ await _cloService . DeleteCLOAsync ( id ) ;
150+ return NoContent ( ) ;
151+ }
152+ catch ( Exception ex )
153+ {
154+ return HandleException ( ex ) ;
155+ }
156+ }
157+
158+ /// <summary>
159+ /// Deletes all CLOs for a specific subject.
160+ /// </summary>
161+ /// <param name="subjectId">Subject ID</param>
162+ /// <returns>NoContent on successful deletion</returns>
59163 [ HttpDelete ( "subject/{subjectId}" ) ]
60164 public async Task < IActionResult > DeleteCLOsBySubjectId ( Guid subjectId )
61165 {
62166 try
63167 {
64- await _cloService . DeleteClosBySubjectIdAsync ( subjectId ) ;
168+ await _cloService . DeleteCLOsBySubjectIdAsync ( subjectId ) ;
65169 return NoContent ( ) ;
66170 }
67171 catch ( Exception ex )
0 commit comments