using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using UniVerse.Application.DTOs.Courses; using UniVerse.Application.Interfaces; namespace UniVerse.Api.Controllers; [ApiController] [Route("api/v1/courses")] [Authorize] public class CoursesController : ControllerBase { private readonly ICourseService _courses; public CoursesController(ICourseService courses) => _courses = courses; [HttpGet] public async Task GetAll([FromQuery] CourseFilterRequest filter) => Ok(await _courses.GetAllAsync(filter)); [HttpGet("{id:int}")] public async Task> Get(int id) => Ok(await _courses.GetByIdAsync(id)); [Authorize(Roles = "Admin")] [HttpPost] public async Task> Create([FromBody] CreateCourseRequest req) => CreatedAtAction(nameof(Get), new { id = 0 }, await _courses.CreateAsync(req)); [Authorize(Roles = "Admin")] [HttpPut("{id:int}")] public async Task> Update(int id, [FromBody] UpdateCourseRequest req) => Ok(await _courses.UpdateAsync(id, req)); [Authorize(Roles = "Admin")] [HttpDelete("{id:int}")] public async Task Delete(int id) { await _courses.DeleteAsync(id); return NoContent(); } [Authorize(Roles = "Admin")] [HttpPost("{id:int}/tags")] public async Task AddTag(int id, [FromBody] int tagId) { await _courses.AddTagAsync(id, tagId); return NoContent(); } [Authorize(Roles = "Admin")] [HttpDelete("{id:int}/tags/{tagId:int}")] public async Task RemoveTag(int id, int tagId) { await _courses.RemoveTagAsync(id, tagId); return NoContent(); } }