-
Notifications
You must be signed in to change notification settings - Fork 3
Facade migration t1 roomcategory facade clean #137
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
DjesikaV
wants to merge
12
commits into
main
Choose a base branch
from
Facade-migration-T1-roomcategory-facade-clean
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
12 commits
Select commit
Hold shift + click to select a range
a001096
add RoomCategoryValidator
b4db7f0
Simplify roomCategoryService
6c87b28
migrate room category to facade
35af1ab
refactor RoomCategoryServiceTest
dff3080
add RoomCategoryWebFacadeTest
33887f0
add messages to @NotNull
54b519a
remove validations from response dto
3608c07
add RoomCategoryValidatorTest
c094756
Merge https://github.com/uni-dev-lab/uniplan into Facade-migration—T1…
5d13b2d
rename test methods
f3c1dd8
Merge branch 'main' of https://github.com/uni-dev-lab/uniplan into Fa…
9aa3a8f
Merge branch 'main' into Facade-migration-T1-roomcategory-facade-clean
DjesikaV 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
Binary file not shown.
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
39 changes: 8 additions & 31 deletions
39
src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryService.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 |
|---|---|---|
| @@ -1,52 +1,29 @@ | ||
| package org.unilab.uniplan.roomcategory; | ||
|
|
||
| import static org.unilab.uniplan.utils.ErrorConstants.ROOM_CATEGORY_NOT_FOUND; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.unilab.uniplan.exception.ResourceNotFoundException; | ||
| import org.unilab.uniplan.roomcategory.dto.RoomCategoryDto; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class RoomCategoryService { | ||
|
|
||
| private final RoomCategoryRepository roomCategoryRepository; | ||
| private final RoomCategoryMapper roomCategoryMapper; | ||
|
|
||
| @Transactional | ||
| public RoomCategoryDto createRoomCategory(final RoomCategoryDto roomCategoryDto) { | ||
| final RoomCategory roomCategory = roomCategoryMapper.toEntity(roomCategoryDto); | ||
|
|
||
| return roomCategoryMapper.toDto(roomCategoryRepository.save(roomCategory)); | ||
| public void save(final RoomCategory roomCategory) { | ||
| roomCategoryRepository.save(roomCategory); | ||
| } | ||
|
|
||
| public List<RoomCategoryDto> getAllRoomCategories() { | ||
| final List<RoomCategory> roomCategories = roomCategoryRepository.findAll(); | ||
| return roomCategoryMapper.toDtoList(roomCategories); | ||
| public List<RoomCategory> getAll() { | ||
| return roomCategoryRepository.findAll(); | ||
| } | ||
|
|
||
| public RoomCategoryDto getRoomCategoryById(final UUID roomId, final UUID categoryId) { | ||
| final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); | ||
|
|
||
| return roomCategoryRepository.findById(id) | ||
| .map(roomCategoryMapper::toDto) | ||
| .orElseThrow(() -> new ResourceNotFoundException( | ||
| ROOM_CATEGORY_NOT_FOUND.getMessage(String.valueOf(id)))); | ||
| public Optional<RoomCategory> getById(final RoomCategoryId id) { | ||
| return roomCategoryRepository.findById(id); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void deleteRoomCategory(final UUID roomId, final UUID categoryId) { | ||
| final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); | ||
|
|
||
| final RoomCategory roomCategory = roomCategoryRepository.findById(id) | ||
| .orElseThrow(() -> new ResourceNotFoundException( | ||
| ROOM_CATEGORY_NOT_FOUND.getMessage( | ||
| String.valueOf(id)))); | ||
|
|
||
| public void delete(RoomCategory roomCategory) { | ||
| roomCategoryRepository.delete(roomCategory); | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryValidator.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,47 @@ | ||
| package org.unilab.uniplan.roomcategory; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import org.unilab.uniplan.category.CategoryRepository; | ||
| import org.unilab.uniplan.exception.ResourceNotFoundException; | ||
| import org.unilab.uniplan.room.RoomRepository; | ||
| import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.unilab.uniplan.utils.ErrorConstants.CATEGORY_NOT_FOUND; | ||
| import static org.unilab.uniplan.utils.ErrorConstants.ROOM_NOT_FOUND; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class RoomCategoryValidator { | ||
| private final CategoryRepository categoryRepository; | ||
| private final RoomRepository roomRepository; | ||
|
|
||
| public void validateForCreate(final RoomCategoryRequestDto requestDto) { | ||
| validateCategoryExists(requestDto.categoryId()); | ||
| validateRoomExists(requestDto.roomId()); | ||
| } | ||
|
|
||
| public void validateForUpdate(final RoomCategoryId id, final RoomCategoryRequestDto requestDto) { | ||
| validateCategoryExists(requestDto.categoryId()); | ||
| validateRoomExists(requestDto.roomId()); | ||
| } | ||
|
|
||
| public void validateCategoryExists(final UUID categoryId) { | ||
| if (!categoryRepository.existsById(categoryId)) { | ||
| throw new ResourceNotFoundException( | ||
| CATEGORY_NOT_FOUND.getMessage(String.valueOf(categoryId)) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public void validateRoomExists(final UUID roomId) { | ||
| if (!roomRepository.existsById(roomId)) { | ||
| throw new ResourceNotFoundException( | ||
| ROOM_NOT_FOUND.getMessage(String.valueOf(roomId)) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
77 changes: 77 additions & 0 deletions
77
src/main/java/org/unilab/uniplan/roomcategory/RoomCategoryWebFacade.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,77 @@ | ||
| package org.unilab.uniplan.roomcategory; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.unilab.uniplan.exception.ResourceNotFoundException; | ||
| import org.unilab.uniplan.roomcategory.dto.RoomCategoryRequestDto; | ||
| import org.unilab.uniplan.roomcategory.dto.RoomCategoryResponseDto; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.unilab.uniplan.utils.ErrorConstants.ROOM_CATEGORY_NOT_FOUND; | ||
|
|
||
| @Component | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public class RoomCategoryWebFacade { | ||
|
|
||
| private final RoomCategoryService roomCategoryService; | ||
| private final RoomCategoryMapper roomCategoryMapper; | ||
| private final RoomCategoryValidator roomCategoryValidator; | ||
|
|
||
| private RoomCategory getRoomCategoryOrThrow(final RoomCategoryId id) { | ||
| return roomCategoryService.getById(id) | ||
| .orElseThrow(() -> new ResourceNotFoundException(ROOM_CATEGORY_NOT_FOUND.getMessage( | ||
| String.valueOf(id)))); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void createRoomCategory(final RoomCategoryRequestDto requestDto) { | ||
| roomCategoryValidator.validateForCreate(requestDto); | ||
|
|
||
| final RoomCategory roomCategory = roomCategoryMapper.toEntity(requestDto); | ||
| roomCategoryService.save(roomCategory); | ||
|
|
||
| log.info("created room category with roomId: {} and categoryId: {}", | ||
| requestDto.roomId(), | ||
| requestDto.categoryId()); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<RoomCategoryResponseDto> getAllRoomCategories() { | ||
| return roomCategoryMapper.toResponseDtoList(roomCategoryService.getAll()); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void deleteRoomCategory(final UUID roomId, final UUID categoryId) { | ||
| final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); | ||
| final RoomCategory roomCategory = getRoomCategoryOrThrow(id); | ||
|
|
||
| roomCategoryService.delete(roomCategory); | ||
|
|
||
| log.info("deleted room category with ID: {}", id); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public RoomCategoryResponseDto getRoomCategoryById(final UUID roomId, final UUID categoryId) { | ||
| final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); | ||
| final RoomCategory roomCategory = getRoomCategoryOrThrow(id); | ||
|
|
||
| return roomCategoryMapper.toResponseDto(roomCategory); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void updateRoomCategory(final UUID roomId, final UUID categoryId, final RoomCategoryRequestDto requestDto) { | ||
| final RoomCategoryId id = roomCategoryMapper.toRoomCategoryId(roomId, categoryId); | ||
|
|
||
| roomCategoryValidator.validateForUpdate(id, requestDto); | ||
|
|
||
| final RoomCategory roomCategory = getRoomCategoryOrThrow(id); | ||
| roomCategoryMapper.updateEntity(requestDto, roomCategory); | ||
| roomCategoryService.save(roomCategory); | ||
|
|
||
| log.info("updated room category with ID: {}", roomCategory.getId()); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,8 @@ | |
|
|
||
| public record RoomCategoryResponseDto( | ||
|
|
||
| @NotNull | ||
| UUID roomId, | ||
|
|
||
| @NotNull | ||
| UUID categoryId | ||
| ) { | ||
|
|
||
|
|
||
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.
Implement BaseService. (Could BaseService be generic so it supports both UUID and RoomCategoryId?)
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.
BaseService could be made generic but that would affect all services so I think it should be a separate task