-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bef4ae2
commit 416b323
Showing
48 changed files
with
752 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
dateroad-api/src/main/java/org/dateroad/advertisment/dto/response/AdvGetAllRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
package org.dateroad.advertisment.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.dateroad.advertisement.domain.AdTagType; | ||
import org.dateroad.advertisement.domain.Advertisment; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record AdvGetAllRes( | ||
List<AdvertismentDtoRes> advertismentDtoResList | ||
) { | ||
public static AdvGetAllRes of(List<AdvertismentDtoRes> advertismentDtoResList) { | ||
return AdvGetAllRes.builder() | ||
.advertismentDtoResList(advertismentDtoResList) | ||
.build(); | ||
} | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record AdvertismentDtoRes( | ||
Long advertismentId, | ||
String thumbnail, | ||
String title, | ||
AdTagType tag | ||
){ | ||
) { | ||
public static AdvertismentDtoRes of(Advertisment advertisment) { | ||
return new AdvertismentDtoRes(advertisment.getId(), advertisment.getTitle(), advertisment.getThumbnail(), advertisment.getTag()); | ||
return AdvertismentDtoRes.builder() | ||
.advertismentId(advertisment.getId()) | ||
.thumbnail(advertisment.getThumbnail()) | ||
.title(advertisment.getTitle()) | ||
.tag(advertisment.getTag()) | ||
.build(); | ||
} | ||
} | ||
public static AdvGetAllRes of(List<AdvertismentDtoRes> advertismentDtoResList) { | ||
return new AdvGetAllRes(advertismentDtoResList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 17 additions & 16 deletions
33
dateroad-api/src/main/java/org/dateroad/course/service/CourseSpecifications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
package org.dateroad.course.service; | ||
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.Path; | ||
import jakarta.persistence.criteria.Predicate; | ||
import jakarta.persistence.criteria.Root; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
import org.dateroad.course.dto.request.CourseGetAllReq; | ||
import org.dateroad.date.domain.Course; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
public class CourseSpecifications { | ||
public static Specification<Course> filterByCriteria(CourseGetAllReq courseGetAllReq) { | ||
String city = courseGetAllReq.city(); | ||
String country = courseGetAllReq.country(); | ||
Integer cost = courseGetAllReq.cost(); | ||
return (root, query, criteriaBuilder) -> { | ||
List<Predicate> predicates = new ArrayList<>(); | ||
|
||
if (city != null && !city.isEmpty()) { | ||
predicates.add(criteriaBuilder.equal(root.get("city"), city)); | ||
} | ||
|
||
if (country != null && !country.isEmpty()) { | ||
predicates.add(criteriaBuilder.equal(root.get("country"), country)); | ||
} | ||
|
||
if (cost != null) { | ||
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("cost"), cost)); | ||
} | ||
|
||
addPredicate(predicates, criteriaBuilder, root, "city", courseGetAllReq.city(), criteriaBuilder::equal); | ||
addPredicate(predicates, criteriaBuilder, root, "country", courseGetAllReq.country(), criteriaBuilder::equal); | ||
addPredicate(predicates, criteriaBuilder, root, "cost", courseGetAllReq.cost(), criteriaBuilder::lessThanOrEqualTo); | ||
return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
}; | ||
} | ||
|
||
private static <T> void addPredicate(List<Predicate> predicates, CriteriaBuilder criteriaBuilder, Root<?> root, | ||
String attributeName, T value, | ||
BiFunction<Path<T>, T, Predicate> predicateFunction) { | ||
Optional.ofNullable(value) | ||
.ifPresent(val -> predicates.add( | ||
predicateFunction.apply(root.get(attributeName), val)) | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
dateroad-api/src/main/java/org/dateroad/date/api/DateController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.dateroad.date.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.dateroad.auth.argumentresolve.UserId; | ||
import org.dateroad.date.dto.request.DateCreateReq; | ||
import org.dateroad.date.dto.response.DateDetailRes; | ||
import org.dateroad.date.service.DateService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/dates") | ||
@RestController | ||
public class DateController { | ||
private final DateService dateService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> createDate(@UserId final Long userId, | ||
@RequestBody final DateCreateReq dateCreateReq) { | ||
dateService.createDate(userId, dateCreateReq); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
|
||
@GetMapping("/{dateId}") | ||
public ResponseEntity<DateDetailRes> getDateDetail(@RequestHeader final Long userId, | ||
@PathVariable final Long dateId) { | ||
DateDetailRes dateDetailRes = dateService.getDateDetail(userId, dateId); | ||
return ResponseEntity.ok(dateDetailRes); | ||
} | ||
|
||
@DeleteMapping("/{dateId}") | ||
public ResponseEntity<Void> deleteDate(@UserId final Long userId, | ||
@PathVariable final Long dateId) { | ||
dateService.deleteDate(userId, dateId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
dateroad-api/src/main/java/org/dateroad/date/dto/request/DateCreateReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.dateroad.date.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
public record DateCreateReq( | ||
String title, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul") | ||
LocalDate date, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime startAt, | ||
List<TagCreateReq> tags, | ||
String country, | ||
String city, | ||
List<PlaceCreateReq> places | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
dateroad-api/src/main/java/org/dateroad/date/dto/request/PlaceCreateReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.dateroad.date.dto.request; | ||
|
||
public record PlaceCreateReq( | ||
String name, | ||
float duration, | ||
int sequence | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
dateroad-api/src/main/java/org/dateroad/date/dto/request/TagCreateReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.dateroad.date.dto.request; | ||
|
||
import org.dateroad.tag.domain.DateTagType; | ||
|
||
public record TagCreateReq( | ||
DateTagType tag | ||
) { | ||
} |
43 changes: 43 additions & 0 deletions
43
dateroad-api/src/main/java/org/dateroad/date/dto/response/DateDetailRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.dateroad.date.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.dateroad.date.domain.Date; | ||
import org.dateroad.place.domain.DatePlace; | ||
import org.dateroad.tag.domain.DateTag; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record DateDetailRes( | ||
Long dateId, | ||
String title, | ||
LocalTime startAt, | ||
String city, | ||
List<TagGetRes> tags, | ||
LocalDate date, | ||
List<PlaceGetRes> places | ||
) { | ||
|
||
public static DateDetailRes of(Date date, List<DateTag> tags, List<DatePlace> places) { | ||
|
||
List<TagGetRes> tagGetRes = tags.stream() | ||
.map(TagGetRes::of) | ||
.toList(); | ||
|
||
List<PlaceGetRes> placeGetRes = places.stream() | ||
.map(PlaceGetRes::of) | ||
.toList(); | ||
|
||
return DateDetailRes.builder() | ||
.dateId(date.getId()) | ||
.title(date.getTitle()) | ||
.startAt(date.getStartAt()) | ||
.tags(tagGetRes) | ||
.date(date.getDate()) | ||
.places(placeGetRes) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
dateroad-api/src/main/java/org/dateroad/date/dto/response/PlaceGetRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.dateroad.date.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.dateroad.place.domain.DatePlace; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
|
||
public record PlaceGetRes( | ||
String name, | ||
float duration, | ||
int sequence | ||
) { | ||
public static PlaceGetRes of(DatePlace datePlace) { | ||
return PlaceGetRes.builder() | ||
.name(datePlace.getName()) | ||
.duration(datePlace.getDuration()) | ||
.sequence(datePlace.getSequence()) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dateroad-api/src/main/java/org/dateroad/date/dto/response/TagGetRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.dateroad.date.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import org.dateroad.tag.domain.DateTag; | ||
import org.dateroad.tag.domain.DateTagType; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record TagGetRes( | ||
DateTagType tag | ||
) { | ||
public static TagGetRes of(DateTag dateTag) { | ||
return TagGetRes.builder() | ||
.tag(dateTag.getDateTagType()) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
dateroad-api/src/main/java/org/dateroad/date/service/DateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.dateroad.date.service; | ||
|
||
import org.dateroad.date.domain.Date; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface DateRepository extends JpaRepository<Date, Long> { | ||
} |
Oops, something went wrong.