Добавил API проект
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using UniVerse.Application.DTOs.Achievements;
|
||||
using UniVerse.Application.Interfaces;
|
||||
|
||||
namespace UniVerse.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/achievements")]
|
||||
[Authorize]
|
||||
public class AchievementsController : ControllerBase
|
||||
{
|
||||
private readonly IAchievementService _achievements;
|
||||
public AchievementsController(IAchievementService achievements) => _achievements = achievements;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> GetAll() => Ok(await _achievements.GetAllAsync());
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<ActionResult<AchievementDto>> Get(int id) => Ok(await _achievements.GetByIdAsync(id));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<AchievementDto>> Create([FromBody] CreateAchievementRequest req) =>
|
||||
CreatedAtAction(nameof(Get), new { id = 0 }, await _achievements.CreateAsync(req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpPut("{id:int}")]
|
||||
public async Task<ActionResult<AchievementDto>> Update(int id, [FromBody] UpdateAchievementRequest req) =>
|
||||
Ok(await _achievements.UpdateAsync(id, req));
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> Delete(int id) { await _achievements.DeleteAsync(id); return NoContent(); }
|
||||
}
|
||||
Reference in New Issue
Block a user