Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public record StampInfo(
Long stampId,
String stampName,
int stampOrder,
String deadline,
boolean completed,
String createdAt,
String updatedAt,
Expand All @@ -17,7 +16,6 @@ public static StampInfo from(Stamp stamp) {
stamp.getId(),
stamp.getName(),
stamp.getStampOrder(),
DateUtil.formatDate(stamp.getDeadline()),
stamp.isCompleted(),
DateUtil.formatDateTime(stamp.getCreatedAt()),
DateUtil.formatDateTime(stamp.getUpdatedAt()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.ject.studytrip.stamp.application.service.StampService;
import com.ject.studytrip.stamp.domain.model.Stamp;
import com.ject.studytrip.stamp.presentation.dto.request.CreateStampRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampNameAndDeadlineRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampOrderRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampRequest;
import com.ject.studytrip.trip.application.service.TripService;
import com.ject.studytrip.trip.domain.model.Trip;
import java.util.List;
Expand All @@ -34,12 +34,11 @@ public StampInfo createStamp(Long memberId, Long tripId, CreateStampRequest requ
}

@Transactional
public void updateStampNameAndDeadline(
Long memberId, Long tripId, Long stampId, UpdateStampNameAndDeadlineRequest request) {
public void updateStamp(Long memberId, Long tripId, Long stampId, UpdateStampRequest request) {
Trip trip = tripService.getValidTrip(memberId, tripId);
Stamp stamp = stampService.getValidStamp(trip.getId(), stampId);

stampService.updateStampNameAndDeadline(trip, stamp, request);
stampService.updateStampName(stamp, request);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.ject.studytrip.stamp.domain.repository.StampQueryRepository;
import com.ject.studytrip.stamp.domain.repository.StampRepository;
import com.ject.studytrip.stamp.presentation.dto.request.CreateStampRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampNameAndDeadlineRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampOrderRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampRequest;
import com.ject.studytrip.trip.domain.model.Trip;
import com.ject.studytrip.trip.domain.model.TripCategory;
import java.util.*;
Expand All @@ -25,10 +25,7 @@ public class StampService {
private final StampQueryRepository stampQueryRepository;

public Stamp createStamp(Trip trip, CreateStampRequest request) {
Stamp newStamp =
StampFactory.create(trip, request.name(), request.order(), request.deadline());

StampPolicy.validateStampDeadline(trip.getEndDate(), List.of(newStamp));
Stamp newStamp = StampFactory.create(trip, request.name(), request.order());

List<Stamp> existingStamps =
stampRepository.findAllByTripIdAndDeletedAtIsNull(trip.getId());
Expand All @@ -43,26 +40,16 @@ public Stamp createStamp(Trip trip, CreateStampRequest request) {
public void createStamps(Trip trip, List<CreateStampRequest> requests) {
List<Stamp> stamps =
requests.stream()
.map(
stamp ->
StampFactory.create(
trip,
stamp.name(),
stamp.order(),
stamp.deadline()))
.map(stamp -> StampFactory.create(trip, stamp.name(), stamp.order()))
.toList();

StampPolicy.validateStampDeadline(trip.getEndDate(), stamps);
StampPolicy.validateStampOrders(trip.getCategory(), stamps);

stampRepository.saveAll(stamps);
}

public void updateStampNameAndDeadline(
Trip trip, Stamp stamp, UpdateStampNameAndDeadlineRequest request) {
stamp.update(request.name(), request.deadline());

StampPolicy.validateStampDeadline(trip.getEndDate(), List.of(stamp));
public void updateStampName(Stamp stamp, UpdateStampRequest request) {
stamp.updateName(request.name());
}

public void updateStampOrders(Trip trip, UpdateStampOrderRequest request) {
Expand Down Expand Up @@ -91,7 +78,7 @@ public void updateStampOrders(Trip trip, UpdateStampOrderRequest request) {
}

public void updateStampOrdersByTripCategoryChange(Long tripId, TripCategory newCategory) {
List<Stamp> stamps = stampRepository.findAllByTripIdOrderByDeadlineAsc(tripId);
List<Stamp> stamps = stampRepository.findAllByTripIdOrderByCreatedAtAsc(tripId);

if (newCategory == TripCategory.EXPLORE) {
stamps.forEach(stamp -> stamp.updateStampOrder(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
@RequiredArgsConstructor
public enum StampErrorCode implements ErrorCode {
// 400
STAMP_DEADLINE_CANNOT_BE_IN_PAST(HttpStatus.BAD_REQUEST, "스탬프의 마감일은 과거일 수 없습니다."),
STAMP_DEADLINE_EXCEEDS_TRIP_END_DATE(HttpStatus.BAD_REQUEST, "스탬프의 마감일은 여행 종료일을 초과할 수 없습니다."),
INVALID_STAMP_ORDER_FOR_EXPLORATION_TRIP(
HttpStatus.BAD_REQUEST, "탐험형 여행에서는 스탬프 순서를 지정할 수 없으며, 항상 0이여야 합니다. "),
INVALID_STAMP_ORDER_RANGE_FOR_COURSE_TRIP(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.ject.studytrip.stamp.domain.model.Stamp;
import com.ject.studytrip.trip.domain.model.Trip;
import java.time.LocalDate;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class StampFactory {
public static Stamp create(Trip trip, String name, int stampOrder, LocalDate deadline) {
return Stamp.of(trip, name, stampOrder, deadline);
public static Stamp create(Trip trip, String name, int stampOrder) {
return Stamp.of(trip, name, stampOrder);
}
}
11 changes: 2 additions & 9 deletions src/main/java/com/ject/studytrip/stamp/domain/model/Stamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.ject.studytrip.global.common.entity.BaseTimeEntity;
import com.ject.studytrip.trip.domain.model.Trip;
import jakarta.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.*;

@Entity
Expand All @@ -30,24 +28,19 @@ public class Stamp extends BaseTimeEntity {

private int stampOrder;

@Column(nullable = false)
private LocalDate deadline;

private boolean completed;

public static Stamp of(Trip trip, String name, int stampOrder, LocalDate deadline) {
public static Stamp of(Trip trip, String name, int stampOrder) {
return Stamp.builder()
.trip(trip)
.name(name)
.stampOrder(stampOrder)
.deadline(deadline)
.completed(false)
.build();
}

public void update(String name, LocalDate deadline) {
public void updateName(String name) {
if (hasText(name)) this.name = name;
if (Objects.nonNull(deadline)) this.deadline = deadline;
}

public void updateStampOrder(int newOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.ject.studytrip.stamp.domain.error.StampErrorCode;
import com.ject.studytrip.stamp.domain.model.Stamp;
import com.ject.studytrip.trip.domain.model.TripCategory;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -23,21 +22,6 @@ public static void validateNotDeleted(Stamp stamp) {
throw new CustomException(StampErrorCode.STAMP_ALREADY_DELETED);
}

public static void validateStampDeadline(LocalDate tripEndDate, List<Stamp> stamps) {
if (tripEndDate == null || stamps.isEmpty()) return;

LocalDate today = LocalDate.now();
for (Stamp stamp : stamps) {
LocalDate stampDeadline = stamp.getDeadline();

if (stampDeadline.isBefore(today))
throw new CustomException(StampErrorCode.STAMP_DEADLINE_CANNOT_BE_IN_PAST);

if (stampDeadline.isAfter(tripEndDate))
throw new CustomException(StampErrorCode.STAMP_DEADLINE_EXCEEDS_TRIP_END_DATE);
}
}

public static void validateStampOrders(TripCategory tripCategory, List<Stamp> stamps) {
int maxOrder = stamps.size();
Set<Integer> orderSet = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface StampRepository {

List<Stamp> findAllByTripIdAndDeletedAtIsNull(Long tripId);

List<Stamp> findAllByTripIdOrderByDeadlineAsc(Long tripId);
List<Stamp> findAllByTripIdOrderByCreatedAtAsc(Long tripId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface StampJpaRepository extends JpaRepository<Stamp, Long> {

List<Stamp> findAllByTripIdAndDeletedAtIsNull(Long tripId);

List<Stamp> findAllByTripIdOrderByDeadlineAsc(Long tripId);
List<Stamp> findAllByTripIdOrderByCreatedAtAsc(Long tripId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<Stamp> findAllByTripIdAndDeletedAtIsNull(Long tripId) {
}

@Override
public List<Stamp> findAllByTripIdOrderByDeadlineAsc(Long tripId) {
return stampJpaRepository.findAllByTripIdOrderByDeadlineAsc(tripId);
public List<Stamp> findAllByTripIdOrderByCreatedAtAsc(Long tripId) {
return stampJpaRepository.findAllByTripIdOrderByCreatedAtAsc(tripId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.ject.studytrip.stamp.application.dto.StampInfo;
import com.ject.studytrip.stamp.application.facade.StampFacade;
import com.ject.studytrip.stamp.presentation.dto.request.CreateStampRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampNameAndDeadlineRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampOrderRequest;
import com.ject.studytrip.stamp.presentation.dto.request.UpdateStampRequest;
import com.ject.studytrip.stamp.presentation.dto.response.CreateStampResponse;
import com.ject.studytrip.stamp.presentation.dto.response.LoadStampDetailResponse;
import com.ject.studytrip.stamp.presentation.dto.response.LoadStampInfoResponse;
Expand Down Expand Up @@ -43,14 +43,14 @@ public ResponseEntity<StandardResponse> createStamp(
HttpStatus.CREATED.value(), CreateStampResponse.of(result)));
}

@Operation(summary = "스탬프 이름, 마감일 수정", description = "특정 스탬프의 이름과 마감일을 수정합니다.")
@Operation(summary = "스탬프 수정", description = "특정 스탬프의 이름을 수정합니다.")
@PatchMapping("/api/trips/{tripId}/stamps/{stampId}")
public ResponseEntity<StandardResponse> updateStamp(
@AuthenticationPrincipal String memberId,
@PathVariable @NotNull(message = "여행 ID는 필수 요청 파라미터입니다.") Long tripId,
@PathVariable @NotNull(message = "스탬프 ID는 필수 요청 파라미터입니다.") Long stampId,
@RequestBody @Valid UpdateStampNameAndDeadlineRequest request) {
stampFacade.updateStampNameAndDeadline(Long.valueOf(memberId), tripId, stampId, request);
@RequestBody @Valid UpdateStampRequest request) {
stampFacade.updateStamp(Long.valueOf(memberId), tripId, stampId, request);

return ResponseEntity.status(HttpStatus.OK)
.body(StandardResponse.success(HttpStatus.OK.value(), null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package com.ject.studytrip.stamp.presentation.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;

public record CreateStampRequest(
@Schema(description = "스탬프 이름") @NotEmpty(message = "스탬프 이름은 필수 요청 값입니다.") String name,
@Schema(description = "스탬프 순서") @Min(value = 0, message = "스탬프 순서는 최소 0 이상이여야 합니다.")
int order,
@Schema(description = "스탬프 마감일")
@NotNull(message = "스탬프 마감일은 필수 요청 값입니다.")
@FutureOrPresent(message = "스탬프 마감일은 현재 날짜보다 과거일 수 없습니다.")
LocalDate deadline) {}
int order) {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ject.studytrip.stamp.presentation.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;

public record UpdateStampRequest(@Schema(description = "수정할 스탬프 이름") String name) {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ public record LoadStampDetailResponse(
@Schema(description = "스탬프 ID") Long stampId,
@Schema(description = "스탬프 이름") String stampName,
@Schema(description = "스탬프 순서") int stampOrder,
@Schema(description = "스탬프 마감일") String stampDeadline,
@Schema(description = "스탬프 완료 여부") boolean completed,
@Schema(description = "미션 목록") List<LoadMissionInfoResponse> missions) {
public static LoadStampDetailResponse of(StampInfo stampInfo, List<MissionInfo> missionInfos) {
return new LoadStampDetailResponse(
stampInfo.stampId(),
stampInfo.stampName(),
stampInfo.stampOrder(),
stampInfo.deadline(),
stampInfo.completed(),
missionInfos.stream().map(LoadMissionInfoResponse::of).toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ public record LoadStampInfoResponse(
@Schema(description = "스탬프 ID") Long stampId,
@Schema(description = "스탬프 이름") String stampName,
@Schema(description = "스탬프 순서") int stampOrder,
@Schema(description = "스탬프 마감일") String stampDeadline,
@Schema(description = "스탬프 완료 여부") boolean completed) {
public static LoadStampInfoResponse of(StampInfo info) {
return new LoadStampInfoResponse(
info.stampId(),
info.stampName(),
info.stampOrder(),
info.deadline(),
info.completed());
info.stampId(), info.stampName(), info.stampOrder(), info.completed());
}
}
Loading