Skip to content

Commit

Permalink
Merge pull request #32 from KUSITMS-CORECORD/feat/#25
Browse files Browse the repository at this point in the history
[Feat/#25] 역량 분석 기능 구현(1)
  • Loading branch information
daeun084 authored Oct 31, 2024
2 parents 3377c63 + 52dfb3c commit 5462ee9
Show file tree
Hide file tree
Showing 18 changed files with 408 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/corecord/dev/common/base/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BaseEntity {
private LocalDateTime updatedAt;

public String getCreatedAtFormatted() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
return createdAt.format(formatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import corecord.dev.common.response.ApiResponse;
import corecord.dev.common.status.ErrorStatus;
import corecord.dev.domain.analysis.exception.model.AnalysisException;
import corecord.dev.domain.folder.exception.model.FolderException;
import corecord.dev.domain.record.exception.model.RecordException;
import corecord.dev.domain.token.exception.model.TokenException;
Expand Down Expand Up @@ -45,6 +46,12 @@ public ResponseEntity<ApiResponse<Void>> handleRecordException(RecordException e
return ApiResponse.error(e.getRecordErrorStatus());
}

@ExceptionHandler(AnalysisException.class)
public ResponseEntity<ApiResponse<Void>> handleAnalysisException(AnalysisException e) {
log.warn(">>>>>>>>AnalysisException: {}", e.getAnalysisErrorStatus().getMessage());
return ApiResponse.error(e.getAnalysisErrorStatus());
}

// GeneralException 처리
@ExceptionHandler(GeneralException.class)
public ResponseEntity<ApiResponse<Void>> handleGeneralException(GeneralException e) {
Expand Down
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;
}
22 changes: 19 additions & 3 deletions src/main/java/corecord/dev/domain/analysis/constant/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

@AllArgsConstructor
public enum Keyword {
COMMUNICATION("커뮤니케이션"),
TEAMWORK("팀워크"),
LEADERSHIP("리더십")
PROBLEM_SOLViNG_SKILL("문제해결능력"), ANALYTICAL_SKILL("분석력"),
GLOBAL_SKILL("글로벌역량"), JUDGEMENT_SKILL("판단력"),

TARGET_AWARENESS("목표의식"), MOMENTUM("추진력"),

COMMUNICATION("커뮤니케이션"), LEADERSHIP("리더십"),
COLLABORATION("협업능력"), ADAPTABILITY("적응력"),

CREATIVITY("창의성"), LOGIC("논리성"),
CHALLENGE_MINDSET("도전정신"), SELF_IMPROVEMENT("자기계발"), RESPONSIBILITY("책임감")
;

private final String value;
Expand All @@ -15,4 +22,13 @@ public String getValue() {
return value;
}

public static Keyword getName(String value){
for (Keyword keyword : Keyword.values()) {
if (keyword.getValue().equals(value)) {
return keyword;
}
}
return null;
}

}
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);
}

}
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();
}
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public class Ability extends BaseEntity {
@JoinColumn(name = "analysis_id", nullable = false)
private Analysis analysis;

public void updateContent(String content) {
if (content != null && !content.isEmpty()) {
this.content = content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ public class Analysis extends BaseEntity {
@Column(nullable = false)
private Long analysisId;

@Column(nullable = false)
private int count; // min=1, max=3

@Column(nullable = false, length = 500)
private String suggestion;
private String comment;

@OneToOne
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "record_id", nullable = false)
private Record record;

Expand Down
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;
}
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();
}
}
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> {
}
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> {
}
Loading

0 comments on commit 5462ee9

Please sign in to comment.