Skip to content

Commit

Permalink
Merge branch 'develop' into mvp/member
Browse files Browse the repository at this point in the history
  • Loading branch information
tape4 authored Aug 2, 2024
2 parents 511d4d4 + 9beef3d commit c849f9f
Show file tree
Hide file tree
Showing 41 changed files with 1,035 additions and 217 deletions.
17 changes: 17 additions & 0 deletions src/main/java/umc/kkijuk/server/KKIJUKConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package umc.kkijuk.server;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class KKIJUKConfiguration implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PATCH", "DELETE", "PUT")
.allowedHeaders("*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import umc.kkijuk.server.career.dto.converter.CareerConverter;
import umc.kkijuk.server.career.service.CareerService;
import umc.kkijuk.server.common.LoginUser;
import umc.kkijuk.server.member.domain.Member;

import java.util.List;

Expand All @@ -27,11 +28,14 @@ public class CareerController {

private final CareerService careerService;

private final Member requestMember = Member.builder()
.id(LoginUser.get().getId())
.build();

@PostMapping("")
@Operation(summary = "활동 추가 API", description = "내 커리어 - 활동을 추가하는 API")
public CareerResponse<CareerResponseDto.CareerResultDto> create(@RequestBody @Valid CareerRequestDto.CreateCareerDto request){
LoginUser loginUser = LoginUser.get();
Career career = careerService.createCareer(request);
Career career = careerService.createCareer(requestMember, request);
return CareerResponse.success(HttpStatus.CREATED,
CareerResponseMessage.CAREER_CREATE_SUCCESS,
CareerConverter.toCareerResultDto(career));
Expand All @@ -41,8 +45,7 @@ public CareerResponse<CareerResponseDto.CareerResultDto> create(@RequestBody @Va
@Operation(summary = "활동 삭제 API", description = "내 커리어 - 활동을 삭제하는 API")
@Parameter(name="careerId", description = "활동 Id, path variable 입니다.",example = "1")
public CareerResponse<Object> delete(@PathVariable Long careerId){
LoginUser loginUser = LoginUser.get();
careerService.deleteCareer(careerId);
careerService.deleteCareer(requestMember, careerId);
return CareerResponse.success(HttpStatus.OK,
CareerResponseMessage.CAREER_DELETE_SUCCESS,null);
}
Expand All @@ -52,8 +55,7 @@ public CareerResponse<Object> delete(@PathVariable Long careerId){
@Parameter(name="careerId", description = "활동 Id, path variable 입니다.",example = "1")
public CareerResponse<Object> update(@RequestBody @Valid CareerRequestDto.UpdateCareerDto request,
@PathVariable Long careerId) {
LoginUser loginUser = LoginUser.get();
Career updateCareer = careerService.updateCareer(careerId, request);
Career updateCareer = careerService.updateCareer(requestMember,careerId, request);
return CareerResponse.success(HttpStatus.OK,
CareerResponseMessage.CAREER_UPDATE_SUCCESS,
CareerConverter.toCareerDto(updateCareer));
Expand All @@ -62,11 +64,11 @@ public CareerResponse<Object> update(@RequestBody @Valid CareerRequestDto.Update
@GetMapping("")
@Operation(
summary = "활동 조회 API - category(카테고리 기준) , year(연도 기준) ",
description = "내 커리어 - 활동을 카테고리 별로 조회하는 API입니다. query 값으로 category 나 year 값을 주세요. " )
description = "내 커리어 - 활동을 카테고리, 연도 별로 조회하는 API입니다. query 값으로 category 나 year 값을 주세요. " )
public CareerResponse<List<? extends CareerGroupedByResponse>> read(@RequestParam(name="status") String value){
return CareerResponse.success(HttpStatus.OK,
CareerResponseMessage.CAREER_FINDALL_SUCCESS,
careerService.getCareerGroupedBy(value));
careerService.getCareerGroupedBy(requestMember, value));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import org.hibernate.annotations.AnyKeyJavaClass;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Builder
@Getter
Expand All @@ -33,21 +23,4 @@ public CareerResponse(final int status,final String message,T data){
public static <T> CareerResponse<T> success(HttpStatus status, String message, T data){
return new CareerResponse<>(status.value(),message,data);
}
public static CareerResponse<?> createFail (BindingResult bindingResult){
Map<String, String> errors = new HashMap<>();
List<ObjectError> allErrors = bindingResult.getAllErrors();
for ( ObjectError error: allErrors ) {
if( error instanceof FieldError) {
errors.put(((FieldError)error).getField(),error.getDefaultMessage());
}else{
errors.put(error.getObjectName(),error.getDefaultMessage());
}
}
return new CareerResponse<>(HttpStatus.BAD_REQUEST.value(), CareerResponseMessage.CAREER_CREATE_FAIL,errors);
}
public static CareerResponse<?> createError(String message){
return new CareerResponse<>(HttpStatus.BAD_REQUEST.value(), message, null);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,12 @@ public class CareerResponseMessage {
public static final String CAREER_UPDATE_SUCCESS = "활동 수정이 정상적으로 이루어졌습니다.";
public static final String CAREER_DELETE_SUCCESS = "활동 삭제가 정상적으로 이루어졌습니다.";
public static final String CAREER_FINDALL_SUCCESS = "활동 조회가 정상적으로 이루어졌습니다.";


public static final String CAREER_NOT_FOUND ="존재하는 활동 Id가 아닙니다.";
public static final String CAREER_CREATE_FAIL = "활동 추가를 실패했습니다.";


public static final String CAREER_FOTMAT_INVALID = "올바른 날짜 형식이 아닙니다. YYYY-MM-DD 형식으로 입력해야 합니다.";
public static final String CAREER_ENDDATE = "현재 진행중이 아니라면, 활동 종료 날짜를 입력해야 합니다.";
public static final String CAREER_PERIOD_FAIL = "시작 날짜는 종료 날짜보다 앞에 있어야 합니다.";


public static final String CATEGORY_NOT_FOUND = "존재하는 카테고리 Id가 아닙니다.";
public static final String CAREER_FINDALL_FAIL = "올바른 요청이 아닙니다. category, year 요청을 주세요";









}
19 changes: 15 additions & 4 deletions src/main/java/umc/kkijuk/server/career/domain/Career.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import jakarta.persistence.*;
import lombok.*;
import umc.kkijuk.server.career.domain.base.BaseEntity;
import umc.kkijuk.server.careerdetail.domain.CareerDetail;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand All @@ -22,8 +25,8 @@ public class Career extends BaseEntity {
@Column(name="career_alias", length = 20)
private String alias;

@Column(name="career_current")
private Boolean current;
@Column(name="career_unknown")
private Boolean unknown;

@Column(name="career_summary",length = 50)
private String summary;
Expand All @@ -41,6 +44,14 @@ public class Career extends BaseEntity {
@JoinColumn(name = "category_id")
private Category category;


@OneToMany(mappedBy = "career", cascade = CascadeType.ALL)
private List<CareerDetail> careerDetailList = new ArrayList<>();


@Column(nullable = false)
private Long memberId;

public void setName(String name) {
this.name = name;
}
Expand All @@ -49,8 +60,8 @@ public void setAlias(String alias) {
this.alias = alias;
}

public void setCurrent(Boolean current) {
this.current = current;
public void setUnknown(Boolean unknown) {
this.unknown = unknown;
}

public void setSummary(String summary) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/umc/kkijuk/server/career/dto/CareerRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public static class CreateCareerDto{
@Schema(description = "활동 내역", example = "주요 활동 내용을 요약하여 작성해주세요. 최대 50자 까지 입력 가능 선택사항입니다.", type = "string")
String summary;

@NotNull(message = "활동 여부는 필수 선택 항목입니다.")
@Schema(description = "활동 여부", example = "false", type = "boolean")
Boolean isCurrent;
@NotNull(message = "활동 기간을 알고 있는지 여부를 나타냅니다.")
@Schema(description = "활동 기간 인지 여부", example = "false", type = "boolean")
Boolean isUnknown;


@NotNull(message = "활동 시작 날짜는 필수 입력 항목입니다.")
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
Expand Down Expand Up @@ -64,8 +65,8 @@ public static class UpdateCareerDto{
@Size(max = 50)
@Schema(description = "수정된 활동 내역", example = "활동 내역 최대 50자까지 입력 가능(선택사항입니다.)",type = "string")
String summary;
@Schema(description = "수정된 활동 여부", example = "false", type = "boolean")
Boolean isCurrent;
@Schema(description = "수정된 활동 기간 인지 여부", example = "false", type = "boolean")
Boolean isUnknown;
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
@Schema(description = "수정된 활동 시작 날짜", example = "2024-04-14", type="string")
LocalDate startDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class CareerDto{
String careerName;
String alias;
String summary;
Boolean isCurrent;
Boolean isUnknown;
LocalDate startDate;
LocalDate endDate;
int year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

public class CareerConverter {

public static Career toCareer(CareerRequestDto.CreateCareerDto request){
public static Career toCareer(CareerRequestDto.CreateCareerDto request, Long memberId){
return Career.builder()
.memberId(memberId)
.name(request.getCareerName())
.alias(request.getAlias())
.summary(request.getSummary())
.startdate(request.getStartDate())
.enddate(request.getEndDate())
.current(request.getIsCurrent())
.unknown(request.getIsUnknown())
.enddate(request.getEndDate())
.build();
}
Expand All @@ -32,7 +33,7 @@ public static CareerResponseDto.CareerDto toCareerDto(Career career) {
.careerName(career.getName())
.alias(career.getAlias())
.summary(career.getSummary())
.isCurrent(career.getCurrent())
.isUnknown(career.getUnknown())
.startDate(career.getStartdate())
.endDate(career.getEnddate())
.year(career.getYear())
Expand All @@ -55,7 +56,7 @@ public static List<CareerResponseDto.CareerGroupedByCategoryDto> toCareerGrouped
.year(career.getYear())
.startDate(career.getStartdate())
.endDate(career.getEnddate())
.isCurrent(career.getCurrent())
.isUnknown(career.getUnknown())
.categoryId(Math.toIntExact(career.getCategory().getId()))
.categoryName(career.getCategory().getName())
.build())
Expand All @@ -78,7 +79,7 @@ public static List<CareerResponseDto.CareerGroupedByYearDto> toCareerGroupedByYe
.year(career.getYear())
.startDate(career.getStartdate())
.endDate(career.getEnddate())
.isCurrent(career.getCurrent())
.isUnknown(career.getUnknown())
.categoryId(Math.toIntExact(career.getCategory().getId()))
.categoryName(career.getCategory().getName())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import umc.kkijuk.server.career.domain.Career;

import java.util.List;


public interface CareerRepository extends JpaRepository<Career, Long> {
List<Career> findAllByUnknown(boolean isUnknown);
List<Career> findAllCareerByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package umc.kkijuk.server.career.scheduler;

import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import umc.kkijuk.server.career.domain.Career;
import umc.kkijuk.server.career.repository.CareerRepository;

import java.time.LocalDate;
import java.util.List;

@Component
@RequiredArgsConstructor
public class CareerScheduler {
private final CareerRepository careerRepository;
@Scheduled(cron = "0 * * * * ?")
public void updateUnkownEndDates() {
List<Career> careers = careerRepository.findAllByUnknown(true);
LocalDate now = LocalDate.now();
for (Career career : careers) {
career.setEnddate(now);
careerRepository.save(career);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import umc.kkijuk.server.career.controller.response.CareerGroupedByResponse;
import umc.kkijuk.server.career.domain.Career;
import umc.kkijuk.server.career.dto.CareerRequestDto;
import umc.kkijuk.server.member.domain.Member;

import java.util.List;
import java.util.Optional;

public interface CareerService {
Career createCareer(CareerRequestDto.CreateCareerDto request);
void deleteCareer(Long careerId);
Career createCareer(Member member, CareerRequestDto.CreateCareerDto request);
void deleteCareer(Member member, Long careerId);
Optional<Career> findCareer(Long value);
Career updateCareer(Long careerId, CareerRequestDto.UpdateCareerDto request);
List<? extends CareerGroupedByResponse> getCareerGroupedBy(String value);
Career updateCareer(Member member, Long careerId, CareerRequestDto.UpdateCareerDto request);
List<? extends CareerGroupedByResponse> getCareerGroupedBy(Member member, String value);
}
Loading

0 comments on commit c849f9f

Please sign in to comment.