Compare commits
No commits in common. 'dev' and 'main' have entirely different histories.
@ -1,70 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using CatalogService.Data;
|
|
||||||
using CatalogService.DTOs;
|
|
||||||
using CatalogService.Entities;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Shared.DTOs;
|
|
||||||
|
|
||||||
namespace CatalogService.Controllers;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Authorize]
|
|
||||||
[Route("api/catalog/[controller]")]
|
|
||||||
public class ExercicesController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly CatalogDbContext _context;
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
|
|
||||||
public ExercicesController(CatalogDbContext context, IMapper mapper)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<IActionResult> Create([FromBody] CreateExerciceTemplateDto dto)
|
|
||||||
{
|
|
||||||
var exercice = _mapper.Map<Exercice>(dto);
|
|
||||||
_context.Exercices.Add(exercice);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
return CreatedAtAction(nameof(GetById), new { id = exercice.Id }, _mapper.Map<ExerciceTemplateDto>(exercice));
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("{id}")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<IActionResult> Update(string id, [FromBody] UpdateExerciceTemplateDto dto)
|
|
||||||
{
|
|
||||||
var exercice = await _context.Exercices.FindAsync(id);
|
|
||||||
if (exercice == null) return NotFound();
|
|
||||||
|
|
||||||
_mapper.Map(dto, exercice);
|
|
||||||
exercice.UpdatedAt = DateTime.UtcNow;
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpDelete("{id}")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<IActionResult> Delete(string id)
|
|
||||||
{
|
|
||||||
var exercice = await _context.Exercices.FindAsync(id);
|
|
||||||
if (exercice == null) return NotFound();
|
|
||||||
|
|
||||||
_context.Exercices.Remove(exercice);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<ActionResult<ExerciceTemplateDto>> GetById(string id)
|
|
||||||
{
|
|
||||||
var exercice = await _context.Exercices.FindAsync(id);
|
|
||||||
if (exercice == null) return NotFound();
|
|
||||||
|
|
||||||
return _mapper.Map<ExerciceTemplateDto>(exercice);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Shared.Enum;
|
|
||||||
|
|
||||||
namespace CatalogService.DTOs;
|
|
||||||
|
|
||||||
public class UpdateExerciceTemplateDto
|
|
||||||
{
|
|
||||||
public string? Name { get; set; }
|
|
||||||
|
|
||||||
public string? Description { get; set; }
|
|
||||||
|
|
||||||
public ETarget? Target { get; set; }
|
|
||||||
|
|
||||||
public string? ImageUrl { get; set; }
|
|
||||||
|
|
||||||
public string? VideoUrl { get; set; }
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using CatalogService.DTOs;
|
|
||||||
using CatalogService.Entities;
|
|
||||||
|
|
||||||
namespace CatalogService.RequestHelpers;
|
|
||||||
|
|
||||||
public class MappingProfiles : Profile
|
|
||||||
{
|
|
||||||
public MappingProfiles()
|
|
||||||
{
|
|
||||||
CreateMap<Exercice, ExerciceTemplateDto>();
|
|
||||||
CreateMap<ExerciceTemplateDto, Exercice>();
|
|
||||||
CreateMap<CreateExerciceTemplateDto, Exercice>();
|
|
||||||
CreateMap<UpdateExerciceTemplateDto, Exercice>();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Shared.DTOs;
|
|
||||||
|
|
||||||
public class DeleteDto
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public required string Id { get; set; }
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
using Shared.Enum;
|
using Shared.Enum;
|
||||||
|
|
||||||
namespace CatalogService.DTOs;
|
namespace Shared.DTOs;
|
||||||
|
|
||||||
public class ExerciceTemplateDto
|
public class ExerciceTemplateDto
|
||||||
{
|
{
|
@ -1,231 +0,0 @@
|
|||||||
{
|
|
||||||
"info": {
|
|
||||||
"_postman_id": "c019ebd5-bed6-49ea-a584-086e91bfe503",
|
|
||||||
"name": "Catalog Exercices",
|
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
|
||||||
},
|
|
||||||
"item": [
|
|
||||||
{
|
|
||||||
"name": "Créer un exercice",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"var jsonData = pm.response.json();",
|
|
||||||
"pm.test('Status code is 201', function() {",
|
|
||||||
" pm.response.to.have.status(201);",
|
|
||||||
"});",
|
|
||||||
"pm.test('L\'exercice a un id', function() {",
|
|
||||||
" pm.expect(jsonData.id).to.be.a('string');",
|
|
||||||
"});",
|
|
||||||
"pm.environment.set('exerciceId', jsonData.id);"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\n \"name\": \"Pompes\",\n \"description\": \"Exercice de musculation pour les pectoraux\",\n \"target\": 1,\n \"imageUrl\": \"images/pompes.jpg\",\n \"videoUrl\": \"https://www.youtube.com/watch?v=IODxDxX7oi4\"\n}"
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Récupérer l'exercice par id",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"var jsonData = pm.response.json();",
|
|
||||||
"pm.test('Status code is 200', function() {",
|
|
||||||
" pm.response.to.have.status(200);",
|
|
||||||
"});",
|
|
||||||
"pm.test('Nom de l\\'exercice est Pompes', function() {",
|
|
||||||
" pm.expect(jsonData.name).to.eq('Pompes');",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [],
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices/{{exerciceId}}",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices",
|
|
||||||
"{{exerciceId}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mettre à jour l'exercice",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"pm.test('Status code is 204', function() {",
|
|
||||||
" pm.response.to.have.status(204);",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "PUT",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\n \"id\": \"{{exerciceId}}\",\n \"name\": \"Pompes modifiées\",\n \"description\": \"Exercice modifié\",\n \"target\": 2,\n \"imageUrl\": \"images/pompes_mod.jpg\",\n \"videoUrl\": \"https://www.youtube.com/watch?v=abcd\"\n}"
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices/{{exerciceId}}",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices",
|
|
||||||
"{{exerciceId}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Vérifier la mise à jour",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"var jsonData = pm.response.json();",
|
|
||||||
"pm.test('Status code is 200', function() {",
|
|
||||||
" pm.response.to.have.status(200);",
|
|
||||||
"});",
|
|
||||||
"pm.test('Nom de l\\'exercice est Pompes modifiées', function() {",
|
|
||||||
" pm.expect(jsonData.name).to.eq('Pompes modifiées');",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [],
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices/{{exerciceId}}",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices",
|
|
||||||
"{{exerciceId}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Supprimer l'exercice",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"pm.test('Status code is 204', function() {",
|
|
||||||
" pm.response.to.have.status(204);",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "DELETE",
|
|
||||||
"header": [],
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices/{{exerciceId}}",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices",
|
|
||||||
"{{exerciceId}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Vérifier la suppression",
|
|
||||||
"event": [
|
|
||||||
{
|
|
||||||
"listen": "test",
|
|
||||||
"script": {
|
|
||||||
"exec": [
|
|
||||||
"pm.test('Status code is 404', function() {",
|
|
||||||
" pm.response.to.have.status(404);",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"type": "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [],
|
|
||||||
"url": {
|
|
||||||
"raw": "{{catalogApi}}/api/exercices/{{exerciceId}}",
|
|
||||||
"host": [
|
|
||||||
"{{catalogApi}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"exercices",
|
|
||||||
"{{exerciceId}}"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"variable": [
|
|
||||||
{
|
|
||||||
"key": "catalogApi",
|
|
||||||
"value": "http://localhost:5000"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Reference in new issue