Skip to content

Commit

Permalink
feat: 큐레이션 컨트롤러 유닛테스트 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daolove0323 authored Nov 8, 2024
1 parent a46924a commit 3db4d86
Show file tree
Hide file tree
Showing 22 changed files with 469 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected String getSubPath() {
@Override
protected CurationImage toEntity(ImageRequest imageRequest) {
return CurationImage.builder()
.name(imageRequest.getUrl())
.url(imageRequest.getUrl())
.size(imageRequest.getSize())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected String getSubPath() {

@Override
protected EventImage toEntity(ImageRequest imageRequest) {
return EventImage.builder().name(imageRequest.getUrl()).size(imageRequest.getSize()).build();
return EventImage.builder().url(imageRequest.getUrl()).size(imageRequest.getSize()).build();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CurationImage extends Image {
private CurationCard curationCard;

@Builder
public CurationImage(String name, Long size, String extension) {
super(name, size, extension);
public CurationImage(String url, Long size, String extension) {
super(url, size, extension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EventImage extends Image {
private Event event;

@Builder
public EventImage(String name, Long size, String extension) {
super(name, size, extension);
public EventImage(String url, Long size, String extension) {
super(url, size, extension);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.ktc2.cokaen.wouldyouin._common.api;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@Builder
public class SliceInfo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum ErrorCode {

FAIL_TO_PAY(HttpStatus.CONFLICT.value(), "-20400", "Fail to %s"),

UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400", "Unauthorized, %s id is not matched."),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED.value(), "-20400", "Unauthorized, %s."),

ENTITY_PARAM_IS_NULL(HttpStatus.BAD_REQUEST.value(), "-20400", "%s is null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse;
import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody;
import org.ktc2.cokaen.wouldyouin._common.exception.BusinessException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
Expand All @@ -21,7 +22,7 @@ public ResponseEntity<ApiResponseBody<Void>> handleBusinessException(BusinessExc
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ApiResponseBody<Void>> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
return ApiResponse.error(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult().getFieldErrors().stream()
.map(error -> String.format("%s %s", error.getField(), error.getDefaultMessage()))
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining(",")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException;
import org.ktc2.cokaen.wouldyouin.auth.persist.CustomUserDetails;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -54,6 +55,6 @@ private void validateMemberType(List<MemberType> required, MemberType actual) {
if (actual == MemberType.admin || required.contains(actual)) {
return;
}
throw new RuntimeException("요구된 멤버 형식과 실제 형식이 다릅니다.");
throw new UnauthorizedException("요구된 멤버 형식과 실제 형식이 다릅니다.");
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.ktc2.cokaen.wouldyouin.curation.api.dto;

import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage;
import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard;

@Getter
@Builder(toBuilder = true)
@EqualsAndHashCode
public class CurationCardRequest {

@NotEmpty(message = "부제목은 필수입니다.")
Expand All @@ -22,6 +25,11 @@ public class CurationCardRequest {

private List<Long> imageIds;

@AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.")
public boolean isImageSizeValid() {
return imageIds == null || imageIds.size() <= 5;
}

public CurationCard toEntity(List<CurationImage> images) {
return CurationCard.builder()
.subtitle(this.subtitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.ktc2.cokaen.wouldyouin._common.vo.Area;
import org.ktc2.cokaen.wouldyouin.curation.persist.Curation;
Expand All @@ -15,6 +16,7 @@

@Getter
@Builder(toBuilder = true)
@EqualsAndHashCode
public class CurationCreateRequest {

@NotEmpty(message = "제목은 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.util.List;
import lombok.Builder;
import lombok.Getter;
import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo;

@Getter
@Builder
public class CurationSliceResponse {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public CurationResponse create(Long curatorId, CurationCreateRequest curationCre

public void validateCuratorId(Long curatorId, Curation curation) {
if (!curatorId.equals(curation.getCurator().getId())) {
throw new UnauthorizedException("Curator");
throw new UnauthorizedException("큐레이터 ID가 큐레이션의 큐레이터 ID와 일치하지 않습니다.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public ResponseEntity<ApiResponseBody<EventSliceResponse>> getEventsByHostId(
hostId, PageRequest.of(page, size), lastId));
}

// Todo: 이름으로 검색

@GetMapping("/{eventId}")
public ResponseEntity<ApiResponseBody<EventResponse>> getEventByEventId(
@PathVariable("eventId") Long eventId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean isEndTimeAfterStartTime() {

@AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.")
public boolean isImageSizeValid() {
return imageIds.size() <= 5;
return imageIds == null || imageIds.size() <= 5;
}

public Event toEntity(Host host, List<EventImage> images) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public EventResponse create(Long hostId, EventCreateRequest eventCreateRequest)

private void validateHostId(Long hostId, Event event) {
if (!hostId.equals(event.getHost().getId())) {
throw new UnauthorizedException("Host");
throw new UnauthorizedException("호스트 ID가 행사의 호스트 ID와 일치하지 않습니다.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void delete(Long memberId, Long reservationId) {

public void validateMemberId(Long memberId, Reservation reservation) {
if (!memberId.equals(reservation.getMember().getId())) {
throw new UnauthorizedException("member ");
throw new UnauthorizedException("member ID가 예약의 member ID와 일치하지 않습니다.");
}
}
}
Loading

0 comments on commit 3db4d86

Please sign in to comment.