-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/search #10 #30
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
bnminji
wants to merge
6
commits into
prgrms-be-devcourse:develop
Choose a base branch
from
bnminji:feature/search-#10
base: develop
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
6 commits
Select commit
Hold shift + click to select a range
f2e013c
git commit -m "Feat: RoomResponse(All,One), SearchService(+Test), Sea…
bnminji f893070
git commit -m "Feat: SearchService::findByFilters(+Test) 구현"
bnminji b1e6036
git commit -m "Feat: QueryDSL dependency 및 plugin 추가"
bnminji 168d026
git commit -m "Feat: SearchController(+Test) 구현"
bnminji ad6862e
git commit -m "Refactor: SearchRequest 수정"
bnminji 641e720
git commit -m "Refactor: SearchService, SearchController 수정"
bnminji 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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/programmers/staybb/Controller/User/HostController.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
36 changes: 36 additions & 0 deletions
36
src/main/java/org/programmers/staybb/Controller/search/SearchController.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,36 @@ | ||
| package org.programmers.staybb.controller.search; | ||
|
|
||
| import javassist.NotFoundException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.programmers.staybb.dto.search.SearchAllResponse; | ||
| import org.programmers.staybb.dto.search.SearchOneResponse; | ||
| import org.programmers.staybb.dto.search.SearchRequest; | ||
| import org.programmers.staybb.dto.search.SearchRequestModel; | ||
| import org.programmers.staybb.service.SearchService; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.ModelAttribute; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| public class SearchController { | ||
| private final SearchService searchService; | ||
| public SearchController(SearchService searchService) { | ||
| this.searchService = searchService; | ||
| } | ||
|
|
||
| @GetMapping("/v1/search") | ||
| public ResponseEntity<Page<SearchAllResponse>> getAll(final @ModelAttribute SearchRequestModel searchRequestModel, Pageable pageable) { | ||
| SearchRequest searchRequest = new SearchRequest(searchRequestModel); | ||
| return ResponseEntity.ok(searchService.findByFilters(searchRequest, pageable)); | ||
| } | ||
|
|
||
| @GetMapping("/v1/search/rooms/{roomId}") | ||
| public ResponseEntity<SearchOneResponse> getOne(final @PathVariable Long roomId) throws NotFoundException { | ||
| return ResponseEntity.ok(searchService.findOne(roomId)); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/programmers/staybb/configuration/QueryDSLConfig.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,18 @@ | ||
| package org.programmers.staybb.configuration; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import javax.persistence.EntityManager; | ||
| import javax.persistence.PersistenceContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class QueryDSLConfig { | ||
| @PersistenceContext | ||
| private EntityManager entityManager; | ||
|
|
||
| @Bean | ||
| public JPAQueryFactory jpaQueryFactory() { | ||
| return new JPAQueryFactory(entityManager); | ||
| } | ||
| } |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/org/programmers/staybb/dto/search/SearchAllResponse.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,28 @@ | ||
| package org.programmers.staybb.dto.search; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import org.programmers.staybb.domain.room.Address; | ||
| import org.programmers.staybb.domain.room.Option; | ||
| import org.programmers.staybb.domain.room.Room; | ||
|
|
||
|
|
||
| @Getter | ||
| public class SearchAllResponse { | ||
|
|
||
| private Long id; | ||
| private String roomName; | ||
| private int maxGuest; | ||
|
|
||
| private Option option; | ||
| private String region; | ||
|
|
||
| @Builder | ||
| public SearchAllResponse(Room entity) { | ||
| this.id = entity.getId(); | ||
| this.roomName = entity.getRoomName(); | ||
| this.maxGuest = entity.getMaxGuest(); | ||
| this.option = entity.getOption(); | ||
| this.region = entity.getAddress().getRegion(); | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/programmers/staybb/dto/search/SearchOneResponse.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,38 @@ | ||
| package org.programmers.staybb.dto.search; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import java.time.LocalDate; | ||
| import javax.validation.constraints.Email; | ||
| import javax.validation.constraints.NotBlank; | ||
| import javax.validation.constraints.NotEmpty; | ||
| import javax.validation.constraints.NotNull; | ||
| import javax.validation.constraints.Past; | ||
| import javax.validation.constraints.Pattern; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import org.programmers.staybb.domain.room.Address; | ||
| import org.programmers.staybb.domain.room.Option; | ||
| import org.programmers.staybb.domain.room.Room; | ||
|
|
||
|
|
||
| @Getter | ||
| public class SearchOneResponse { | ||
|
|
||
| private Long id; | ||
| private String roomName; | ||
| private int maxGuest; | ||
| private String description; | ||
|
|
||
| private Option option; | ||
| private String roughAddress; | ||
|
|
||
| @Builder | ||
| public SearchOneResponse(Room entity) { | ||
| this.id = entity.getId(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. id는 필요없지 않을까요? |
||
| this.roomName = entity.getRoomName(); | ||
| this.maxGuest = entity.getMaxGuest(); | ||
| this.description = entity.getDescription(); | ||
| this.option = entity.getOption(); | ||
| this.roughAddress = entity.getAddress().getAddress(); | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
src/main/java/org/programmers/staybb/dto/search/SearchRequest.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,43 @@ | ||
| package org.programmers.staybb.dto.search; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import java.time.LocalDate; | ||
| import javax.validation.constraints.Past; | ||
| import javax.validation.constraints.PositiveOrZero; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.apache.tomcat.jni.Local; | ||
| import org.programmers.staybb.domain.reservation.Guest; | ||
| import org.programmers.staybb.domain.room.Option; | ||
| import org.programmers.staybb.domain.room.Room; | ||
|
|
||
| @Getter | ||
| @Setter | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setter도 필요한가요? |
||
| public class SearchRequest { | ||
|
|
||
| private String location; | ||
| @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") | ||
| @Past(message = "현재보다 이전인 날짜를 전달받았습니다.") | ||
| private LocalDate startDate; | ||
| @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") | ||
| @Past(message = "현재보다 이전인 날짜를 전달받았습니다.") | ||
| private LocalDate endDate; | ||
| private Guest guest; | ||
| private Option option; | ||
|
|
||
| public SearchRequest(SearchRequestModel searchRequestModel) { | ||
| this.location = searchRequestModel.getLocation(); | ||
| this.startDate = LocalDate.parse(searchRequestModel.getStartDate()); | ||
| this.endDate = LocalDate.parse(searchRequestModel.getEndDate()); | ||
| this.guest = new Guest( | ||
| searchRequestModel.getAdult(), | ||
| searchRequestModel.getKid(), | ||
| searchRequestModel.getTeen()); | ||
| this.option = Option.builder() | ||
| .bedNum(searchRequestModel.getBedNum()) | ||
| .bedroomNum(searchRequestModel.getBedroomNum()) | ||
| .bathroomNum(searchRequestModel.getBathroomNum()) | ||
| .build(); | ||
| } | ||
| } | ||
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.
Respose의 convert해주는 과정에서 생성자보다 static으로 선언한 of 메소드를 해주는 것이 좀 더 명확한 느낌아닌 느낌이 들어요 ㅎㅎ
어떻게 생각하시나요??