-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] #40 create search the closest promise today * [feat] #40 create search list of upcoming promises * [feat] #40 edit today's next promise logic * [fix] #40 edit upcoming promises logic * [fix] #40 add missed brace in code --------- Co-authored-by: tkdwns414 <[email protected]> Co-authored-by: Sangjune park <[email protected]>
- Loading branch information
1 parent
e3f9707
commit b4132ac
Showing
6 changed files
with
145 additions
and
0 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
33 changes: 33 additions & 0 deletions
33
src/main/java/org/kkumulkkum/server/dto/promise/response/MainPromiseDto.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,33 @@ | ||
package org.kkumulkkum.server.dto.promise.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import org.kkumulkkum.server.domain.Promise; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public record MainPromiseDto( | ||
Long id, | ||
String name, | ||
String meetingName, | ||
String dressLevel, | ||
int dDay, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd") | ||
LocalDateTime date, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "a h:mm", locale = "en") | ||
LocalDateTime time, | ||
String placeName | ||
) { | ||
public static MainPromiseDto from(Promise promise) { | ||
return new MainPromiseDto( | ||
promise.getId(), | ||
promise.getName(), | ||
promise.getMeeting().getName(), | ||
promise.getDressUpLevel().getContent(), | ||
(int) ChronoUnit.DAYS.between(LocalDateTime.now(), promise.getTime()), | ||
promise.getTime(), | ||
promise.getTime(), | ||
promise.getPlaceName() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/kkumulkkum/server/dto/promise/response/MainPromisesDto.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.kkumulkkum.server.dto.promise.response; | ||
|
||
import org.kkumulkkum.server.domain.Promise; | ||
|
||
import java.util.List; | ||
|
||
public record MainPromisesDto( | ||
List<MainPromiseDto> promises | ||
) { | ||
public static MainPromisesDto from(List<Promise> promises) { | ||
return new MainPromisesDto( | ||
promises.stream() | ||
.map(MainPromiseDto::from) | ||
.toList() | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/kkumulkkum/server/repository/PromiseRepository.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,17 +1,51 @@ | ||
package org.kkumulkkum.server.repository; | ||
|
||
import org.kkumulkkum.server.domain.Promise; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public interface PromiseRepository extends JpaRepository<Promise, Long> { | ||
|
||
List<Promise> findAllByMeetingId(Long meetingId); | ||
|
||
@Query("SELECT p FROM Participant pt " + | ||
"JOIN pt.member m " + | ||
"JOIN pt.promise p " + | ||
"WHERE m.user.id = :userId " + | ||
"AND p.time >= :startOfDay " + | ||
"AND p.time < :startOfNextDay " + | ||
"AND p.time > CURRENT_TIMESTAMP " + | ||
"AND p.isCompleted = false " + | ||
"ORDER BY p.time ASC, p.createdAt ASC") | ||
List<Promise> findNextPromiseByUserId(Long userId, LocalDateTime startOfDay, LocalDateTime startOfNextDay, Pageable pageable); | ||
|
||
@Query("SELECT p FROM Participant pt " + | ||
"JOIN pt.member m " + | ||
"JOIN pt.promise p " + | ||
"WHERE m.user.id = :userId " + | ||
"AND p.time > CURRENT_TIMESTAMP " + | ||
"AND p.isCompleted = false " + | ||
"AND p.id <> :nextPromiseId " + | ||
"ORDER BY p.time ASC, p.createdAt ASC") | ||
Page<Promise> findUpcomingPromisesExcludingNext(Long userId, Long nextPromiseId, Pageable pageable); | ||
|
||
@Query("SELECT p FROM Participant pt " + | ||
"JOIN pt.member m " + | ||
"JOIN pt.promise p " + | ||
"WHERE m.user.id = :userId " + | ||
"AND p.time > CURRENT_TIMESTAMP " + | ||
"AND p.isCompleted = false " + | ||
"ORDER BY p.time ASC, p.createdAt ASC") | ||
Page<Promise> findUpcomingPromises(Long userId, Pageable pageable); | ||
|
||
@Query("SELECT CASE WHEN EXISTS " + | ||
"(SELECT p FROM Participant p WHERE p.promise.id = :promiseId AND p.arrivalAt IS NULL) " + | ||
"THEN TRUE ELSE FALSE END FROM Participant p") | ||
boolean existsByArrivedAtIsNull(Long promiseId); | ||
|
||
} |
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