-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 주소안에 같은 글자를 가진 방들을 검색해 가져옵니다. closes#24
- Loading branch information
Showing
8 changed files
with
93 additions
and
4 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
16 changes: 16 additions & 0 deletions
16
BE/src/main/java/yanse/airbnb/domain/room/RoomRepository.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 yanse.airbnb.domain.room; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import yanse.airbnb.web.dto.ResponseSearchAddressDto; | ||
|
||
public interface RoomRepository extends JpaRepository<Room, Long> { | ||
|
||
@Query("select new yanse.airbnb.web.dto.ResponseSearchAddressDto" | ||
+ "(concat(r.address.city, ' ' ,r.address.region, ' ' ,r.address.district, r.address.detail)) from Room r " | ||
+ "where r.address.city like %:address% or r.address.region like %:address% " | ||
+ "or r.address.district like %:address% or r.address.detail like %:address%") | ||
List<ResponseSearchAddressDto> findByAddress(@Param("address") String address); | ||
} |
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,19 @@ | ||
package yanse.airbnb.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import yanse.airbnb.domain.room.RoomRepository; | ||
import yanse.airbnb.web.dto.ResponseSearchAddressDto; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class SearchService { | ||
|
||
private final RoomRepository roomRepository; | ||
public List<ResponseSearchAddressDto> findAddress(String address) { | ||
return roomRepository.findByAddress(address); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
BE/src/main/java/yanse/airbnb/web/controller/SearchController.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,23 @@ | ||
package yanse.airbnb.web.controller; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import yanse.airbnb.service.SearchService; | ||
import yanse.airbnb.web.dto.ResponseSearchAddressDto; | ||
|
||
@RequestMapping("/search") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class SearchController { | ||
|
||
private final SearchService searchService; | ||
|
||
@GetMapping | ||
public List<ResponseSearchAddressDto> searchAddress(@RequestParam String address) { | ||
return searchService.findAddress(address); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
BE/src/main/java/yanse/airbnb/web/dto/ResponseSearchAddressDto.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 yanse.airbnb.web.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ResponseSearchAddressDto { | ||
|
||
private String address; | ||
} |
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