Skip to content
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

[#32] 공간 검색 기능 #48

Merged
merged 23 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8a90456
refactor: address 구조 변경
hoa0217 Feb 13, 2024
8f34a7c
fix: roadAddress null 개선
hoa0217 Feb 15, 2024
d826178
chore: elastic search 설정
hoa0217 Feb 15, 2024
0d3d634
feature: query 검색 개발
hoa0217 Feb 15, 2024
c93b87e
feature: 쿼리를 사용한 검색을 구현한다.
hoa0217 Feb 20, 2024
c187cd7
fix: 날짜 형변환 수정
hoa0217 Feb 20, 2024
e2707be
fix: like검색에 필요한 % 추가
hoa0217 Feb 20, 2024
68378ee
fix: QueryParam형식으로 요청을 받을 경우 생성자를 타지 않아 timeRange가 null이 됨.
hoa0217 Feb 20, 2024
d06c1cf
refactor: 주소검색추가
hoa0217 Feb 21, 2024
a480498
refactor: 공간상세조회추가
hoa0217 Feb 21, 2024
79ee9ab
refactor: description column length 지정
hoa0217 Feb 26, 2024
7e5452a
refactor: elastic search 비밀번호 지정
hoa0217 Feb 26, 2024
8a727c9
refactor: elasticsearch, query-search 분리
hoa0217 Feb 26, 2024
c7ff268
chore: elasticsearch Testcontainer 설정
hoa0217 Feb 28, 2024
e46aad1
chore: elasticsearch Testcontainer 설정
hoa0217 Feb 28, 2024
3b84d76
chore: TestContainer용 SpaceIndex레파지토리
hoa0217 Feb 28, 2024
ec2c052
test: SpaceIndexQueryRepository Test
hoa0217 Feb 28, 2024
fb4bb16
test: SpaceQueryRepository(검색) Test
hoa0217 Feb 28, 2024
57bb6cc
test: SpaceServiceTest 수정
hoa0217 Mar 1, 2024
afc3dec
chore: SingletoneTestContainer 설정 (Redis, RabbitMQ)
hoa0217 Mar 3, 2024
d89727b
test: 통합테스트 시 AbstractIntegrationContainerBaseTest를 상속하도록 수정한다.
hoa0217 Mar 3, 2024
ced0138
style: 코드 스타일 및 import 문 정리
hoa0217 Mar 3, 2024
409448f
fix: count query 버그 수정
hoa0217 Mar 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ dependencies {
// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'
implementation 'it.ozimov:embedded-redis:0.7.2'

//queryDsl
// Elastic Search
implementation 'org.springframework.data:spring-data-elasticsearch'

// QueryDsl
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
implementation "com.querydsl:querydsl-apt:${queryDslVersion}"
implementation 'org.jetbrains:annotations:24.0.0'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation "org.testcontainers:elasticsearch:1.19.6"
testImplementation "org.testcontainers:rabbitmq:1.19.6"

// Database
runtimeOnly 'com.h2database:h2'
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/modoospace/ModoospaceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@SpringBootApplication
public class ModoospaceApplication {

public static void main(String[] args) {
SpringApplication.run(ModoospaceApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(ModoospaceApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.modoospace.config.elacticsearch;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {

@Value("${spring.elasticsearch.host}")
private String host;
@Value("${spring.elasticsearch.port}")
private int port;
@Value("${spring.elasticsearch.username}")
private String username;
@Value("${spring.elasticsearch.password}")
private String password;

@Override
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(host + ":" + port)
.withBasicAuth(username, password)
.build();

return RestClients.create(clientConfiguration).rest();
}
}
36 changes: 0 additions & 36 deletions src/main/java/com/modoospace/config/redis/EmbeddedRedisConfig.java

This file was deleted.

This file was deleted.

14 changes: 12 additions & 2 deletions src/main/java/com/modoospace/space/controller/SpaceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.modoospace.config.auth.LoginEmail;
import com.modoospace.space.controller.dto.space.SpaceCreateUpdateRequest;
import com.modoospace.space.controller.dto.space.SpaceDetailResponse;
import com.modoospace.space.controller.dto.space.SpaceResponse;
import com.modoospace.space.controller.dto.space.SpaceSearchRequest;
import com.modoospace.space.sevice.SpaceService;
Expand Down Expand Up @@ -38,13 +39,22 @@ public ResponseEntity<Void> create(@PathVariable Long categoryId,
@GetMapping()
public ResponseEntity<Page<SpaceResponse>> search(SpaceSearchRequest searchRequest,
Pageable pageable) {
searchRequest.updateTimeRange();
Page<SpaceResponse> spaces = spaceService.searchSpace(searchRequest, pageable);
return ResponseEntity.ok().body(spaces);
}

@GetMapping("/query")
public ResponseEntity<Page<SpaceResponse>> searchQuery(SpaceSearchRequest searchRequest,
Pageable pageable) {
searchRequest.updateTimeRange();
Page<SpaceResponse> spaces = spaceService.searchSpaceQuery(searchRequest, pageable);
return ResponseEntity.ok().body(spaces);
}

@GetMapping("/{spaceId}")
public ResponseEntity<SpaceResponse> find(@PathVariable Long spaceId) {
SpaceResponse space = spaceService.findSpace(spaceId);
public ResponseEntity<SpaceDetailResponse> find(@PathVariable Long spaceId) {
SpaceDetailResponse space = spaceService.findSpace(spaceId);
return ResponseEntity.ok().body(space);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.modoospace.space.controller.dto.address;

import com.modoospace.space.domain.Address;
import javax.validation.constraints.NotEmpty;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class AddressCreateUpdateRequest {

@NotEmpty
private String depthFirst; // 시도

@NotEmpty
private String depthSecond; // 구

@NotEmpty
private String depthThird; // 동

@NotEmpty
private String addressNo; // 지번

@NotEmpty
private String roadName; // 도로명

@NotEmpty
private String buildingNo; // 건물번호

private String detailAddress; // 나머지 주소

private String x; // 경도

private String y; // 위도

@Builder
public AddressCreateUpdateRequest(String depthFirst, String depthSecond, String depthThird,
String addressNo, String roadName, String buildingNo, String detailAddress, String x,
String y) {
this.depthFirst = depthFirst;
this.depthSecond = depthSecond;
this.depthThird = depthThird;
this.addressNo = addressNo;
this.roadName = roadName;
this.buildingNo = buildingNo;
this.detailAddress = detailAddress;
this.x = x;
this.y = y;
}

public Address toEntity() {
return Address.builder()
.depthFirst(depthFirst)
.depthSecond(depthSecond)
.depthThird(depthThird)
.addressNo(addressNo)
.roadName(roadName)
.buildingNo(buildingNo)
.detailAddress(detailAddress)
.x(x)
.y(y)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.modoospace.space.controller.dto.address;

import com.modoospace.space.domain.Address;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class AddressResponse {

private String depthFirst; // 시도
private String depthSecond; // 구
private String depthThird; // 동
private String noAddress; // 지번주소
private String roadAddress; // 도로명주소

@Builder
public AddressResponse(String depthFirst, String depthSecond, String depthThird,
String noAddress,
String roadAddress) {
this.depthFirst = depthFirst;
this.depthSecond = depthSecond;
this.depthThird = depthThird;
this.noAddress = noAddress;
this.roadAddress = roadAddress;
}

public static AddressResponse of(Address address) {
return AddressResponse.builder()
.depthFirst(address.getDepthFirst())
.depthSecond(address.getDepthSecond())
.depthThird(address.getDepthThird())
.noAddress(getNoAddress(address))
.roadAddress(getRoadAddress(address))
.build();
}

private static String getNoAddress(Address address) {
return address.getDepthFirst() + " " + address.getDepthSecond() + " "
+ address.getDepthThird() + " " + address.getAddressNo() + " "
+ address.getDetailAddress();
}

private static String getRoadAddress(Address address) {
return address.getDepthFirst() + " " + address.getDepthSecond() + " "
+ address.getRoadName() + " " + address.getBuildingNo() + " "
+ address.getDetailAddress();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.modoospace.space.controller.dto.facility;

import com.modoospace.space.controller.dto.timeSetting.TimeSettingResponse;
import com.modoospace.space.controller.dto.weekdaySetting.WeekdaySettingResponse;
import com.modoospace.space.domain.Facility;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.Builder;
Expand Down Expand Up @@ -28,16 +32,26 @@ public class FacilityResponse {

private String description;

@NotEmpty
private List<TimeSettingResponse> timeSettings;

@NotEmpty
private List<WeekdaySettingResponse> weekdaySettings;

@Builder
public FacilityResponse(Long id, String name, Boolean reservationEnable,
Integer minUser, Integer maxUser, String description) {
public FacilityResponse(Long id, String name, Boolean reservationEnable, Integer minUser,
Integer maxUser, String description, List<TimeSettingResponse> timeSettings,
List<WeekdaySettingResponse> weekdaySettings) {
this.id = id;
this.name = name;
this.reservationEnable = reservationEnable;

this.minUser = minUser;
this.maxUser = maxUser;
this.description = description;

this.timeSettings = timeSettings;
this.weekdaySettings = weekdaySettings;
}

public static FacilityResponse of(Facility facility) {
Expand All @@ -48,6 +62,16 @@ public static FacilityResponse of(Facility facility) {
.minUser(facility.getMinUser())
.maxUser(facility.getMaxUser())
.description(facility.getDescription())
.timeSettings(TimeSettingResponse
.of(facility.getTimeSettings().getTimeSettings()))
.weekdaySettings(WeekdaySettingResponse
.of(facility.getWeekdaySettings().getWeekdaySettings()))
.build();
}

public static List<FacilityResponse> of(List<Facility> facilities) {
return facilities.stream()
.map(FacilityResponse::of)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.modoospace.space.controller.dto.space;

import com.modoospace.member.domain.Member;
import com.modoospace.space.domain.Address;
import com.modoospace.space.controller.dto.address.AddressCreateUpdateRequest;
import com.modoospace.space.domain.Category;
import com.modoospace.space.domain.Space;
import javax.validation.constraints.NotEmpty;
Expand All @@ -19,9 +19,10 @@ public class SpaceCreateUpdateRequest {
private String description;

@NotNull
private Address address;
private AddressCreateUpdateRequest address;

public SpaceCreateUpdateRequest(String name, String description, Address address) {
public SpaceCreateUpdateRequest(String name, String description,
AddressCreateUpdateRequest address) {
this.name = name;
this.description = description;
this.address = address;
Expand All @@ -31,7 +32,7 @@ public Space toEntity(Category category, Member host) {
return Space.builder()
.name(name)
.description(description)
.address(address)
.address(address.toEntity())
.category(category)
.host(host)
.build();
Expand Down
Loading
Loading