Skip to content

Commit

Permalink
Refactor : career, careerdetail 코드 수정
Browse files Browse the repository at this point in the history
Merge pull request #24 from kkijuk/mvp/career
  • Loading branch information
tape4 authored Aug 8, 2024
2 parents 7a55a04 + c8f2ca7 commit 708d807
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Getter;
import umc.kkijuk.server.career.validation.ValidCategory;
import umc.kkijuk.server.career.validation.ValidPeriod;

import java.time.LocalDate;
Expand Down Expand Up @@ -49,7 +47,6 @@ public static class CreateCareerDto{
@Schema(description = "활동 종료 날짜", example = "2024-07-20", type = "string")
LocalDate endDate;

@ValidCategory
@NotNull(message = "활동 카테고리는 필수 선택 항목입니다.")
@Schema(description = "활동 카테고리", example = "1", type = "int")
Integer category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package umc.kkijuk.server.career.dto.converter;

import umc.kkijuk.server.career.controller.response.CareerResponse;
import umc.kkijuk.server.career.domain.Career;
import umc.kkijuk.server.career.dto.CareerRequestDto;
import umc.kkijuk.server.career.dto.CareerResponseDto;
Expand All @@ -11,7 +10,6 @@
import java.util.stream.Collectors;

public class CareerConverter {

public static Career toCareer(CareerRequestDto.CreateCareerDto request, Long memberId){
return Career.builder()
.memberId(memberId)
Expand All @@ -21,7 +19,6 @@ public static Career toCareer(CareerRequestDto.CreateCareerDto request, Long mem
.startdate(request.getStartDate())
.enddate(request.getEndDate())
.unknown(request.getIsUnknown())
.enddate(request.getEndDate())
.build();
}
public static CareerResponseDto.CareerResultDto toCareerResultDto(Career career){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@RequiredArgsConstructor
public class CareerScheduler {
private final CareerRepository careerRepository;
@Scheduled(cron = "0 * * * * ?")
@Scheduled(cron = "0 0 0 * * ?")
public void updateUnkownEndDates() {
List<Career> careers = careerRepository.findAllByUnknown(true);
LocalDate now = LocalDate.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Career createCareer(Member requestMember, CareerRequestDto.CreateCareerDt
career.setEnddate(LocalDate.now());
career.setYear(LocalDate.now().getYear());
}
career.setCategory(categoryRepository.findById(Long.valueOf(request.getCategory())).get());
career.setCategory(categoryRepository.findById(Long.valueOf(request.getCategory())).orElseThrow(() -> new ResourceNotFoundException("category", request.getCategory())));
career.setYear(parsingYear(request));
return careerRepository.save(career);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CareerDetailResponse<CareerDetailResponseDto.CareerDetailResult> create(@
@Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다.")
})
public CareerDetailResponse<Object> delete(@PathVariable Long careerId, @PathVariable Long detailId) {
careerDetailService.delete(requestMember, detailId);
careerDetailService.delete(requestMember, careerId ,detailId);
return CareerDetailResponse.success(HttpStatus.OK, "활동 기록을 성공적으로 삭제했습니다.",null);
}
@PutMapping("/{careerId}/{detailId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface CareerDetailService {
CareerDetail create(Member member, CareerDetailRequestDto.CareerDetailCreate request, Long careerId);
void delete(Member member, Long careerDetailId);
void delete(Member member, Long careerId ,Long careerDetailId);
CareerDetail update(Member member,CareerDetailRequestDto.CareerDetailUpdate request, Long careerId, Long detailId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import umc.kkijuk.server.careerdetail.dto.converter.CareerTagConverter;
import umc.kkijuk.server.careerdetail.repository.CareerDetailRepository;
import umc.kkijuk.server.careerdetail.repository.CareerTagRepository;
import umc.kkijuk.server.common.domian.exception.CareerValidationException;
import umc.kkijuk.server.common.domian.exception.OwnerMismatchException;
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException;
import umc.kkijuk.server.member.domain.Member;
Expand Down Expand Up @@ -52,8 +53,12 @@ public CareerDetail create(Member requestMember, CareerDetailRequestDto.CareerDe

@Override
@Transactional
public void delete(Member reqeustMember ,Long detailId) {
public void delete(Member reqeustMember , Long careerId , Long detailId) {
CareerDetail careerDetail = careerDetailRepository.findById(detailId).orElseThrow(() -> new ResourceNotFoundException("CareerDetail", detailId));
Career career = careerDetail.getCareer();
if(!career.getId().equals(careerId)){
throw new CareerValidationException("주어진 활동 기록 Id는 해당 활동에 속하지 않습니다. 활동 Id와 활동 기록 Id를 확인해 주세요.");
}
if(!careerDetail.getMemberId().equals(reqeustMember.getId())){
throw new OwnerMismatchException();
}
Expand All @@ -63,6 +68,10 @@ public void delete(Member reqeustMember ,Long detailId) {
@Transactional
public CareerDetail update(Member requestMember, CareerDetailRequestDto.CareerDetailUpdate request, Long careerId, Long detailId){
CareerDetail updateCareerDetail = careerDetailRepository.findById(detailId).orElseThrow(() -> new ResourceNotFoundException("CareerDetail", detailId));
Career career = updateCareerDetail.getCareer();
if(!career.getId().equals(careerId)){
throw new CareerValidationException("주어진 활동 기록 Id는 해당 활동에 속하지 않습니다. 활동 Id와 활동 기록 Id를 확인해 주세요.");
}
if(!updateCareerDetail.getMemberId().equals(requestMember.getId())){
throw new OwnerMismatchException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public ErrorResponse handleInvalidFormatExceptions(InvalidFormatException except

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(OwnerMismatchException.class)
public ErrorResponse CareerOwnerMismatchException(OwnerMismatchException exception) {
public ErrorResponse OwnerMismatchException(OwnerMismatchException exception) {
return new ErrorResponse(exception.getMessage());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void init() {
//given
when(careerDetailRepository.findById(any(Long.class))).thenReturn(Optional.of(careerDetail));
//when
careerDetailService.delete(testRequestMember1, 1L);
careerDetailService.delete(testRequestMember1, 1L,1L);
//then
verify(careerDetailRepository,times(1)).delete(careerDetail);
}
Expand All @@ -165,7 +165,7 @@ void init() {
//when
//then
assertThrows(ResourceNotFoundException.class, () ->
careerDetailService.delete(testRequestMember1, 1L));
careerDetailService.delete(testRequestMember1, 1L,1L));
verify(careerDetailRepository, never()).delete(any(CareerDetail.class));
verify(careerDetailRepository,times(1)).findById(any(Long.class));
}
Expand Down

0 comments on commit 708d807

Please sign in to comment.