-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from theImmortalCoders/dev
Release 1.8
- Loading branch information
Showing
50 changed files
with
1,579 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
rag-2-backend/Infrastructure/Common/Mapper/CourseMapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#region | ||
|
||
using rag_2_backend.Infrastructure.Database.Entity; | ||
using rag_2_backend.Infrastructure.Module.Course.Dto; | ||
|
||
#endregion | ||
|
||
namespace rag_2_backend.Infrastructure.Common.Mapper; | ||
|
||
public static class CourseMapper | ||
{ | ||
public static CourseResponse Map(Course course) | ||
{ | ||
return new CourseResponse | ||
{ | ||
Id = course.Id, | ||
Name = course.Name | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#region | ||
|
||
using HttpExceptions.Exceptions; | ||
using rag_2_backend.Infrastructure.Database; | ||
using rag_2_backend.Infrastructure.Database.Entity; | ||
|
||
#endregion | ||
|
||
namespace rag_2_backend.Infrastructure.Dao; | ||
|
||
public class CourseDao(DatabaseContext dbContext) | ||
{ | ||
public virtual Course GetCourseByIdOrThrow(int id) | ||
{ | ||
return dbContext.Courses.SingleOrDefault(u => u.Id == id) ?? | ||
throw new NotFoundException("Course not found"); | ||
} | ||
|
||
public virtual List<Course> GetAllCourses() | ||
{ | ||
return dbContext.Courses.ToList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#region | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
#endregion | ||
|
||
namespace rag_2_backend.Infrastructure.Database.Entity; | ||
|
||
[Table("course_table")] | ||
[Index(nameof(Name), IsUnique = true)] | ||
public class Course | ||
{ | ||
[Key] public int Id { get; init; } | ||
[MaxLength(100)] public string Name { get; set; } = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
rag-2-backend/Infrastructure/Module/Course/CourseController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#region | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using rag_2_backend.Infrastructure.Module.Course.Dto; | ||
|
||
#endregion | ||
|
||
namespace rag_2_backend.Infrastructure.Module.Course; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class CourseController(CourseService courseService) : ControllerBase | ||
{ | ||
/// <summary>Get courses available in system</summary> | ||
[HttpGet] | ||
public async Task<IEnumerable<CourseResponse>> GetCourses() | ||
{ | ||
return await courseService.GetCourses(); | ||
} | ||
|
||
/// <summary>Add new course to system (Admin)</summary> | ||
/// <response code="400">Course with this name already exists</response> | ||
[HttpPost] | ||
[Authorize(Roles = "Admin")] | ||
public void Add([FromBody] [Required] CourseRequest request) | ||
{ | ||
courseService.AddCourse(request); | ||
} | ||
|
||
/// <summary>Edit existing course (Admin)</summary> | ||
/// <response code="404">Course not found</response> | ||
/// <response code="400">Course with this name already exists</response> | ||
[HttpPut("{id:int}")] | ||
[Authorize(Roles = "Admin")] | ||
public void Edit([FromBody] [Required] CourseRequest request, int id) | ||
{ | ||
courseService.EditCourse(request, id); | ||
} | ||
|
||
/// <summary>Remove existing course (Admin)</summary> | ||
/// <response code="404">Course not found</response> | ||
/// <response code="400">Cannot delete used course</response> | ||
[HttpDelete("{id:int}")] | ||
[Authorize(Roles = "Admin")] | ||
public void Remove([Required] int id) | ||
{ | ||
courseService.RemoveCourse(id); | ||
} | ||
} |
Oops, something went wrong.