-
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] 확정된 약속들 조회 API 구현
- Loading branch information
Showing
41 changed files
with
1,212 additions
and
857 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
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
23 changes: 0 additions & 23 deletions
23
src/main/java/org/noostak/appointment/domain/AppointmentRepository.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,31 +1,8 @@ | ||
package org.noostak.appointment.domain; | ||
|
||
import org.noostak.appointment.common.exception.AppointmentErrorCode; | ||
import org.noostak.appointment.common.exception.AppointmentException; | ||
import org.noostak.appointment.domain.vo.AppointmentStatus; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface AppointmentRepository extends JpaRepository<Appointment, Long>, AppointmentRepositoryCustom { | ||
|
||
@Query(nativeQuery = true, value = | ||
"SELECT * " + | ||
"FROM appointment " + | ||
"WHERE appointment_status = :status "+ | ||
"AND groups_id = :groupId") | ||
List<Appointment> findAllByGroupIdConfirmed(String status, Long groupId); | ||
|
||
|
||
default List<Appointment> getAllByGroupIdConfirmed(AppointmentStatus status, Long groupId){ | ||
return findAllByGroupIdConfirmed(status.name(),groupId); | ||
} | ||
|
||
default Appointment getById(Long appointmentId){ | ||
return findById(appointmentId) | ||
.orElseThrow(()-> new AppointmentException(AppointmentErrorCode.APPOINTMENT_NOT_FOUND)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/noostak/appointment/domain/AppointmentRepositoryCustom.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,7 +1,11 @@ | ||
package org.noostak.appointment.domain; | ||
|
||
import org.noostak.appointment.domain.vo.AppointmentStatus; | ||
|
||
import java.util.List; | ||
|
||
public interface AppointmentRepositoryCustom { | ||
List<Appointment> findAllByGroupId(Long groupId); | ||
List<Appointment> findAllByGroupIdConfirmed(AppointmentStatus status, Long groupId); | ||
List<Appointment> findAllByGroupIdConfirmed(Long groupId); | ||
} |
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
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
1 change: 0 additions & 1 deletion
1
...rg/noostak/appointmentoption/application/AppointmentOptionConfirmedOptionServiceImpl.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
65 changes: 2 additions & 63 deletions
65
src/main/java/org/noostak/appointmentoption/domain/AppointmentOptionRepository.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,69 +1,8 @@ | ||
package org.noostak.appointmentoption.domain; | ||
|
||
import org.noostak.appointment.domain.Appointment; | ||
import org.noostak.appointmentoption.domain.vo.AppointmentOptionStatus; | ||
import org.noostak.appointmentoption.common.exception.AppointmentOptionErrorCode; | ||
import org.noostak.appointmentoption.common.exception.AppointmentOptionException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Repository | ||
public interface AppointmentOptionRepository extends JpaRepository<AppointmentOption, Long> { | ||
|
||
@Query(nativeQuery = true, | ||
value = "SELECT * " + | ||
"FROM appointment_option " + | ||
"WHERE appointment_id = :appointmentId " + | ||
"AND appointment_option_status = :status " + | ||
"AND YEAR(appointment_option_date) = :year " + | ||
"AND MONTH(appointment_option_date) = :month " + | ||
"LIMIT 1") | ||
AppointmentOption findByAppointmentConfirmedYearAndMonth( | ||
Long appointmentId, | ||
String status, | ||
int year, | ||
int month); | ||
|
||
default AppointmentOption getByAppointmentConfirmedYearAndMonth(Appointment appointment, int year, int month){ | ||
return findByAppointmentConfirmedYearAndMonth( | ||
appointment.getId(), | ||
AppointmentOptionStatus.CONFIRMED.name(), | ||
year, | ||
month | ||
); | ||
} | ||
|
||
@Query(nativeQuery = true, | ||
value = "SELECT * " + | ||
"FROM appointment_option " + | ||
"WHERE appointment_id = :appointmentId " + | ||
"AND appointment_option_status = :status " + | ||
"AND appointment_option_date BETWEEN :startDate AND :endDate " + | ||
"LIMIT 1") | ||
AppointmentOption findAllByAppointmentConfirmedBetweenDate(Long appointmentId, | ||
String status, | ||
LocalDate startDate, | ||
LocalDate endDate); | ||
|
||
|
||
default AppointmentOption getAllByAppointmentConfirmedBetweenDate( | ||
Appointment appointment, | ||
LocalDate startDate, | ||
LocalDate endDate | ||
) { | ||
return findAllByAppointmentConfirmedBetweenDate( | ||
appointment.getId(), | ||
AppointmentOptionStatus.CONFIRMED.name(), | ||
startDate, | ||
endDate | ||
); | ||
} | ||
|
||
default AppointmentOption getById(Long optionId){ | ||
return findById(optionId) | ||
.orElseThrow(()-> new AppointmentOptionException(AppointmentOptionErrorCode.APPOINTMENT_OPTION_NOT_FOUND)); | ||
} | ||
} | ||
public interface AppointmentOptionRepository extends JpaRepository<AppointmentOption, Long>, AppointmentOptionRepositoryCustom { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/noostak/appointmentoption/domain/AppointmentOptionRepositoryCustom.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,11 @@ | ||
package org.noostak.appointmentoption.domain; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
public interface AppointmentOptionRepositoryCustom { | ||
Optional<AppointmentOption> findByAppointmentConfirmedYearAndMonth(Long appointmentId, int year, int month); | ||
Optional<AppointmentOption> findByAppointmentConfirmedBetweenDate(Long appointmentId, LocalDate startDate, LocalDate endDate); | ||
Optional<AppointmentOption> findConfirmedOptionByAppointmentId(Long appointmentId); | ||
} | ||
|
64 changes: 64 additions & 0 deletions
64
src/main/java/org/noostak/appointmentoption/domain/AppointmentOptionRepositoryImpl.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,64 @@ | ||
package org.noostak.appointmentoption.domain; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.noostak.appointmentoption.domain.vo.AppointmentOptionStatus; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
import static org.noostak.appointmentoption.domain.QAppointmentOption.appointmentOption; | ||
|
||
@RequiredArgsConstructor | ||
public class AppointmentOptionRepositoryImpl implements AppointmentOptionRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Optional<AppointmentOption> findByAppointmentConfirmedYearAndMonth(Long appointmentId, int year, int month) { | ||
return Optional.ofNullable( | ||
queryFactory | ||
.selectFrom(appointmentOption) | ||
.where( | ||
appointmentOption.appointment.id.eq(appointmentId), | ||
appointmentOption.status.eq(AppointmentOptionStatus.CONFIRMED), | ||
appointmentOption.date.year().eq(year), | ||
appointmentOption.date.month().eq(month) | ||
) | ||
.limit(1) | ||
.fetchOne() | ||
); | ||
} | ||
|
||
@Override | ||
public Optional<AppointmentOption> findByAppointmentConfirmedBetweenDate(Long appointmentId, LocalDate startDate, LocalDate endDate) { | ||
return Optional.ofNullable( | ||
queryFactory | ||
.selectFrom(appointmentOption) | ||
.where( | ||
appointmentOption.appointment.id.eq(appointmentId), | ||
appointmentOption.status.eq(AppointmentOptionStatus.CONFIRMED), | ||
appointmentOption.date.between( | ||
startDate.atStartOfDay(), | ||
endDate.atTime(23, 59, 59) | ||
) | ||
) | ||
.limit(1) | ||
.fetchOne() | ||
); | ||
} | ||
|
||
@Override | ||
public Optional<AppointmentOption> findConfirmedOptionByAppointmentId(Long appointmentId) { | ||
return Optional.ofNullable( | ||
queryFactory | ||
.selectFrom(appointmentOption) | ||
.where( | ||
appointmentOption.appointment.id.eq(appointmentId), | ||
appointmentOption.status.eq(AppointmentOptionStatus.CONFIRMED) // 확정된 옵션만 조회 | ||
) | ||
.fetchOne() | ||
); | ||
} | ||
} |
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
Oops, something went wrong.