-
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.
- Loading branch information
1 parent
2e73481
commit 3421b08
Showing
9 changed files
with
101 additions
and
30 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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/kcy/fitapet/domain/care/dao/CareDateQueryDslRepository.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,4 @@ | ||
package com.kcy.fitapet.domain.care.dao; | ||
|
||
public interface CareDateQueryDslRepository { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kcy/fitapet/domain/care/dao/CareDateQueryDslRepositoryImpl.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,16 @@ | ||
package com.kcy.fitapet.domain.care.dao; | ||
|
||
import com.kcy.fitapet.domain.care.domain.QCare; | ||
import com.kcy.fitapet.domain.care.domain.QCareDate; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CareDateQueryDslRepositoryImpl implements CareDateQueryDslRepository { | ||
private final QCare care = QCare.care; | ||
private final QCareDate careDate = QCareDate.careDate; | ||
|
||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/kcy/fitapet/domain/care/dao/CareQueryDslRepository.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,5 @@ | ||
package com.kcy.fitapet.domain.care.dao; | ||
|
||
public interface CareQueryDslRepository { | ||
boolean isValidCare(Long petId, Long careId); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/kcy/fitapet/domain/care/dao/CareQueryDslRepositoryImpl.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,31 @@ | ||
package com.kcy.fitapet.domain.care.dao; | ||
|
||
import com.kcy.fitapet.domain.care.domain.QCare; | ||
import com.kcy.fitapet.domain.care.domain.QCareCategory; | ||
import com.kcy.fitapet.domain.pet.domain.QPet; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import static com.querydsl.core.types.dsl.Expressions.constant; | ||
|
||
@Repository | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class CareQueryDslRepositoryImpl implements CareQueryDslRepository { | ||
private final JPAQueryFactory queryFactory; | ||
private final QPet pet = QPet.pet; | ||
private final QCareCategory careCategory = QCareCategory.careCategory; | ||
private final QCare care = QCare.care; | ||
|
||
public boolean isValidCare(Long petId, Long careId) { | ||
return queryFactory | ||
.select(constant(1)) | ||
.from(pet) | ||
.leftJoin(careCategory).on(careCategory.pet.id.eq(pet.id)) | ||
.leftJoin(care).on(care.careCategory.id.eq(careCategory.id)) | ||
.where(pet.id.eq(petId).and(care.id.eq(careId))) | ||
.fetchOne() != null; | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/kcy/fitapet/global/common/security/authorization/CareAuthorize.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,27 @@ | ||
package com.kcy.fitapet.global.common.security.authorization; | ||
|
||
import com.kcy.fitapet.domain.care.dao.CareDateRepository; | ||
import com.kcy.fitapet.domain.care.dao.CareRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component("careAuthorize") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CareAuthorize { | ||
private final CareRepository careRepository; | ||
private final CareDateRepository careDateRepository; | ||
|
||
public boolean isValidCare(Long petId, Long careId) { | ||
return careRepository.isValidCare(petId, careId); | ||
} | ||
|
||
public boolean isValidCareAndCareDate(Long petId, Long careId, Long careDateId) { | ||
return isValidCare(petId, careId) && isValidCareDate(careId, careDateId); | ||
} | ||
|
||
private boolean isValidCareDate(Long careId, Long careDateId) { | ||
return careDateRepository.existsByIdAndCare_Id(careDateId, careId); | ||
} | ||
} |