Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,43 @@ public ApiResponse<ContentResponseDTO> uploadContent(@RequestBody ContentRequest
return ApiResponse.onSuccess(contentService.uploadContent(contentRequestDTO));
}

@DeleteMapping("/{contentId}")
@Operation(
summary = "컨텐츠 삭제 API",
description = """
특정 컨텐츠를 삭제합니다. (관리자용)
Path Parameters:
- 'contentId': 삭제할 콘텐츠 ID
"""
)
public ApiResponse<String> deleteContent(@PathVariable Long contentId) {
contentService.deleteContent(contentId);
return ApiResponse.onSuccess("컨텐츠 삭제 완료");
}

@GetMapping
@Operation(
summary = "직무별 컨텐츠 조회 API",
summary = "로그인한 사용자의 직무별 컨텐츠 조회 API",
description = """
특정 직무 ID에 해당하는 컨텐츠를 조회합니다.
로그인한 사용자의 직무 ID에 해당하는 컨텐츠를 조회합니다.
이때 사용자가 해당 컨텐츠를 스크랩했는지 여부가 담겨 조회됩니다.
Query Parameters:
- `jobId`: 직무 ID (필수)
- `page`: 페이지 번호 (기본값: 1)
- `size`: 페이지 크기 (기본값: 10)
"""
)
public ApiResponse<PageResponseDTO<List<ContentResponseDTO>>> getContentsByJobId(
@RequestParam Long jobId,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@LoginMember Member member) {
return ApiResponse.onSuccess(contentService.getContentsByJobId(jobId, page, size, member));
return ApiResponse.onSuccess(contentService.getContentsByJobId(page, size, member));
}

@PostMapping("/{contentId}/scrap")
@Operation(
summary = "컨텐츠 스크랩 API",
description = """
컨텐츠를 스크랩합니다.
컨텐츠를 스크랩합니다.
Path Parameters:
- 'contentId': 스크랩할 콘텐츠 ID
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package UMC.career_mate.domain.content.service;


import UMC.career_mate.domain.content.Content;
import UMC.career_mate.domain.content.converter.ContentConverter;
import UMC.career_mate.domain.content.dto.request.ContentRequestDTO;
Expand All @@ -11,6 +10,8 @@
import UMC.career_mate.domain.job.Service.JobService;
import UMC.career_mate.domain.member.Member;
import UMC.career_mate.global.common.PageResponseDTO;
import UMC.career_mate.global.response.exception.GeneralException;
import UMC.career_mate.global.response.exception.code.CommonErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -39,10 +40,22 @@ public ContentResponseDTO uploadContent(ContentRequestDTO contentRequestDTO) {
return ContentConverter.toContentResponseDTO(content);
}

public void deleteContent(Long contentId) {
// 컨텐츠 존재 여부 확인
Content content = contentRepository.findById(contentId)
.orElseThrow(() -> new GeneralException(CommonErrorCode.NOT_FOUND_CONTENT));

contentRepository.delete(content);
}

@Transactional(readOnly = true)
public PageResponseDTO<List<ContentResponseDTO>> getContentsByJobId(Long jobId, int page, int size, Member member) {
// Job ID 유효성 확인
jobService.findJobById(jobId);
public PageResponseDTO<List<ContentResponseDTO>> getContentsByJobId(int page, int size, Member member) {

// 로그인한 사용자의 직무 ID 확인
Long jobId = member.getJob().getId();
if (jobId == null) {
throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
}
Comment on lines +52 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

직무 정보 검증 로직 개선 필요

현재 구현은 직무 ID가 null인 경우만 처리하고 있습니다. 사용자의 직무 정보에 대한 더 구체적인 유효성 검사가 필요합니다.

다음과 같이 개선하는 것을 추천드립니다:

-        Long jobId = member.getJob().getId();
-        if (jobId == null) {
+        Job job = member.getJob();
+        if (job == null) {
+            throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
+        }
+        Long jobId = job.getId();
+        if (jobId == null || jobId <= 0) {
             throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public PageResponseDTO<List<ContentResponseDTO>> getContentsByJobId(int page, int size, Member member) {
// 로그인한 사용자의 직무 ID 확인
Long jobId = member.getJob().getId();
if (jobId == null) {
throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
}
public PageResponseDTO<List<ContentResponseDTO>> getContentsByJobId(int page, int size, Member member) {
// 로그인한 사용자의 직무 ID 확인
Job job = member.getJob();
if (job == null) {
throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
}
Long jobId = job.getId();
if (jobId == null || jobId <= 0) {
throw new GeneralException(CommonErrorCode.NOT_FOUND_JOB);
}


PageRequest pageRequest = PageRequest.of(page - 1, size);
Page<Content> contentPage = contentRepository.findByJobId(jobId, pageRequest);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
spring:
profiles:
active: dev
active: dev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

파일 끝에 개행 문자를 추가해주세요.

YAML 파일의 끝에는 항상 개행 문자가 있어야 합니다. 이는 POSIX 표준을 준수하고 다른 도구들과의 호환성을 보장하기 위함입니다.

다음과 같이 수정해주세요:

spring:
  profiles:
-    active: dev
+    active: dev
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
active: dev
spring:
profiles:
active: dev
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 3-3: no new line character at the end of file

(new-line-at-end-of-file)


💡 Codebase verification

프로덕션 환경 설정의 심각한 문제점이 확인되었습니다

현재 'dev' 프로필이 여러 위치에 하드코딩되어 있어 프로덕션 환경에서 심각한 문제가 될 수 있습니다:

  • application.ymlactive: dev 하드코딩
  • DockerfileENTRYPOINT 명령어에 -Dspring.profiles.active=dev 하드코딩

권장 수정사항:

  1. application.yml에서 기본 프로필 설정 제거
  2. Dockerfile의 프로필 설정을 환경변수로 대체:
    ENTRYPOINT ["java","-jar","-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}","/app.jar"]
  3. 환경별 설정 파일 (application-prod.yml, application-dev.yml) 추가
  4. 배포 시 환경변수 SPRING_PROFILES_ACTIVE를 통해 프로필 주입
🔗 Analysis chain

프로덕션 환경 설정 관리 방안을 검토해주세요.

버전 관리 시스템에 'dev' 프로필이 하드코딩되어 있는 것이 확인됩니다. 프로덕션 환경에서는 환경 변수나 외부 설정을 통해 프로필을 주입하는 것이 더 안전한 방법일 수 있습니다.

다음 스크립트를 실행하여 프로필 설정이 다른 설정 파일에서도 하드코딩되어 있는지 확인해보시겠습니까?

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: 프로필 설정이 하드코딩된 YAML 파일 검색

echo "프로필 설정이 하드코딩된 YAML 파일 검색 중..."
rg -l "active:\s*(dev|prod|test)" --type yaml

Length of output: 151


Script:

#!/bin/bash
# Search for profile-specific configuration files and deployment configs
echo "프로필별 설정 파일 및 배포 관련 파일 검색..."

echo -e "\n1. 프로필별 설정 파일 검색:"
fd "application-.*\.yml" "src/"

echo -e "\n2. 도커 및 쿠버네티스 설정 파일 검색:"
fd "(Dockerfile|docker-compose.*\.yml|\.k8s|kubernetes)" .

echo -e "\n3. 배포 스크립트 검색:"
fd "(deploy.*\.sh|\.env.*)" .

Length of output: 382


Script:

#!/bin/bash
# Check Docker files for environment configuration
echo "도커 설정 파일 내용 확인..."

echo -e "\n1. Dockerfile 내용:"
cat Dockerfile

echo -e "\n2. docker-compose.yml 내용:"
cat docker-compose.yml

Length of output: 575

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 3-3: no new line character at the end of file

(new-line-at-end-of-file)