Skip to content

Commit

Permalink
[Weekly/11/Refactor/All] refactor: Advertisement, Event 유효성 리팩터링 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariimo authored Nov 14, 2024
1 parent 2fd7faa commit 0aa3b99
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public ResponseEntity<ApiResponseBody<List<AdvertisementResponse>>> getActiveAdv
@GetMapping("/{adId}")
public ResponseEntity<ApiResponseBody<AdvertisementResponse>> getAdvertisementByAdId(
@PathVariable Long adId) {
return ApiResponse.ok(advertisementService.getAdvertisementByAdId(adId));
return ApiResponse.ok(advertisementService.getById(adId));
}

@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ApiResponseBody<AdvertisementResponse>> createAdvertisement(
@Valid @RequestPart AdvertisementRequest advertisementRequest,
@RequestPart(required = false) MultipartFile image,
@Authorize(MemberType.admin) MemberIdentifier admin) {
@Authorize(MemberType.admin) MemberIdentifier identifier) {
return ApiResponse.created(advertisementService.create(advertisementRequest, image));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
Expand All @@ -14,7 +15,7 @@
@Builder(toBuilder = true)
public class AdvertisementRequest {

@NotEmpty(message = "광고명은 필수입니다.")
@NotBlank(message = "광고명은 필수입니다.")
private String title;

@NotNull(message = "광고게시 시작 시간은 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Advertisement getByIdOrThrow(Long adId) {
}

@Transactional(readOnly = true)
public AdvertisementResponse getAdvertisementByAdId(Long adId) {
public AdvertisementResponse getById(Long adId) {
return AdvertisementResponse.from(getByIdOrThrow(adId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Optional;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -25,11 +27,11 @@ public class Advertisement {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "advertisement_id")
@Setter(AccessLevel.NONE)
@Column(name = "advertisement_id")
private Long id;

@NotNull
@NotBlank
@Column(name = "title")
private String title;

Expand Down Expand Up @@ -57,9 +59,9 @@ public Advertisement(String title, AdvertisementImage advertisementImage,
}

public void updateFrom(AdvertisementRequest advertisementRequest, AdvertisementImage adImage) {
this.title = advertisementRequest.getTitle();
this.advertisementImage = adImage;
this.startTime = advertisementRequest.getStartTime();
this.endTime = advertisementRequest.getEndTime();
Optional.ofNullable(advertisementRequest.getTitle()).ifPresent(this::setTitle);
Optional.ofNullable(adImage).ifPresent(this::setAdvertisementImage);
Optional.ofNullable(advertisementRequest.getStartTime()).ifPresent(this::setStartTime);
Optional.ofNullable(advertisementRequest.getEndTime()).ifPresent(this::setEndTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public class EventCreateRequest {
@NotNull(message = "장소는 필수입니다.")
private Location location;

@NotNull(message = "시작시간은 필수입니다.")
@FutureOrPresent(message = "시작 시간은 현재 시간 이후여야 합니다.")
private LocalDateTime startTime;

@NotNull(message = "종료시간은 필수입니다.")
@FutureOrPresent(message = "종료 시간은 현재 시간 이후여야 합니다.")
private LocalDateTime endTime;

Expand All @@ -48,6 +50,7 @@ public class EventCreateRequest {
@Max(value = 1000000, message = "가격은 1,000,000원 이하입니다.")
private Integer price;

@NotNull(message = "좌석입력은 필수입니다.")
@Min(value = 0, message = "총 좌석은 0석 이상입니다.")
@Max(value = 1000, message = "총 좌석은 1,000석 이하입니다.")
private Integer totalSeat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public class EventEditRequest {
@NotNull(message = "장소는 필수입니다.")
private Location location;

@NotNull(message = "시작 시간은 필수입니다.")
@FutureOrPresent(message = "시작 시간은 현재 시간 이후여야 합니다.")
private LocalDateTime startTime;

@NotNull(message = "종료 시간은 필수입니다.")
@FutureOrPresent(message = "종료 시간은 현재 시간 이후여야 합니다.")
private LocalDateTime endTime;

Expand All @@ -45,6 +47,7 @@ public class EventEditRequest {
@Max(value = 1000000, message = "가격은 1,000,000원 이하입니다.")
private Integer price;

@NotNull(message = "좌석은 필수입니다.")
@Min(value = 0, message = "총 좌석은 0석 이상입니다.")
@Max(value = 1000, message = "총 좌석은 1,000석 이하입니다.")
private Integer totalSeat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Event {
@Column(name = "event_id")
private Long id;

@NotNull
@NotBlank
@Column(name = "title")
private String title;

Expand All @@ -70,9 +70,11 @@ public class Event {
@Column(name = "location")
private Location location;

@NotNull
@Column(name = "start_time")
private LocalDateTime startTime;

@NotNull
@Column(name = "end_time")
private LocalDateTime endTime;

Expand All @@ -81,10 +83,12 @@ public class Event {
@Column(name = "price")
private Integer price;

@NotNull
@Min(1)
@Column(name = "total_seat")
private Integer totalSeat;

@NotNull
@Min(0)
@Column(name = "left_seat")
private Integer leftSeat;
Expand All @@ -101,6 +105,7 @@ public class Event {
@OneToMany(mappedBy = "event", fetch = FetchType.LAZY)
private List<EventImage> images = new ArrayList<>();

@NotNull
@CreatedDate
@Column(name = "created_date")
private LocalDateTime createdDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
// @Autowired
// private WebApplicationContext context;
//
// @BeforeAll
// public static void init() {
// id = 3L;
// validHost = entity.get();
// objectMapper = new ObjectMapper();
// objectMapper.registerModule(new JavaTimeModule());
// }
//// @BeforeAll
//// public static void init() {
//// id = 3L;
//// validHost = entity.get();
//// objectMapper = new ObjectMapper();
//// objectMapper.registerModule(new JavaTimeModule());
//// }
//
// @BeforeEach
// public void setup() throws Exception {
Expand Down

0 comments on commit 0aa3b99

Please sign in to comment.