Skip to content

Commit 6ca5001

Browse files
committed
Merge branch 'ThucSIT' into SIT
2 parents 80415ff + 6713031 commit 6ca5001

15 files changed

Lines changed: 585 additions & 70 deletions

File tree

FPTStella/FPTStella.API/Controllers/CLOController.cs

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using FPTStella.Application.Common.Interfaces.Services;
22
using FPTStella.Contracts.DTOs.CLOs;
3-
using Microsoft.AspNetCore.Http;
43
using Microsoft.AspNetCore.Mvc;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
57

68
namespace 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)

FPTStella/FPTStella.API/Controllers/CLO_PLO_MappingController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,18 @@ public async Task<IActionResult> UpdateCloMapping([FromBody] PatchCloMappingDto
158158
return BadRequest(ex.Message);
159159
}
160160
}
161+
[HttpGet("plo-details/{cloId}")]
162+
public async Task<IActionResult> GetPloDetailsWithCurriculumByCloId(Guid cloId)
163+
{
164+
try
165+
{
166+
var plos = await _cloPlaMappingService.GetPLOsWithDetailsByCloIdAsync(cloId);
167+
return Ok(plos);
168+
}
169+
catch (Exception ex)
170+
{
171+
return HandleException(ex);
172+
}
161173
}
174+
}
162175
}

FPTStella/FPTStella.Application/Common/Interfaces/Repositories/ICLORepository.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using FPTStella.Domain.Entities;
33
using System;
44
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
75
using System.Threading.Tasks;
86

97
namespace FPTStella.Application.Common.Interfaces.Repositories
@@ -18,17 +16,32 @@ public interface ICLORepository : IRepository<CLOs>
1816
Task<List<CLOs>> GetBySubjectIdAsync(Guid subjectId);
1917

2018
/// <summary>
21-
/// Checks if a CLO exists for a specific subject with the given details
19+
/// Checks if a CLO with the given name exists for a specific subject.
20+
/// </summary>
21+
/// <param name="subjectId">Subject ID</param>
22+
/// <param name="cloName">CLO name to check</param>
23+
/// <returns>True if exists, false otherwise</returns>
24+
Task<bool> IsCloNameExistedAsync(Guid subjectId, string cloName);
25+
26+
/// <summary>
27+
/// Checks if a CLO exists for a specific subject with the given details.
2228
/// </summary>
2329
/// <param name="subjectId">Subject ID</param>
2430
/// <param name="cloDetails">CLO details to check</param>
2531
/// <returns>True if exists, false otherwise</returns>
26-
Task<bool> IsCloExistedAsync(Guid subjectId, string cloDetails);
32+
Task<bool> IsCloDetailsExistedAsync(Guid subjectId, string cloDetails);
33+
34+
/// <summary>
35+
/// Gets CLOs by a list of Subject IDs.
36+
/// </summary>
37+
/// <param name="subjectIds">List of Subject IDs</param>
38+
/// <returns>List of CLOs</returns>
39+
Task<List<CLOs>> GetBySubjectIdsAsync(List<Guid> subjectIds);
2740

2841
/// <summary>
29-
/// Deletes CLOs associated with a subject
42+
/// Deletes CLOs associated with a specific Subject ID.
3043
/// </summary>
3144
/// <param name="subjectId">Subject ID</param>
32-
Task DeleteClosBySubjectIdAsync(Guid subjectId);
45+
Task DeleteBySubjectIdAsync(Guid subjectId);
3346
}
34-
}
47+
}

FPTStella/FPTStella.Application/Common/Interfaces/Repositories/ICLO_PLO_MappingRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@ public interface ICLO_PLO_MappingRepository : IRepository<CLO_PLO_Mapping>
8282
/// Adds multiple mappings at once.
8383
/// </summary>
8484
Task AddManyAsync(IEnumerable<CLO_PLO_Mapping> mappings);
85+
Task<List<(Guid Id, string PloName, string CurriculumName, string Description)>> GetPLOsWithDetailsByCloIdAsync(Guid cloId);
86+
8587
}
86-
}
88+
}
Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,79 @@
11
using FPTStella.Contracts.DTOs.CLOs;
22
using System;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
64
using System.Threading.Tasks;
75

86
namespace FPTStella.Application.Common.Interfaces.Services
97
{
108
public interface ICLOService
119
{
12-
Task<Guid> CreateCloAsync(CreateCLODto createCloDto);
13-
Task<List<CLOWithDetailsDto>> GetClosBySubjectIdAsync(Guid subjectId);
14-
Task DeleteClosBySubjectIdAsync(Guid subjectId);
10+
/// <summary>
11+
/// Creates a new CLO.
12+
/// </summary>
13+
/// <param name="createCLODto">The DTO containing CLO creation data</param>
14+
/// <returns>The newly created CLO as a DTO</returns>
15+
Task<CLOWithDetailsDto> CreateCLOAsync(CreateCLODto createCLODto);
16+
17+
/// <summary>
18+
/// Gets all active CLOs.
19+
/// </summary>
20+
/// <returns>A list of all active CLOs as DTOs</returns>
21+
Task<List<CLOWithDetailsDto>> GetAllCLOsAsync();
22+
23+
/// <summary>
24+
/// Gets a CLO by its ID.
25+
/// </summary>
26+
/// <param name="id">The CLO ID</param>
27+
/// <returns>The CLO as a DTO</returns>
28+
Task<CLOWithDetailsDto> GetCLOByIdAsync(Guid id);
29+
30+
/// <summary>
31+
/// Gets CLOs by a Subject ID.
32+
/// </summary>
33+
/// <param name="subjectId">The Subject ID</param>
34+
/// <returns>A list of CLOs as DTOs</returns>
35+
Task<List<CLOWithDetailsDto>> GetCLOsBySubjectIdAsync(Guid subjectId);
36+
37+
/// <summary>
38+
/// Gets CLOs by a list of Subject IDs.
39+
/// </summary>
40+
/// <param name="subjectIds">The list of Subject IDs</param>
41+
/// <returns>A list of CLOs as DTOs</returns>
42+
Task<List<CLOWithDetailsDto>> GetCLOsBySubjectIdsAsync(List<Guid> subjectIds);
43+
44+
/// <summary>
45+
/// Checks if a CLO with the given name exists for a specific subject.
46+
/// </summary>
47+
/// <param name="subjectId">The Subject ID</param>
48+
/// <param name="cloName">The CLO name</param>
49+
/// <returns>True if the CLO exists, false otherwise</returns>
50+
Task<bool> IsCloNameExistedAsync(Guid subjectId, string cloName);
51+
52+
/// <summary>
53+
/// Checks if a CLO with the given details exists for a specific subject.
54+
/// </summary>
55+
/// <param name="subjectId">The Subject ID</param>
56+
/// <param name="cloDetails">The CLO details</param>
57+
/// <returns>True if the CLO exists, false otherwise</returns>
58+
Task<bool> IsCloDetailsExistedAsync(Guid subjectId, string cloDetails);
59+
60+
/// <summary>
61+
/// Updates an existing CLO.
62+
/// </summary>
63+
/// <param name="id">The CLO ID</param>
64+
/// <param name="updateCLODto">The DTO containing update data</param>
65+
Task UpdateCLOAsync(Guid id, UpdateCLODto updateCLODto);
66+
67+
/// <summary>
68+
/// Soft deletes a CLO by setting its DeleteFlag.
69+
/// </summary>
70+
/// <param name="id">The CLO ID</param>
71+
Task DeleteCLOAsync(Guid id);
72+
73+
/// <summary>
74+
/// Deletes all CLOs by Subject ID.
75+
/// </summary>
76+
/// <param name="subjectId">The Subject ID</param>
77+
Task DeleteCLOsBySubjectIdAsync(Guid subjectId);
1578
}
16-
}
79+
}

FPTStella/FPTStella.Application/Common/Interfaces/Services/ICLO_PLO_MappingService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FPTStella.Contracts.DTOs.CLO_PLO_Mappings;
22
using FPTStella.Contracts.DTOs.CLOs;
3+
using FPTStella.Contracts.DTOs.PLOs;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -21,5 +22,7 @@ public interface ICLO_PLO_MappingService
2122
Task<UpdateCLO_PLO_MappingResultDto> UpdateMappingsAsync(UpdateCLO_PLO_MappingBatchDto updateMappingBatchDto);
2223
Task UpdateCloPlaMappingAsync(PatchCloPloMappingDto dto);
2324
Task UpdateCloMappingAsync(PatchCloMappingDto dto);
25+
Task<List<PLOWithCurriculumDto>> GetPLOsWithDetailsByCloIdAsync(Guid cloId);
26+
2427
}
2528
}

0 commit comments

Comments
 (0)