-
Notifications
You must be signed in to change notification settings - Fork 3
Enhancement/134 enhance room domain model #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PIPetkova19
wants to merge
21
commits into
main
Choose a base branch
from
enhancement/134-enhance-room-domain-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5a2598a
Remove internal dto, update mapper
PIPetkova19 81bd802
Update roomService by implementing baseService
PIPetkova19 8527924
Add room facade layer
PIPetkova19 5217de6
Update controller to use facade layer
PIPetkova19 cd5b74c
Add tests for room service
PIPetkova19 93be8fa
Add tests for roomMapper
PIPetkova19 5745b77
Add tests for RoomWebFacade
PIPetkova19 f8fc9aa
Include category in room response
PIPetkova19 18a22b8
Change to left join instead of inner
PIPetkova19 2109a9e
Use Criteria API instead of jpql in room repository
PIPetkova19 01bbc6c
Update mapper test
PIPetkova19 c1969bc
Update room web facade tests
PIPetkova19 68610f8
Change findRoomResponseById signature
PIPetkova19 b964d82
Feature/104 add soft delete on faculty; Bug/105 Delete Major doesn't …
PIPetkova19 7c9ecbe
Add availableSeats column to Room entity, update dtos, repository met…
PIPetkova19 ab0c3e1
Make faculty optional for room
PIPetkova19 489f7f0
Add description field to category
PIPetkova19 2afbb6d
Add Building entity, update liquibase
PIPetkova19 cd3b649
Add room field to building
PIPetkova19 3768d12
Merge branch 'main' into enhancement/134-enhance-room-domain-model
PIPetkova19 3ba1f78
Merge branch 'main' into enhancement/134-enhance-room-domain-model
PIPetkova19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| package org.unilab.uniplan.building; | ||
|
|
||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.OneToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.unilab.uniplan.common.model.BaseEntity; | ||
| import org.unilab.uniplan.room.Room; | ||
| import org.unilab.uniplan.university.University; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Table(name = "building") | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Building extends BaseEntity { | ||
|
|
||
| @Column(name = "name", nullable = false, length = 50) | ||
| private String name; | ||
|
|
||
| @Column(name = "address", nullable = false, length = 100) | ||
| private String address; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "university_id", referencedColumnName = "id") | ||
| private University university; | ||
|
|
||
| @OneToMany(mappedBy = "building") | ||
| private List<Room> rooms = new ArrayList<>(); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
src/main/java/org/unilab/uniplan/room/CustomRoomRepository.java
This file contains hidden or 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,14 @@ | ||
| package org.unilab.uniplan.room; | ||
|
|
||
| import org.springframework.data.repository.query.Param; | ||
| import org.unilab.uniplan.room.dto.RoomResponseDto; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public interface CustomRoomRepository { | ||
|
|
||
| List<RoomResponseDto> findAllRoomResponses(); | ||
|
|
||
| Optional<RoomResponseDto> findRoomResponseById(UUID id); | ||
| } |
81 changes: 81 additions & 0 deletions
81
src/main/java/org/unilab/uniplan/room/CustomRoomRepositoryImpl.java
This file contains hidden or 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,81 @@ | ||
| package org.unilab.uniplan.room; | ||
|
|
||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.persistence.PersistenceContext; | ||
| import org.hibernate.query.common.JoinType; | ||
| import org.hibernate.query.criteria.HibernateCriteriaBuilder; | ||
| import org.hibernate.query.criteria.JpaCriteriaQuery; | ||
| import org.hibernate.query.criteria.JpaEntityJoin; | ||
| import org.hibernate.query.criteria.JpaRoot; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.unilab.uniplan.category.Category; | ||
| import org.unilab.uniplan.room.dto.RoomResponseDto; | ||
| import org.unilab.uniplan.roomcategory.RoomCategory; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public class CustomRoomRepositoryImpl implements CustomRoomRepository { | ||
|
|
||
| @PersistenceContext | ||
| private EntityManager entityManager; | ||
|
|
||
| @Override | ||
| public List<RoomResponseDto> findAllRoomResponses() { | ||
| HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder(); | ||
|
|
||
| JpaCriteriaQuery<RoomResponseDto> query = cb.createQuery(RoomResponseDto.class); | ||
|
|
||
| JpaRoot<Room> room = query.from(Room.class); | ||
|
|
||
| JpaEntityJoin<Room, RoomCategory> roomCategory = | ||
| room.join(RoomCategory.class, JoinType.LEFT); | ||
| roomCategory.on(cb.equal(roomCategory.get("room"), room)); | ||
|
|
||
| JpaEntityJoin<RoomCategory, Category> category = | ||
| roomCategory.join(Category.class, JoinType.LEFT); | ||
| category.on(cb.equal(category, roomCategory.get("category"))); | ||
|
|
||
| query.select(cb.construct( | ||
| RoomResponseDto.class, | ||
| room.get("id"), | ||
| room.get("faculty").get("id"), | ||
| room.get("roomNumber"), | ||
| room.get("availableSeats"), | ||
| category.get("id"), | ||
| room.get("building").get("id") | ||
| )); | ||
|
|
||
| return entityManager.createQuery(query).getResultList(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<RoomResponseDto> findRoomResponseById(UUID id) { | ||
| HibernateCriteriaBuilder cb = (HibernateCriteriaBuilder) entityManager.getCriteriaBuilder(); | ||
|
|
||
| JpaCriteriaQuery<RoomResponseDto> query = cb.createQuery(RoomResponseDto.class); | ||
|
|
||
| JpaRoot<Room> room = query.from(Room.class); | ||
| JpaEntityJoin<Room, RoomCategory> roomCategory = | ||
| room.join(RoomCategory.class, JoinType.LEFT); | ||
| roomCategory.on(cb.equal(roomCategory.get("room"), room)); | ||
|
|
||
| JpaEntityJoin<RoomCategory, Category> category = | ||
| roomCategory.join(Category.class, JoinType.LEFT); | ||
| category.on(cb.equal(category, roomCategory.get("category"))); | ||
|
|
||
| query.select(cb.construct( | ||
| RoomResponseDto.class, | ||
| room.get("id"), | ||
| room.get("faculty").get("id"), | ||
| room.get("roomNumber"), | ||
| room.get("availableSeats"), | ||
| category.get("id"), | ||
| room.get("building").get("id") | ||
| )).where(cb.equal(room.get("id"), id)); | ||
|
|
||
| return entityManager.createQuery(query) | ||
| .getResultStream() | ||
| .findFirst(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are unused imports