diff --git a/API_SQLuedo/.dockerignore b/API_SQLuedo/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/API_SQLuedo/.dockerignore @@ -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/** \ No newline at end of file diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index fb57815..8c0b394 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -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(); + } + } } } \ No newline at end of file diff --git a/API_SQLuedo/API/Dockerfile b/API_SQLuedo/API/Dockerfile new file mode 100644 index 0000000..2ea3b4c --- /dev/null +++ b/API_SQLuedo/API/Dockerfile @@ -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"] \ No newline at end of file diff --git a/API_SQLuedo/API/Service/UserDataServiceAPI.cs b/API_SQLuedo/API/Service/UserDataServiceAPI.cs index 72bca16..621ee65 100644 --- a/API_SQLuedo/API/Service/UserDataServiceAPI.cs +++ b/API_SQLuedo/API/Service/UserDataServiceAPI.cs @@ -25,4 +25,7 @@ public class UserDataServiceApi(IUserService 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(); } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/UserDataService.cs b/API_SQLuedo/DbDataManager/Service/UserDataService.cs index ebb3ba5..4158622 100644 --- a/API_SQLuedo/DbDataManager/Service/UserDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/UserDataService.cs @@ -116,4 +116,13 @@ public class UserDataService : IUserService 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; + } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/IUserService.cs b/API_SQLuedo/Shared/IUserService.cs index d1d458a..d723558 100644 --- a/API_SQLuedo/Shared/IUserService.cs +++ b/API_SQLuedo/Shared/IUserService.cs @@ -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); } } \ No newline at end of file