-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
19 changed files
with
407 additions
and
58 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
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/org/ftclub/cabinet/cabinet/repository/CabinetComplexRepository.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 org.ftclub.cabinet.cabinet.repository; | ||
|
||
import java.util.List; | ||
import org.ftclub.cabinet.cabinet.domain.Cabinet; | ||
import org.ftclub.cabinet.cabinet.domain.CabinetPlace; | ||
import org.ftclub.cabinet.dto.ActiveCabinetInfoEntities; | ||
import org.ftclub.cabinet.lent.domain.LentHistory; | ||
import org.ftclub.cabinet.user.domain.User; | ||
import org.ftclub.cabinet.utils.annotations.ComplexRepository; | ||
|
||
@ComplexRepository(entityClass = {Cabinet.class, CabinetPlace.class, LentHistory.class, User.class}) | ||
public interface CabinetComplexRepository { | ||
List<ActiveCabinetInfoEntities> findCabinetsActiveLentHistoriesByBuildingAndFloor(String building, Integer floor); | ||
List<Cabinet> findCabinetsByBuildingAndFloor(String building, Integer floor); | ||
List <Cabinet> findAllCabinetsByBuildingAndFloor(String building, Integer floor); | ||
} |
73 changes: 73 additions & 0 deletions
73
...end/src/main/java/org/ftclub/cabinet/cabinet/repository/CabinetComplexRepositoryImpl.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,73 @@ | ||
package org.ftclub.cabinet.cabinet.repository; | ||
|
||
|
||
import static org.ftclub.cabinet.cabinet.domain.QCabinet.cabinet; | ||
import static org.ftclub.cabinet.cabinet.domain.QCabinetPlace.cabinetPlace; | ||
import static org.ftclub.cabinet.lent.domain.QLentHistory.lentHistory; | ||
import static org.ftclub.cabinet.user.domain.QUser.user; | ||
|
||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import javax.persistence.EntityManager; | ||
import org.ftclub.cabinet.cabinet.domain.Cabinet; | ||
import org.ftclub.cabinet.dto.ActiveCabinetInfoEntities; | ||
import org.ftclub.cabinet.dto.QActiveCabinetInfoEntities; | ||
import org.springframework.cache.annotation.CacheConfig; | ||
import org.springframework.cache.annotation.Cacheable; | ||
|
||
@CacheConfig(cacheNames = "cabinets") | ||
public class CabinetComplexRepositoryImpl implements CabinetComplexRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public CabinetComplexRepositoryImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
// CACHE | ||
@Cacheable(key = "#building + #floor") | ||
public List<Cabinet> findAllCabinetsByBuildingAndFloor(String building, Integer floor) { | ||
JPAQuery<Cabinet> query = queryFactory.selectFrom(cabinet) | ||
.join(cabinetPlace) | ||
.on(cabinet.cabinetPlace.cabinetPlaceId.eq(cabinetPlace.cabinetPlaceId)) | ||
.where(cabinetPlace.location.building | ||
.eq(building) | ||
.and(cabinetPlace.location.floor.eq(floor)) | ||
); | ||
return query.fetch(); | ||
} | ||
|
||
@Override | ||
public List<ActiveCabinetInfoEntities> findCabinetsActiveLentHistoriesByBuildingAndFloor( | ||
String building, Integer floor) { | ||
return queryFactory.selectDistinct( | ||
new QActiveCabinetInfoEntities(cabinet, lentHistory, user)) | ||
.from(cabinet) | ||
.join(cabinetPlace) | ||
.on(cabinet.cabinetPlace.cabinetPlaceId.eq(cabinetPlace.cabinetPlaceId)) | ||
.join(lentHistory) | ||
.on(cabinet.cabinetId.eq(lentHistory.cabinet.cabinetId)) | ||
.join(user) | ||
.on(lentHistory.user.userId.eq(user.userId)) | ||
.where(cabinetPlace.location.building | ||
.eq(building) | ||
.and(cabinetPlace.location.floor.eq(floor)) | ||
.and(lentHistory.endedAt.isNull()) | ||
) | ||
.fetch(); | ||
} | ||
|
||
//WIP | ||
@Override | ||
public List<Cabinet> findCabinetsByBuildingAndFloor(String building, Integer floor) { | ||
JPAQuery<Cabinet> where = queryFactory.select(cabinet) | ||
.from(cabinet) | ||
.join(cabinetPlace) | ||
.on(cabinet.cabinetId.eq(cabinetPlace.cabinetPlaceId)) | ||
.where(cabinetPlace.location.building | ||
.eq(building) | ||
.and(cabinetPlace.location.floor.eq(floor))); | ||
return where.fetch(); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/org/ftclub/cabinet/cabinet/repository/FloorLoadRepository.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.ftclub.cabinet.cabinet.repository; | ||
|
||
import org.ftclub.cabinet.cabinet.domain.Cabinet; | ||
import org.ftclub.cabinet.utils.annotations.ComplexRepository; | ||
import org.ftclub.cabinet.lent.domain.LentHistory; | ||
import org.ftclub.cabinet.user.domain.User; | ||
|
||
@ComplexRepository(entityClass = {Cabinet.class, LentHistory.class, User.class}) | ||
public interface FloorLoadRepository { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/org/ftclub/cabinet/cabinet/repository/FloorLoadRepositoryImpl.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.ftclub.cabinet.cabinet.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import javax.persistence.EntityManager; | ||
import org.ftclub.cabinet.cabinet.domain.Cabinet; | ||
import org.ftclub.cabinet.cabinet.domain.CabinetPlace; | ||
import org.ftclub.cabinet.utils.annotations.ComplexRepository; | ||
import org.ftclub.cabinet.lent.domain.LentHistory; | ||
import org.ftclub.cabinet.user.domain.User; | ||
|
||
@ComplexRepository(entityClass = {Cabinet.class, CabinetPlace.class, LentHistory.class, User.class}) | ||
public class FloorLoadRepositoryImpl implements FloorLoadRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public FloorLoadRepositoryImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
} |
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.