diff --git a/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java b/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java index 4736efb..cc2ce4f 100644 --- a/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java +++ b/backend/src/main/java/com/worlabel/domain/model/controller/AiModelController.java @@ -56,5 +56,15 @@ public class AiModelController { aiModelService.addModel(memberId, projectId, aiModelRequest); } - + @Operation(summary = "프로젝트 모델 이름 변경", description = "프로젝트에 있는 모델의 이름을 변경합니다.") + @SwaggerApiSuccess(description = "프로젝트 모델의 이름이 변경됩니다.") + @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) + @PutMapping("/projects/{project_id}/models/{model_id}") + public void renameModel( + @CurrentUser final Integer memberId, + @PathVariable("project_id") final Integer projectId, + @PathVariable("model_id") final Integer modelId, + @Valid @RequestBody final AiModelRequest aiModelRequest) { + aiModelService.renameModel(memberId, projectId,modelId, aiModelRequest); + } } diff --git a/backend/src/main/java/com/worlabel/domain/model/entity/AiModel.java b/backend/src/main/java/com/worlabel/domain/model/entity/AiModel.java index f035e2e..c2901f0 100644 --- a/backend/src/main/java/com/worlabel/domain/model/entity/AiModel.java +++ b/backend/src/main/java/com/worlabel/domain/model/entity/AiModel.java @@ -73,4 +73,7 @@ public class AiModel extends BaseEntity { return new AiModel(name, null, 0, project); } + public void rename(final String newName) { + this.name = newName; + } } diff --git a/backend/src/main/java/com/worlabel/domain/model/entity/dto/AiModelRequest.java b/backend/src/main/java/com/worlabel/domain/model/entity/dto/AiModelRequest.java index f24fca4..28d1c6e 100644 --- a/backend/src/main/java/com/worlabel/domain/model/entity/dto/AiModelRequest.java +++ b/backend/src/main/java/com/worlabel/domain/model/entity/dto/AiModelRequest.java @@ -7,7 +7,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -@Schema(name = "모델 생성 dto", description = "모델 생성 DTO") +@Schema(name = "모델 요청 dto", description = "모델 요청 DTO") @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor @Getter diff --git a/backend/src/main/java/com/worlabel/domain/model/repository/AiModelRepository.java b/backend/src/main/java/com/worlabel/domain/model/repository/AiModelRepository.java index 6507e6e..7c719a3 100644 --- a/backend/src/main/java/com/worlabel/domain/model/repository/AiModelRepository.java +++ b/backend/src/main/java/com/worlabel/domain/model/repository/AiModelRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; +import java.util.Optional; public interface AiModelRepository extends JpaRepository { @@ -13,4 +14,8 @@ public interface AiModelRepository extends JpaRepository { "WHERE a.project IS NULL " + "OR a.project.id = :projectId ") List findAllByProjectId(@Param("projectId") Integer projectId); + + @Query("SELECT a FROM AiModel a " + + "WHERE a.project IS NOT NULL AND a.id = :modelId") + Optional findCustomModelById(@Param("modelId") int modelId); } diff --git a/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java b/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java index 9a15dcd..2f287a7 100644 --- a/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java +++ b/backend/src/main/java/com/worlabel/domain/model/service/AiModelService.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; @Slf4j @Service @@ -47,6 +48,18 @@ public class AiModelService { aiModelRepository.save(aiModel); } + @CheckPrivilege(PrivilegeType.EDITOR) + public void renameModel(final Integer memberId, final Integer projectId, final int modelId, final AiModelRequest aiModelRequest) { + AiModel customModel = getCustomModel(modelId); + customModel.rename(aiModelRequest.getName()); + + aiModelRepository.save(customModel); + } + + private AiModel getCustomModel(int modelId) { + return aiModelRepository.findCustomModelById(modelId).orElseThrow(() -> new CustomException(ErrorCode.BAD_REQUEST)); + } + @Transactional(readOnly = true) public List getCategories(final Integer modelId) { List categoryList = labelCategoryRepository.findAllByModelId(modelId); @@ -56,7 +69,7 @@ public class AiModelService { } private Project getProject(Integer projectId) { - return projectRepository.findById(projectId).orElseThrow(()-> new CustomException(ErrorCode.DATA_NOT_FOUND)); + return projectRepository.findById(projectId).orElseThrow(() -> new CustomException(ErrorCode.DATA_NOT_FOUND)); } }