Ajout de la route pour promouvoir un user

notePad
Maxime SAPOUNTZIS 1 year ago
parent bdc1e01aa4
commit 92a1b9e8b3

@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**

@ -128,5 +128,25 @@ namespace API.Controllers
logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();
}
[HttpPut("user/promote/{id:int}")]
[ProducesResponseType(typeof(UserDto), 200)]
[ProducesResponseType(typeof(string), 404)]
public IActionResult PromoteUser(int id)
{
var userPromoted = userService.GetUserById(id);
if (userPromoted != null)
{
userPromoted = userService.PromoteUser(id);
logger.LogInformation("[INFORMATION] La promotion de l'utilisateur avec l'id {id} a été effectuée");
return Ok(userPromoted);
}
else
{
logger.LogInformation("[INFORMATION] La promotion de l'utilisateur avec l'id {id} à échouée",
id);
return NotFound();
}
}
}
}

@ -0,0 +1,32 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["API/API.csproj", "API/"]
COPY ["DbContextLib/DbContextLib.csproj", "DbContextLib/"]
COPY ["EntityFramework/Entities.csproj", "EntityFramework/"]
COPY ["Dto/Dto.csproj", "Dto/"]
COPY ["DbDataManager/DbDataManager.csproj", "DbDataManager/"]
COPY ["Model/Model.csproj", "Model/"]
COPY ["Shared/Shared.csproj", "Shared/"]
COPY ["StubbedContextLib/StubbedContextLib.csproj", "StubbedContextLib/"]
RUN dotnet restore "./API/./API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "./API.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]

@ -25,4 +25,7 @@ public class UserDataServiceApi(IUserService<UserEntity> userService) : IUserSer
public UserDto CreateUser(string username, string password, string email, bool isAdmin) =>
userService.CreateUser(username, password, email, isAdmin).FromEntityToDto();
public UserDto PromoteUser(int id) =>
userService.PromoteUser(id).FromEntityToDto();
}

@ -116,4 +116,13 @@ public class UserDataService : IUserService<UserEntity>
DbContext.SaveChangesAsync();
return newUserEntity;
}
public UserEntity PromoteUser(int id)
{
var userEdit = GetUserById(id);
var newUserEntity = UpdateUser(id,new UserEntity{Id = id,Username = userEdit.Username,Password = userEdit.Password,Email = userEdit.Email,IsAdmin = true});
DbContext.Users.Add(newUserEntity);
DbContext.SaveChangesAsync();
return newUserEntity;
}
}

@ -10,5 +10,6 @@ namespace Shared
public bool DeleteUser(int id);
public TUser UpdateUser(int id, TUser user);
public TUser CreateUser(string username, string password, string email, bool isAdmin);
public TUser PromoteUser(int id);
}
}
Loading…
Cancel
Save