Feat: 모델 이름 변경 API
This commit is contained in:
parent
2f6631276d
commit
8eccfc891e
@ -56,5 +56,15 @@ public class AiModelController {
|
|||||||
aiModelService.addModel(memberId, projectId, aiModelRequest);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,4 +73,7 @@ public class AiModel extends BaseEntity {
|
|||||||
return new AiModel(name, null, 0, project);
|
return new AiModel(name, null, 0, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rename(final String newName) {
|
||||||
|
this.name = newName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Schema(name = "모델 생성 dto", description = "모델 생성 DTO")
|
@Schema(name = "모델 요청 dto", description = "모델 요청 DTO")
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface AiModelRepository extends JpaRepository<AiModel, Integer> {
|
public interface AiModelRepository extends JpaRepository<AiModel, Integer> {
|
||||||
|
|
||||||
@ -13,4 +14,8 @@ public interface AiModelRepository extends JpaRepository<AiModel, Integer> {
|
|||||||
"WHERE a.project IS NULL " +
|
"WHERE a.project IS NULL " +
|
||||||
"OR a.project.id = :projectId ")
|
"OR a.project.id = :projectId ")
|
||||||
List<AiModel> findAllByProjectId(@Param("projectId") Integer projectId);
|
List<AiModel> findAllByProjectId(@Param("projectId") Integer projectId);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM AiModel a " +
|
||||||
|
"WHERE a.project IS NOT NULL AND a.id = :modelId")
|
||||||
|
Optional<AiModel> findCustomModelById(@Param("modelId") int modelId);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -47,6 +48,18 @@ public class AiModelService {
|
|||||||
aiModelRepository.save(aiModel);
|
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)
|
@Transactional(readOnly = true)
|
||||||
public List<LabelCategoryResponse> getCategories(final Integer modelId) {
|
public List<LabelCategoryResponse> getCategories(final Integer modelId) {
|
||||||
List<LabelCategory> categoryList = labelCategoryRepository.findAllByModelId(modelId);
|
List<LabelCategory> categoryList = labelCategoryRepository.findAllByModelId(modelId);
|
||||||
|
Loading…
Reference in New Issue
Block a user