Compare commits
3 Commits
main
...
TrainingPr
Author | SHA1 | Date |
---|---|---|
|
abe52d71c2 | 4 months ago |
|
55eb74c93b | 4 months ago |
|
53d4dadf68 | 4 months ago |
@ -1,75 +0,0 @@
|
|||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: default
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet restore API_dotnet.sln
|
|
||||||
- dotnet build API_dotnet.sln -c Release --no-restore
|
|
||||||
- dotnet publish API_dotnet.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
|
|
||||||
|
|
||||||
- name: tests
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet restore API_dotnet.sln
|
|
||||||
- dotnet test API_dotnet.sln --no-restore
|
|
||||||
depends_on: [build]
|
|
||||||
|
|
||||||
- name: code-inspection
|
|
||||||
image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet8
|
|
||||||
secrets: [ SECRET_SONAR_LOGIN ]
|
|
||||||
environment:
|
|
||||||
sonar_host: https://codefirst.iut.uca.fr/sonar/
|
|
||||||
sonar_token:
|
|
||||||
from_secret: SECRET_SONAR_LOGIN # Secret de Drone
|
|
||||||
project_key: Optifit_API_ef
|
|
||||||
commands:
|
|
||||||
- dotnet restore API_dotnet.sln
|
|
||||||
- dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.login=$${sonar_token}
|
|
||||||
- dotnet build API_dotnet.sln -c Release --no-restore
|
|
||||||
- dotnet test API_dotnet.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
|
|
||||||
- reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
|
|
||||||
- dotnet publish API_dotnet.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
|
|
||||||
- dotnet sonarscanner end /d:sonar.login=$${sonar_token}
|
|
||||||
when:
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
event:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
depends_on: [build,tests]
|
|
||||||
|
|
||||||
- name: docker-build-and-push
|
|
||||||
image: plugins/docker
|
|
||||||
settings:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: .
|
|
||||||
registry: hub.codefirst.iut.uca.fr
|
|
||||||
repo: hub.codefirst.iut.uca.fr/louis.laborie/optifit_ef_api
|
|
||||||
username:
|
|
||||||
from_secret: SECRET_REGISTRY_USERNAME
|
|
||||||
password:
|
|
||||||
from_secret: SECRET_REGISTRY_PASSWORD
|
|
||||||
when:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
- rebase
|
|
||||||
- pipeline
|
|
||||||
|
|
||||||
- name: deploy-container
|
|
||||||
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
|
||||||
environment:
|
|
||||||
IMAGENAME: hub.codefirst.iut.uca.fr/louis.laborie/optifit_ef_api:latest
|
|
||||||
CONTAINERNAME: optifit-ef-api
|
|
||||||
COMMAND: create
|
|
||||||
OVERWRITE: true
|
|
||||||
CODEFIRST_CLIENTDRONE_ENV_ASPNETCORE_HTTP_PORTS: 80
|
|
||||||
ADMINS: louislaborie,tonyfages,anthonyrichard
|
|
||||||
depends_on:
|
|
||||||
- docker-build-and-push
|
|
@ -1,29 +0,0 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
EXPOSE 80
|
|
||||||
EXPOSE 443
|
|
||||||
EXPOSE 8080
|
|
||||||
EXPOSE 8081
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
WORKDIR /src
|
|
||||||
COPY ["Infrastructure/Infrastructure.csproj", "Infrastructure/"]
|
|
||||||
COPY ["Server/Server.csproj", "Server/"]
|
|
||||||
COPY ["Shared/Shared.csproj", "Shared/"]
|
|
||||||
RUN dotnet restore "Server/Server.csproj"
|
|
||||||
COPY . .
|
|
||||||
WORKDIR "/src/Server"
|
|
||||||
RUN dotnet build "Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
|
||||||
|
|
||||||
FROM build AS publish
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
RUN dotnet publish "Server.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM base AS final
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
ENTRYPOINT ["dotnet", "Server.dll"]
|
|
@ -1,22 +1,22 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Infrastructure.Base;
|
using Infrastructure.Base;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
namespace Infrastructure.Entities;
|
namespace Infrastructure.Entities;
|
||||||
|
|
||||||
public class Exercice : EntityBase
|
public class Exercice : EntityBase
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; set; }
|
public string TemplateId { get; set; }
|
||||||
|
public Exercice_template Template { get; set; }
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
public float Duration { get; set; }
|
|
||||||
|
|
||||||
public string Image { get; set; }
|
public ECategory Category { get; set; }
|
||||||
|
public int NbSets { get; set; }
|
||||||
public string Video { get; set; }
|
public int NbReps { get; set; }
|
||||||
|
public int RestingTime { get; set; }
|
||||||
public int NbSeries { get; set; }
|
|
||||||
|
// Clé étrangère explicite vers Session
|
||||||
public int NbRepetitions { get; set; }
|
[Required]
|
||||||
|
public string SessionId { get; set; }
|
||||||
|
public Session Session { get; set; }
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Infrastructure.Base;
|
||||||
|
|
||||||
|
namespace Infrastructure.Entities;
|
||||||
|
|
||||||
|
[Table("Exercice_template")]
|
||||||
|
public class Exercice_template : EntityBase
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Equipment { get; set; }
|
||||||
|
public string Instructions { get; set; }
|
||||||
|
|
||||||
|
public float Duration { get; set; }
|
||||||
|
|
||||||
|
public string? ImageId { get; set; }
|
||||||
|
|
||||||
|
public string? VideoId { get; set; }
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
using Infrastructure.Entities;
|
||||||
|
|
||||||
|
namespace Infrastructure.Repositories;
|
||||||
|
|
||||||
|
public class ExerciceTemplateRepository : GenericRepository<Exercice_template>, IExerciceTemplateRepository
|
||||||
|
{
|
||||||
|
public ExerciceTemplateRepository(OptifitDbContext context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
using Infrastructure.Entities;
|
||||||
|
|
||||||
|
namespace Infrastructure.Repositories;
|
||||||
|
|
||||||
|
public interface IExerciceTemplateRepository : IRepository<Exercice_template>
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Server.Dto.Request;
|
||||||
|
using Server.Dto.Response;
|
||||||
|
using Server.IServices;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace Server.Controller.v1;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
public class ExercicesTemplateController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<ExercicesTemplateController> _logger;
|
||||||
|
private readonly IExerciceTemplateSercice _dataServices;
|
||||||
|
|
||||||
|
public ExercicesTemplateController(ILogger<ExercicesTemplateController> logger, IExerciceTemplateSercice dataServices)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_dataServices = dataServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ResponseTemplateExerciceDto>), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetExercices([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 5, [FromQuery] bool ascending = true)
|
||||||
|
{
|
||||||
|
var exercices = await _dataServices.GetExercices(pageIndex, pageSize, ascending);
|
||||||
|
return exercices.TotalCount == 0 ? NoContent() : Ok(exercices);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[ProducesResponseType(typeof(ResponseTemplateExerciceDto), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> GetExerciceById(string id)
|
||||||
|
{
|
||||||
|
var exercice = await _dataServices.GetExerciceById(id);
|
||||||
|
return exercice == null ? NotFound() : Ok(exercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(ResponseTemplateExerciceDto), StatusCodes.Status201Created)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> CreateExercice([FromBody] RequestTemplateExerciceDto request)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
var createdExercice = await _dataServices.CreateExercice(request);
|
||||||
|
return CreatedAtAction(nameof(GetExerciceById), new { id = createdExercice.Id }, createdExercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
[ProducesResponseType(typeof(ResponseTemplateExerciceDto), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> UpdateExercice(string id, [FromBody] RequestTemplateExerciceDto request)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
var updatedExercice = await _dataServices.UpdateExercice(id, request);
|
||||||
|
return updatedExercice == null ? NotFound() : Ok(updatedExercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
[RequireHttps]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<IActionResult> DeleteExercice(string id)
|
||||||
|
{
|
||||||
|
var deleted = await _dataServices.DeleteExercice(id);
|
||||||
|
return deleted ? NoContent() : NotFound();
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,16 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
namespace Server.Dto.Request
|
namespace Server.Dto.Request
|
||||||
{
|
{
|
||||||
public class RequestExerciceDto
|
public class RequestExerciceDto
|
||||||
{
|
{
|
||||||
[Required]
|
public ECategory Category { get; set; }
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
public int NbSets { get; set; }
|
||||||
|
|
||||||
public float Duration { get; set; }
|
public int NbReps { get; set; }
|
||||||
|
|
||||||
public string Image { get; set; }
|
public int RestingTime { get; set; }
|
||||||
|
|
||||||
public string Video { get; set; }
|
|
||||||
|
|
||||||
public int NbSeries { get; set; }
|
|
||||||
|
|
||||||
public int NbRepetitions { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
namespace Server.Dto.Request;
|
||||||
|
|
||||||
|
public class RequestTemplateExerciceDto
|
||||||
|
{
|
||||||
|
public string Equipment { get; set; }
|
||||||
|
|
||||||
|
public string Instructions { get; set; }
|
||||||
|
|
||||||
|
public float Duration { get; set; }
|
||||||
|
|
||||||
|
public string? ImageId { get; set; }
|
||||||
|
|
||||||
|
public string? VideoId { get; set; }
|
||||||
|
}
|
@ -1,20 +1,21 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
namespace Server.Dto.Request
|
namespace Server.Dto.Request
|
||||||
{
|
{
|
||||||
public class RequestTrainingProgramDto
|
public class RequestTrainingProgramDto
|
||||||
{
|
{
|
||||||
[Required]
|
|
||||||
|
public ELang Lang { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[Required]
|
public string? OwnerId { get; set; }
|
||||||
public int WeekDuration { get; set; }
|
public int? WeekDuration { get; set; }
|
||||||
|
|
||||||
public string Description { get; set; }
|
public EGoal EGoal { get; set; }
|
||||||
|
|
||||||
public string Difficulty { get; set; }
|
public EDifficulty EDifficulty { get; set; }
|
||||||
|
|
||||||
public List<RequestSessionDto> Sessions { get; set; } = new List<RequestSessionDto>();
|
public List<RequestSessionDto> Sessions { get; set; } = new List<RequestSessionDto>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,21 +1,27 @@
|
|||||||
|
using Shared;
|
||||||
|
|
||||||
namespace Server.Dto.Response
|
namespace Server.Dto.Response
|
||||||
{
|
{
|
||||||
public class ResponseExerciceDto
|
public class ResponseExerciceDto
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string TemplateId { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string TemplateName { get; set; }
|
||||||
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
public float Duration { get; set; }
|
|
||||||
|
|
||||||
public string Image { get; set; }
|
public string TemplateInstructions { get; set; }
|
||||||
|
|
||||||
|
public string? TemplateImageId { get; set; }
|
||||||
|
|
||||||
public string Video { get; set; }
|
public string? TemplateVideoId { get; set; }
|
||||||
|
|
||||||
|
public ECategory Category { get; set; }
|
||||||
|
|
||||||
public int NbSeries { get; set; }
|
public int NbSets { get; set; }
|
||||||
|
|
||||||
public int NbRepetitions { get; set; }
|
public int NbReps { get; set; }
|
||||||
|
|
||||||
|
public int RestingTime { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
namespace Server.Dto.Response;
|
||||||
|
|
||||||
|
public class ResponseTemplateExerciceDto
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Equipment { get; set; }
|
||||||
|
|
||||||
|
public string Instructions { get; set; }
|
||||||
|
|
||||||
|
public float Duration { get; set; }
|
||||||
|
|
||||||
|
public string? ImageId { get; set; }
|
||||||
|
|
||||||
|
public string? VideoId { get; set; }
|
||||||
|
}
|
@ -1,19 +1,22 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
namespace Server.Dto.Response
|
namespace Server.Dto.Response
|
||||||
{
|
{
|
||||||
public class ResponseTrainingProgramDto
|
public class ResponseTrainingProgramDto
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public ELang Lang { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public int WeekDuration { get; set; }
|
public string? OwnerId { get; set; }
|
||||||
|
public int? WeekDuration { get; set; }
|
||||||
public string Description { get; set; }
|
|
||||||
|
public EGoal EGoal { get; set; }
|
||||||
public string Difficulty { get; set; }
|
|
||||||
|
public EDifficulty EDifficulty { get; set; }
|
||||||
public List<ResponseSessionDto> Sessions { get; set; } = new List<ResponseSessionDto>();
|
public List<ResponseSessionDto> Sessions { get; set; } = new List<ResponseSessionDto>();
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
@ -0,0 +1,14 @@
|
|||||||
|
using Server.Dto.Request;
|
||||||
|
using Server.Dto.Response;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace Server.IServices;
|
||||||
|
|
||||||
|
public interface IExerciceTemplateSercice
|
||||||
|
{
|
||||||
|
Task<PaginatedResult<ResponseTemplateExerciceDto>> GetExercices(int page, int size, bool ascending = true);
|
||||||
|
Task<ResponseTemplateExerciceDto?> GetExerciceById(string id);
|
||||||
|
Task<ResponseTemplateExerciceDto> CreateExercice(RequestTemplateExerciceDto request);
|
||||||
|
Task<ResponseTemplateExerciceDto?> UpdateExercice(string id, RequestTemplateExerciceDto request);
|
||||||
|
Task<bool> DeleteExercice(string id);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Infrastructure.Entities;
|
||||||
|
using Server.Dto.Request;
|
||||||
|
using Server.Dto.Response;
|
||||||
|
|
||||||
|
namespace Server.Mappers
|
||||||
|
{
|
||||||
|
public class ExerciceTemplateProfile : Profile
|
||||||
|
{
|
||||||
|
public ExerciceTemplateProfile()
|
||||||
|
{
|
||||||
|
// Mapping de l'entité vers le DTO de réponse
|
||||||
|
CreateMap<Exercice_template, ResponseTemplateExerciceDto>()
|
||||||
|
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
|
||||||
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
|
||||||
|
.ForMember(dest => dest.Equipment, opt => opt.MapFrom(src => src.Equipment))
|
||||||
|
.ForMember(dest => dest.Instructions, opt => opt.MapFrom(src => src.Instructions))
|
||||||
|
.ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.Duration))
|
||||||
|
.ForMember(dest => dest.ImageId, opt => opt.MapFrom(src => src.ImageId))
|
||||||
|
.ForMember(dest => dest.VideoId, opt => opt.MapFrom(src => src.VideoId));
|
||||||
|
|
||||||
|
// Mapping du DTO de requête vers l'entité
|
||||||
|
CreateMap<RequestTemplateExerciceDto, Exercice_template>()
|
||||||
|
// Comme la propriété Name n'est pas fournie dans le DTO, on l'ignore ici
|
||||||
|
.ForMember(dest => dest.Name, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.Equipment, opt => opt.MapFrom(src => src.Equipment))
|
||||||
|
.ForMember(dest => dest.Instructions, opt => opt.MapFrom(src => src.Instructions))
|
||||||
|
.ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.Duration))
|
||||||
|
.ForMember(dest => dest.ImageId, opt => opt.MapFrom(src => src.ImageId))
|
||||||
|
.ForMember(dest => dest.VideoId, opt => opt.MapFrom(src => src.VideoId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Infrastructure;
|
||||||
|
using Infrastructure.Entities;
|
||||||
|
using Infrastructure.Repositories;
|
||||||
|
using Server.Dto.Request;
|
||||||
|
using Server.Dto.Response;
|
||||||
|
using Server.IServices;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace Server.Services
|
||||||
|
{
|
||||||
|
public class ExerciceTemplateService : IExerciceTemplateSercice
|
||||||
|
{
|
||||||
|
private readonly OptifitDbContext _context;
|
||||||
|
private readonly IExerciceTemplateRepository _exerciceTemplateRepository;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
public ExerciceTemplateService(OptifitDbContext context, IExerciceTemplateRepository exerciceTemplateRepository, IMapper mapper)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_exerciceTemplateRepository = exerciceTemplateRepository;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginatedResult<ResponseTemplateExerciceDto>> GetExercices(int page, int size, bool ascending = true)
|
||||||
|
{
|
||||||
|
// Ici, on part du principe que la méthode du repository attend un index de page à partir de 0.
|
||||||
|
// Vous pouvez adapter l'appel selon la signature de votre méthode.
|
||||||
|
var exercices = await _exerciceTemplateRepository.GetPaginatedListAsync(page - 1, size, null);
|
||||||
|
return _mapper.Map<PaginatedResult<ResponseTemplateExerciceDto>>(exercices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ResponseTemplateExerciceDto?> GetExerciceById(string id)
|
||||||
|
{
|
||||||
|
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
|
||||||
|
return exercice == null ? null : _mapper.Map<ResponseTemplateExerciceDto>(exercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ResponseTemplateExerciceDto> CreateExercice(RequestTemplateExerciceDto request)
|
||||||
|
{
|
||||||
|
// On mappe le DTO de requête vers l'entité
|
||||||
|
var exercice = _mapper.Map<Exercice_template>(request);
|
||||||
|
|
||||||
|
// Comme le DTO ne fournit pas le Name et que celui-ci est requis,
|
||||||
|
// vous pouvez ici définir une valeur par défaut ou appliquer une logique de création.
|
||||||
|
exercice.Name = string.IsNullOrWhiteSpace(exercice.Name) ? "Exercice Template" : exercice.Name;
|
||||||
|
|
||||||
|
await _exerciceTemplateRepository.InsertAsync(exercice);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return _mapper.Map<ResponseTemplateExerciceDto>(exercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ResponseTemplateExerciceDto?> UpdateExercice(string id, RequestTemplateExerciceDto request)
|
||||||
|
{
|
||||||
|
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
|
||||||
|
if (exercice == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Met à jour l'entité en mappant le DTO dans l'entité existante
|
||||||
|
_mapper.Map(request, exercice);
|
||||||
|
_exerciceTemplateRepository.Update(exercice);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return _mapper.Map<ResponseTemplateExerciceDto>(exercice);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DeleteExercice(string id)
|
||||||
|
{
|
||||||
|
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
|
||||||
|
if (exercice == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_exerciceTemplateRepository.Delete(id);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
namespace Shared;
|
|
||||||
|
|
||||||
public enum ETarget
|
|
||||||
{
|
|
||||||
LEG,
|
|
||||||
ARM,
|
|
||||||
CARDIO,
|
|
||||||
HAMSTRING
|
|
||||||
}
|
|
@ -0,0 +1,12 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public enum EDay
|
||||||
|
{
|
||||||
|
MONDAY,
|
||||||
|
TUESDAY,
|
||||||
|
WEDNESDAY,
|
||||||
|
THURSDAY,
|
||||||
|
FRIDAY,
|
||||||
|
SATURDAY,
|
||||||
|
SUNDAY
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
namespace Shared;
|
namespace Shared;
|
||||||
|
|
||||||
public enum ESportLevel
|
public enum EDifficulty
|
||||||
{
|
{
|
||||||
NOT_SPORTY,
|
NOT_SPORTY,
|
||||||
BEGINNER,
|
BEGINNER,
|
||||||
SPORTY,
|
SPORTY,
|
||||||
VERY_SPORTY
|
VERY_SPORTY
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public enum EGoal
|
||||||
|
{
|
||||||
|
WEIGHT_LOSS,
|
||||||
|
MASS_GAIN,
|
||||||
|
FITNESS,
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public enum ELang
|
||||||
|
{
|
||||||
|
FR,
|
||||||
|
EN
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
namespace Shared;
|
||||||
|
|
||||||
|
public enum ETarget
|
||||||
|
{
|
||||||
|
LEGS,
|
||||||
|
ARMS,
|
||||||
|
BACK,
|
||||||
|
CHEST,
|
||||||
|
ABS,
|
||||||
|
CARDIO
|
||||||
|
}
|
Loading…
Reference in new issue