Skip to content

Commit

Permalink
Merge pull request #26 from ese111/feature_24
Browse files Browse the repository at this point in the history
feat: 위치검색기능 구현
  • Loading branch information
KTH-96 committed May 31, 2022
2 parents c3b4449 + 1157266 commit 23a634a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions BE/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
.DS_Store

### STS ###
.apt_generated
Expand Down
5 changes: 4 additions & 1 deletion BE/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.0'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
16 changes: 16 additions & 0 deletions BE/src/main/java/yanse/airbnb/domain/room/RoomRepository.java
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);
}
19 changes: 19 additions & 0 deletions BE/src/main/java/yanse/airbnb/service/SearchService.java
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 BE/src/main/java/yanse/airbnb/web/controller/SearchController.java
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);
}
}
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;
}
3 changes: 1 addition & 2 deletions BE/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

spring:
datasource:
url: ${MYSQL_URL}
Expand All @@ -18,4 +17,4 @@ spring:
# show_sql: true

logging.level:
org.hibernate.SQL: debug
org.hibernate.SQL: debug
14 changes: 13 additions & 1 deletion BE/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ insert into room (city, region, district, detail, price, rating, review_count, r
values ('서울', '강남구', '강남대로62길23', '4층', 10000, 4.8, 187, '룸이라네',
1, 2, 16, 12, 3, '레지던스', '편안하신가요?', 1);

insert into room (city, region, district, detail, price, rating, review_count, room_description,
bathroom_count, bed_count, check_in_time, check_out_time, max_guest, room_type, room_name,
members_id)
values ('서울', '서초구', '강북대로62길23', '4층', 10000, 4.8, 187, '룸이라네',
1, 2, 16, 12, 3, '레지던스', '편안하신가요?', 1);

insert into room (city, region, district, detail, price, rating, review_count, room_description,
bathroom_count, bed_count, check_in_time, check_out_time, max_guest, room_type, room_name,
members_id)
values ('서울', '동구', '강서대로62길23', '4층', 10000, 4.8, 187, '룸이라네',
1, 2, 16, 12, 3, '레지던스', '편안하신가요?', 1);

insert into room_image (url, room_id) values ('url1', 1), ('url2', 1);

insert into reservation (adult_count, child_count, infant_count, check_in_date_time, check_out_date_time,
cleaning_fee, discount_policy, room_tax, service_tax, reservation_price,
members_id, room_id)
values (2, 1, 0, '2022-05-30', '2022-06-01', 10000.0, 'weekly', 10.0, 10.0, 20000, 1, 1);

insert into wish (members_id, room_id) values (1, 1);
insert into wish (members_id, room_id) values (1, 1);

0 comments on commit 23a634a

Please sign in to comment.