|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using CatalogService.Data;
|
|
|
|
|
using CatalogService.DTOs;
|
|
|
|
@ -11,7 +10,8 @@ using Shared.DTOs;
|
|
|
|
|
namespace CatalogService.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/catalog/[controller]")]
|
|
|
|
|
public class ExercicesController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly CatalogDbContext _context;
|
|
|
|
@ -23,11 +23,12 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
_mapper = mapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[Authorize]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<IActionResult> Create([FromBody] CreateExerciceTemplateDto dto)
|
|
|
|
|
{
|
|
|
|
|
//if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
|
|
|
|
|
var exercice = _mapper.Map<Exercice>(dto);
|
|
|
|
|
_context.Exercices.Add(exercice);
|
|
|
|
@ -35,11 +36,12 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
return CreatedAtAction(nameof(GetById), new { id = exercice.Id }, _mapper.Map<ExerciceTemplateDto>(exercice));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[Authorize]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<IActionResult> Update(string id, [FromBody] UpdateExerciceTemplateDto dto)
|
|
|
|
|
{
|
|
|
|
|
//if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
|
|
|
|
|
var exercice = await _context.Exercices.FindAsync(id);
|
|
|
|
|
if (exercice == null) return NotFound();
|
|
|
|
@ -50,11 +52,12 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[Authorize]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<IActionResult> Delete(string id)
|
|
|
|
|
{
|
|
|
|
|
//if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
|
|
|
|
|
var exercice = await _context.Exercices.FindAsync(id);
|
|
|
|
|
if (exercice == null) return NotFound();
|
|
|
|
@ -64,24 +67,16 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[Authorize]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<ActionResult<ExerciceTemplateDto>> GetById(string id)
|
|
|
|
|
{
|
|
|
|
|
//if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
|
|
|
|
|
var exercice = await _context.Exercices.FindAsync(id);
|
|
|
|
|
if (exercice == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return _mapper.Map<ExerciceTemplateDto>(exercice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<ExerciceTemplateDto>>> GetAll()
|
|
|
|
|
{
|
|
|
|
|
//if (User.Identity.Name != "admin") return Forbid();
|
|
|
|
|
|
|
|
|
|
var exercices = await _context.Exercices.ToListAsync();
|
|
|
|
|
return Ok(_mapper.Map<IEnumerable<ExerciceTemplateDto>>(exercices));
|
|
|
|
|
}
|
|
|
|
|
}
|