-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat/#25] 역량 분석 기능 구현(1)
- Loading branch information
Showing
18 changed files
with
408 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/corecord/dev/domain/analysis/constant/AnalysisSuccessStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package corecord.dev.domain.analysis.constant; | ||
|
||
import corecord.dev.common.base.BaseSuccessStatus; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum AnalysisSuccessStatus implements BaseSuccessStatus { | ||
ANALYSIS_GET_SUCCESS(HttpStatus.CREATED, "S502", "역량별 경험 조회가 성공적으로 완료되었습니다."), | ||
ANALYSIS_UPDATE_SUCCESS(HttpStatus.OK, "S701", "역량별 경험 수정이 성공적으로 완료되었습니다."), | ||
ANALYSIS_DELETE_SUCCESS(HttpStatus.OK, "S702", "역량별 경험 삭제가 성공적으로 완료되었습니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/corecord/dev/domain/analysis/controller/AnalysisController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package corecord.dev.domain.analysis.controller; | ||
|
||
import corecord.dev.common.response.ApiResponse; | ||
import corecord.dev.common.web.UserId; | ||
import corecord.dev.domain.analysis.constant.AnalysisSuccessStatus; | ||
import corecord.dev.domain.analysis.dto.request.AnalysisRequest; | ||
import corecord.dev.domain.analysis.dto.response.AnalysisResponse; | ||
import corecord.dev.domain.analysis.service.AnalysisService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/analysis") | ||
public class AnalysisController { | ||
private final AnalysisService analysisService; | ||
|
||
@GetMapping("/{analysisId}") | ||
public ResponseEntity<ApiResponse<AnalysisResponse.AnalysisDto>> getAnalysis( | ||
@UserId Long userId, | ||
@PathVariable(name = "analysisId") Long analysisId | ||
) { | ||
AnalysisResponse.AnalysisDto analysisResponse = analysisService.getAnalysis(userId, analysisId); | ||
return ApiResponse.success(AnalysisSuccessStatus.ANALYSIS_GET_SUCCESS, analysisResponse); | ||
} | ||
|
||
@PatchMapping("") | ||
public ResponseEntity<ApiResponse<AnalysisResponse.AnalysisDto>> updateAnalysis( | ||
@UserId Long userId, | ||
@RequestBody AnalysisRequest.AnalysisUpdateDto analysisUpdateDto | ||
) { | ||
AnalysisResponse.AnalysisDto analysisResponse = analysisService.updateAnalysis(userId, analysisUpdateDto); | ||
return ApiResponse.success(AnalysisSuccessStatus.ANALYSIS_UPDATE_SUCCESS, analysisResponse); | ||
} | ||
|
||
@DeleteMapping("/{analysisId}") | ||
public ResponseEntity<ApiResponse<String>> deleteAnalysis( | ||
@UserId Long userId, | ||
@PathVariable(name = "analysisId") Long analysisId | ||
) { | ||
analysisService.deleteAnalysis(userId, analysisId); | ||
return ApiResponse.success(AnalysisSuccessStatus.ANALYSIS_DELETE_SUCCESS); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/corecord/dev/domain/analysis/converter/AnalysisConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package corecord.dev.domain.analysis.converter; | ||
|
||
import corecord.dev.domain.analysis.constant.Keyword; | ||
import corecord.dev.domain.analysis.dto.response.AnalysisResponse; | ||
import corecord.dev.domain.analysis.entity.Ability; | ||
import corecord.dev.domain.analysis.entity.Analysis; | ||
import corecord.dev.domain.record.entity.Record; | ||
import corecord.dev.domain.user.entity.User; | ||
|
||
import java.util.List; | ||
|
||
public class AnalysisConverter { | ||
public static Analysis toAnalysis(String comment, Record record) { | ||
return Analysis.builder() | ||
.comment(comment) | ||
.record(record) | ||
.build(); | ||
} | ||
|
||
public static Ability toAbility(Keyword keyword, String content, Analysis analysis, User user) { | ||
return Ability.builder() | ||
.keyword(keyword) | ||
.content(content) | ||
.analysis(analysis) | ||
.user(user) | ||
.build(); | ||
} | ||
|
||
public static AnalysisResponse.AbilityDto toAbilityDto(Ability ability) { | ||
return AnalysisResponse.AbilityDto.builder() | ||
.keyword(ability.getKeyword().getValue()) | ||
.content(ability.getContent()) | ||
.build(); | ||
} | ||
|
||
public static AnalysisResponse.AnalysisDto toAnalysisDto(Analysis analysis) { | ||
Record record = analysis.getRecord(); | ||
|
||
// TODO: keyword 정렬 순서 고려 필요 | ||
List<AnalysisResponse.AbilityDto> abilityDtoList = analysis.getAbilityList().stream() | ||
.map(AnalysisConverter::toAbilityDto) | ||
.toList(); | ||
|
||
return AnalysisResponse.AnalysisDto.builder() | ||
.analysisId(analysis.getAnalysisId()) | ||
.recordId(record.getRecordId()) | ||
.recordTitle(record.getTitle()) | ||
.recordContent(record.getContent()) | ||
.abilityDtoList(abilityDtoList) | ||
.comment(analysis.getComment()) | ||
.createdAt(analysis.getCreatedAtFormatted()) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/corecord/dev/domain/analysis/dto/request/AnalysisRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package corecord.dev.domain.analysis.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Data; | ||
|
||
import java.util.Map; | ||
|
||
public class AnalysisRequest { | ||
|
||
@Data | ||
public static class AnalysisUpdateDto { | ||
@NotBlank(message = "역량 분석 id를 입력해주세요.") | ||
private Long analysisId; | ||
private String recordContent; | ||
private Map<String, String> abilityMap; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/corecord/dev/domain/analysis/dto/response/AnalysisResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package corecord.dev.domain.analysis.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
public class AnalysisResponse { | ||
|
||
@Data | ||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
public static class AbilityDto { | ||
private String keyword; | ||
private String content; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@Data | ||
public static class AnalysisDto { | ||
private Long analysisId; | ||
private Long recordId; | ||
private String recordTitle; | ||
private String recordContent; | ||
private List<AbilityDto> abilityDtoList; | ||
private String comment; | ||
private String createdAt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/corecord/dev/domain/analysis/exception/enums/AnalysisErrorStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package corecord.dev.domain.analysis.exception.enums; | ||
|
||
import corecord.dev.common.base.BaseErrorStatus; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum AnalysisErrorStatus implements BaseErrorStatus { | ||
INVALID_KEYWORD(HttpStatus.BAD_REQUEST, "E400_INVALID_KEYWORD", "역량 분석에 존재하지 않는 키워드입니다."), | ||
USER_ANALYSIS_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "E401_ANALYSIS_UNAUTHORIZED", "유저가 역량 분석에 대한 권한이 없습니다."), | ||
ANALYSIS_NOT_FOUND(HttpStatus.NOT_FOUND, "E0404_ANALYSIS", "존재하지 않는 역량 분석입니다.") | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/corecord/dev/domain/analysis/exception/model/AnalysisException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package corecord.dev.domain.analysis.exception.model; | ||
|
||
import corecord.dev.domain.analysis.exception.enums.AnalysisErrorStatus; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class AnalysisException extends RuntimeException { | ||
private final AnalysisErrorStatus analysisErrorStatus; | ||
|
||
@Override | ||
public String getMessage() { | ||
return analysisErrorStatus.getMessage(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/corecord/dev/domain/analysis/repository/AbilityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package corecord.dev.domain.analysis.repository; | ||
|
||
import corecord.dev.domain.analysis.entity.Ability; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface AbilityRepository extends JpaRepository<Ability, Long> { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/corecord/dev/domain/analysis/repository/AnalysisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package corecord.dev.domain.analysis.repository; | ||
|
||
import corecord.dev.domain.analysis.entity.Analysis; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface AnalysisRepository extends JpaRepository<Analysis, Long> { | ||
} |
Oops, something went wrong.