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 @@ -3,24 +3,24 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.namul.api.payload.response.DefaultResponse;
import org.springframework.web.bind.annotation.*;
import org.withtime.be.withtimebe.domain.date.converter.DateConverter;
import org.withtime.be.withtimebe.domain.date.dto.request.DateRequestDTO;
import org.withtime.be.withtimebe.domain.date.dto.response.DateResponseDTO;
import org.withtime.be.withtimebe.domain.date.entity.DateCourseBookmark;
import org.withtime.be.withtimebe.domain.date.entity.DatePlace;
import org.withtime.be.withtimebe.domain.date.service.command.DateCommandService;
import org.withtime.be.withtimebe.domain.date.service.command.dto.RecommendedCourseResult;
import org.withtime.be.withtimebe.domain.member.entity.Member;
import org.withtime.be.withtimebe.global.security.annotation.AuthenticatedMember;

import java.util.List;


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/date-courses")
@Tag(name = "데이트 생성 API")
public class DateCommandController {

private final DateCommandService dateCommandService;
Expand All @@ -32,10 +32,9 @@ public class DateCommandController {
@PostMapping("/")
public DefaultResponse<DateResponseDTO.DateCourse> createDateCourse(
@RequestBody DateRequestDTO.CreateDateCourse request
// @AuthenticatedMember Member member
){
List<DatePlace> datePlaces = dateCommandService.createDateCourse(request);
DateResponseDTO.DateCourse dateCourse = DateConverter.createDateCourseInfo(datePlaces);
RecommendedCourseResult datePlaces = dateCommandService.createDateCourse(request);
DateResponseDTO.DateCourse dateCourse = DateConverter.createDateCourseInfo(datePlaces.places(), datePlaces.signature());
return DefaultResponse.created(dateCourse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.namul.api.payload.response.DefaultResponse;
import org.springframework.data.domain.Page;
Expand All @@ -21,6 +22,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/date-courses")
@Tag(name = "데이트 조회 API")
public class DateQueryController {

private final DateQueryService dateQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ public static DateCourse createDateCourse(DateRequestDTO.SaveDateCourse dateCour
// 나중에 생성한 정보를 리턴하는 데 사용,,? 근데 애초에 그 뭐야
// builder()로 만들 때 잘 만들어주면 안되냐
// List<DatePlace> -> DateResponseDTO.DateCourseInfo
public static DateResponseDTO.DateCourse createDateCourseInfo(List<DatePlace> datePlaces){
// 단일 추천 코스를 응답으로 구성(시그니처 포함)
public static DateResponseDTO.DateCourse createDateCourseInfo(List<DatePlace> datePlaces, String signature){
List<DateResponseDTO.DatePlace> datePlaceDtos = datePlaces.stream()
.map(DateConverter::createDatePlace)
.toList();

return DateResponseDTO.DateCourse.builder()
.name(LocalDateTime.now().toLocalDate().toString())
.datePlaces(datePlaceDtos)
.signature(signature) // ← 추가
.build();
}

// DatePlace -> DateResponseDTO.DatePlace
public static DateResponseDTO.DatePlace createDatePlace(DatePlace datePlace) {
return DateResponseDTO.DatePlace.builder()
.datePlaceId(datePlace.getId())
.name(datePlace.getName())
.image(datePlace.getImage())
.tel(datePlace.getTel())
Expand All @@ -75,7 +79,6 @@ public static DateResponseDTO.DateCourse createDateCourse(DateCourse dateCourse)
.toList();

return DateResponseDTO.DateCourse.builder()
.dateCourseId(dateCourse.getId())
.name(dateCourse.getName())
.datePlaces(datePlaces)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.withtime.be.withtimebe.domain.date.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import org.withtime.be.withtimebe.domain.date.entity.enums.DatePriceRange;
import org.withtime.be.withtimebe.domain.date.entity.enums.DateTime;
Expand All @@ -11,37 +14,50 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

public record DateRequestDTO() {


public record CreateDateCourse(
@NotNull(message = "예산을 선택해주세요")
DatePriceRange budget,
@NotNull(message = "예산을 선택해주세요")
@Schema(example = "UNDER_10K")
DatePriceRange budget,

@Size(min = 1, message = "최소 하나 이상의 값을 선택해주세요")
@NotNull(message = "값이 비어있을 수 없습니다")
List<String> datePlaces,
@Size(min = 1, message = "최소 하나 이상의 값을 선택해주세요")
@NotNull(message = "값이 비어있을 수 없습니다")
@Schema(example = "[\"서울 종로구\"]")
List<String> datePlaces,

@NotNull(message = "데이트 시간을 선택해주세요")
DateTime dateDurationTime,
@NotNull(message = "데이트 시간을 선택해주세요")
@Schema(example = "ONETOTWO")
DateTime dateDurationTime,

List<MealType> mealPlan,
@Schema(example = "[\"BREAKFAST\"]")
List<MealType> mealPlan,

@NotBlank(message = "이동 수단을 선택해주세요")
Transportation transportation,
@NotNull(message = "이동 수단을 선택해주세요")
@Schema(example = "WALK")
Transportation transportation,

@Size(min = 1, max = 3)
@NotNull(message = "사용자 취향을 선택해주세요")
List<String> userPreferredKeywords,
@Size(min = 1, max = 3)
@NotNull(message = "사용자 취향을 선택해주세요")
@Schema(example = "[\"레트로 골목\", \"카페\"]")
List<String> userPreferredKeywords,

@JsonFormat(shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ss"
)
LocalDateTime startTime,
@NotBlank(message = "startTime은 필수입니다")
@Pattern(
regexp = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}$",
message = "startTime 형식은 yyyy-MM-dd'T'HH:mm 이어야 합니다"
)
@JsonProperty("startTime")
@Schema(example = "2025-08-14T07:45")
LocalDateTime startTime,

int attemptCount
){}
// 이미 보여줬던 코스의 시그니처(예: "12-45-33")
@Schema(example = "[]")
Set<String> excludedCourseSignatures
) {}

public record SaveDateCourse(
List<Long> datePlaceIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record DateCourseBookmark(

@Builder
public record DatePlace(
Long datePlaceId,
String name,
String image,
String tel,
Expand All @@ -28,9 +29,9 @@ public record DatePlace(

@Builder
public record DateCourse(
Long dateCourseId,
String name,
List<DateResponseDTO.DatePlace> datePlaces
List<DateResponseDTO.DatePlace> datePlaces,
String signature
){}

@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
// ScheduledDateCourse
package org.withtime.be.withtimebe.domain.date.entity.model;

import lombok.Builder;
import lombok.Getter;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;

@Builder
@Getter
public class ScheduledDateCourse implements Comparable<ScheduledDateCourse> {
private List<ScheduledDatePlace> scheduledDatePlaces;
private double weight;

private final List<ScheduledDatePlace> scheduledDatePlaces;
private final double weight; // 코스 총점

@Override
public int compareTo(ScheduledDateCourse o) {
return (int)(this.weight - o.weight);
return Double.compare(this.weight, o.weight);
}

public static final Comparator<ScheduledDateCourse> BY_WEIGHT_ASC =
Comparator.comparingDouble(ScheduledDateCourse::getWeight);
public static final Comparator<ScheduledDateCourse> BY_WEIGHT_DESC =
BY_WEIGHT_ASC.reversed();

public ScheduledDateCourse(List<ScheduledDatePlace> scheduledDatePlaces, double weight) {
this.scheduledDatePlaces = Objects.requireNonNull(scheduledDatePlaces, "scheduledDatePlaces must not be null");
this.weight = weight;
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
// ScheduledDatePlace
package org.withtime.be.withtimebe.domain.date.entity.model;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.withtime.be.withtimebe.domain.date.entity.DatePlace;
import org.withtime.be.withtimebe.domain.date.entity.enums.PlaceType;

import java.time.Duration;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.util.Objects;

@Getter
@ToString
public class ScheduledDatePlace {
private DatePlace datePlace;
private LocalTime startTime;
private LocalTime endTime;
private double score;

// 그리고 여기서 그냥 comparator 쓰면 되지 않나?
private final DatePlace datePlace;

@Builder
public ScheduledDatePlace(DatePlace datePlace, LocalTime startTime, Duration duration, double score) {
this.datePlace = datePlace;
// 시간은 점수 산정 단계에선 없어도 됨(선택)
private final LocalDateTime startTime; // nullable
private final LocalDateTime endTime; // nullable

private final double score;

@Builder(toBuilder = true)
private ScheduledDatePlace(DatePlace datePlace,
LocalDateTime startTime,
LocalDateTime endTime,
double score) {
this.datePlace = Objects.requireNonNull(datePlace, "datePlace must not be null");
this.startTime = startTime;
this.endTime = startTime.plus(duration);
this.endTime = endTime;
this.score = score;
}

// 시간 없이 점수만 설정
public static ScheduledDatePlace ofScoreOnly(DatePlace place, double score) {
return ScheduledDatePlace.builder()
.datePlace(place)
.score(score)
.build();
}

// 시작시각 주면 placeType duration으로 종료시각 계산
public ScheduledDatePlace withScheduleFrom(LocalDateTime start) {
PlaceType type = datePlace.getPlaceType();
Duration dur = (type != null) ? type.getDuration() : Duration.ZERO;
LocalDateTime end = (start != null) ? start.plus(dur) : null;
return this.toBuilder()
.startTime(start)
.endTime(end)
.build();
}

public Duration getDuration() {
return Duration.between(startTime, endTime);
if (startTime != null && endTime != null) {
return Duration.between(startTime, endTime);
}
PlaceType type = datePlace.getPlaceType();
return (type != null) ? type.getDuration() : Duration.ZERO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import org.withtime.be.withtimebe.domain.date.dto.request.DateRequestDTO;
import org.withtime.be.withtimebe.domain.date.entity.DateCourse;
import org.withtime.be.withtimebe.domain.date.entity.DateCourseBookmark;
import org.withtime.be.withtimebe.domain.date.entity.DatePlace;
import org.withtime.be.withtimebe.domain.date.service.command.dto.RecommendedCourseResult;
import org.withtime.be.withtimebe.domain.member.entity.Member;

import java.util.List;


public interface DateCommandService {
public DateCourseBookmark createDateCourseBookmark(Long dateCourseId, Member member);
public DateCourse deleteDateCourseBookmark(Long dateCourseId, Member member);
public DateCourseBookmark createDateCourseBookmarkWithGeneratedCourse(DateRequestDTO.SaveDateCourse request, Member members);
public List<DatePlace> createDateCourse(DateRequestDTO.CreateDateCourse request);
DateCourseBookmark createDateCourseBookmark(Long dateCourseId, Member member);
DateCourse deleteDateCourseBookmark(Long dateCourseId, Member member);
DateCourseBookmark createDateCourseBookmarkWithGeneratedCourse(DateRequestDTO.SaveDateCourse request, Member members);
RecommendedCourseResult createDateCourse(DateRequestDTO.CreateDateCourse request);
}
Loading