Skip to content

Commit

Permalink
Merge pull request #48 from f-lab-edu/feature/32-search
Browse files Browse the repository at this point in the history
[#32] 공간 검색 기능
  • Loading branch information
hoa0217 authored Mar 3, 2024
2 parents b69aa3e + 409448f commit 6d9bd10
Show file tree
Hide file tree
Showing 41 changed files with 1,611 additions and 890 deletions.
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

0 comments on commit 6d9bd10

Please sign in to comment.