Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ repositories {
}

dependencies {
//elasticsearch
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'io.github.cdimascio:java-dotenv:5.2.2'


implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand All @@ -33,13 +37,16 @@ dependencies {
implementation 'org.apache.poi:poi:5.2.3'
implementation 'org.apache.poi:poi-ooxml:5.2.3'


compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' // Swagger

}

tasks.named('test') {
Expand Down Expand Up @@ -68,3 +75,4 @@ dependencies {
annotationProcessor "jakarta.persistence:jakarta.persistence-api:3.1.0"
annotationProcessor "jakarta.annotation:jakarta.annotation-api:2.1.1"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.elasticsearch.elasticsearchengine.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import io.github.cdimascio.dotenv.Dotenv;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Configuration
public class ElasticSearchConfig {

private final Dotenv dotenv = Dotenv.configure().directory("C:/git/elasticSearchEngine/docker-elk").load();

@Bean
public ElasticsearchClient elasticsearchClient() {
String username = "elastic";
String password = dotenv.get("ELASTIC_PASSWORD");

RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
.setDefaultHeaders(new Header[]{
new BasicHeader("Authorization", basicAuthHeader(username, password))
})
.build();

ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper());

return new ElasticsearchClient(transport);
}

private String basicAuthHeader(String username, String password) {
String auth = username + ":" + password;
return "Basic " + Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.elasticsearch.elasticsearchengine.controller;

import com.elasticsearch.elasticsearchengine.common.CommonResponse;
import com.elasticsearch.elasticsearchengine.dto.ExcelSaveTourListResponseDto;
import com.elasticsearch.elasticsearchengine.dto.TourListResponseDto;
import com.elasticsearch.elasticsearchengine.dto.TourListRequestDto;
import com.elasticsearch.elasticsearchengine.service.TourService;
import com.elasticsearch.elasticsearchengine.vo.ExcelSaveTourListResponseVo;
import com.elasticsearch.elasticsearchengine.vo.TourListResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static com.elasticsearch.elasticsearchengine.common.BaseResponseStatus.INTERNAL_SERVER_ERROR;
Expand All @@ -38,8 +37,7 @@ public CommonResponse<ExcelSaveTourListResponseVo> excelSaveTourList(
) MultipartFile file
) {
try {
ExcelSaveTourListResponseDto responseDto = tourService.excelSaveTourList(file);
ExcelSaveTourListResponseVo responseVo = ExcelSaveTourListResponseVo.dtoToVo(responseDto);
ExcelSaveTourListResponseVo responseVo = tourService.excelSaveTourList(file);
return CommonResponse.success("관광정보가 성공적으로 등록되었습니다.", responseVo);
} catch (IOException e) {
return CommonResponse.fail(INTERNAL_SERVER_ERROR, "파일 처리 중 오류가 발생했습니다.");
Expand All @@ -49,32 +47,26 @@ public CommonResponse<ExcelSaveTourListResponseVo> excelSaveTourList(

@GetMapping(value = "/find")
@Operation(summary = "관광 정보 조회", description = "페이지 번호, 관광 타입 번호, 시군구코드, 서브 카테고리, 태그를 기준으로 관광 정보를 조회합니다.")
@Parameters({
@Parameter(name = "page", description = "페이지 번호, 기본 값 : 1"),
@Parameter(name = "contentTypeId", description = "관광 타입 번호"),
@Parameter(name = "sigunguCode", description = "시군구코드"),
@Parameter(name = "sideCategory", description = "서브 카테고리"),
@Parameter(name = "tags", description = "태그"),
})
public CommonResponse<TourListResponseVo> findTourList(
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "contentTypeId") String contentTypeId,
@RequestParam(name = "sigunguCode", required = false) String sigunguCode,
@RequestParam(name = "sideCategory", required = false) String sideCategory,
@RequestParam(name = "tags", required = false) List<String> tags
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "검색 조건 및 페이징 정보")
TourListRequestDto tourListRequestDto
) {
Page<TourListResponseDto> TourListPage = tourService.findByMultiCode(page, contentTypeId, sigunguCode, sideCategory, tags);
Pageable pageable = PageRequest.of(tourListRequestDto.getPage(), tourListRequestDto.getSize());

if (TourListPage.isEmpty()) {
return CommonResponse.success("관광 정보", TourListResponseVo.builder()
.totalList(0)
.currentPage(page)
.totalPages(0)
.tourListDto(null)
.build());
}
List<String> tagList = tourListRequestDto.getTags() != null
? Arrays.stream(tourListRequestDto.getTags().split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.toList()
: List.of();

TourListResponseVo tourListResponseVo = tourService.findByMultiCode(
tourListRequestDto.getContentTypeId(),
tourListRequestDto.getSigunguCode(),
tourListRequestDto.getCategory(),
tagList,
pageable);

return CommonResponse.success("관광 정보",
TourListResponseVo.dtoToVo(TourListPage.getContent().get(0)));
return CommonResponse.success("관광 정보", tourListResponseVo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.elasticsearch.elasticsearchengine.controller;

import com.elasticsearch.elasticsearchengine.common.CommonResponse;
import com.elasticsearch.elasticsearchengine.dto.TourListRequestDto;
import com.elasticsearch.elasticsearchengine.service.TourElasticSearchService;
import com.elasticsearch.elasticsearchengine.vo.TourListDetailResponseVo;
import com.elasticsearch.elasticsearchengine.vo.TourListResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("tour_E")
@Tag(name = "tour_elasticSearch_controller", description = "관광정보관리시스템 ver.elasticSearch")
public class TourElasticSearchController {

private final TourElasticSearchService tourElasticSearchService;

@GetMapping(value = "/find")
@Operation(summary = "관광 정보 조회", description = "페이지 번호, 관광 타입 번호, 시군구코드, 서브 카테고리, 태그를 기준으로 관광 정보를 조회합니다.")
public CommonResponse<TourListResponseVo> searchTourWithPasing(
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "검색 조건 및 페이징 정보")
TourListRequestDto tourListRequestDto
) {
Pageable pageable = PageRequest.of(tourListRequestDto.getPage(), tourListRequestDto.getSize());

List<String> tagList = tourListRequestDto.getTags() != null
? Arrays.stream(tourListRequestDto.getTags().split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.toList()
: List.of();

TourListResponseVo tourListResponseVo = tourElasticSearchService.searchTourWithPasing(
tourListRequestDto.getContentTypeId(),
tourListRequestDto.getTitle(),
tourListRequestDto.getSigunguCode(),
tourListRequestDto.getCategory(),
tagList,
tourListRequestDto.getSort(),
pageable);

return CommonResponse.success("관광 정보", tourListResponseVo);
}

@GetMapping(value = "/find/detail")
@Operation(summary = "관광 정보 상세 조회", description = "콘텐츠 고유 번호를 기준으로 관광 정보를 상세 조회합니다.")
public CommonResponse<TourListDetailResponseVo> findByContentId(
@Parameter(description = "콘텐츠 고유 번호")
int contentId
) {
TourListDetailResponseVo tourListDetailResponseVo = tourElasticSearchService.findByContentId(contentId);

return CommonResponse.success("관광 정보", tourListDetailResponseVo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.elasticsearch.elasticsearchengine.domain;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;
import java.util.List;

@Document(indexName = "tourist_attraction_index")
@Data
public class TourAttractionDocument {

@Id
@Field(name = "content_id", type = FieldType.Integer)
private int contentId;

@Field(name = "content_type_id")
private String contentTypeId;

@Field(name = "title")
private String title;

@Field(name = "sigungu_code")
private String sigunguCode;

private String category;

private List<String> tags;

@Field(name = "title_sort", type = FieldType.Keyword)
private String title_sort;

private String addr;

private String thumbnail;

@Field(name = "created_time")
private LocalDateTime createdTime;

@Field(name = "modified_time")
private LocalDateTime modifiedTime;

private String overview;

private String homepage;

private String infocenter;

private String opendate;

private String restdate;

private String expguide;

private String expagerange;

private String accomcount;

private String useseason;

private String usetime;

private String parking;

private double mapx;

private double mapy;

@Field(name = "area_code")
private String areaCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "tour")
public class Tour {
@Entity(name = "tourist_attraction")
public class TouristAttreaction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -22,27 +22,49 @@ public class Tour {

private String title;

private String sigunguCode;

private String category;

private String tags;

private String addr;

private String zipCode;
private String thumbnail;

private String areaCode;
private LocalDate createdTime;

private String sigunguCode;
private LocalDate modifiedTime;

private String category;
@Column(columnDefinition = "text")
private String overview;

private String sideCategory;
@Column(columnDefinition = "text")
private String homepage;

private String tags;
private String infocenter;

private String thumbnail;
private String opendate;

private String restdate;

@Column(columnDefinition = "text")
private String expguide;

private String expagerange;

private String accomcount;

private String useseason;

@Column(columnDefinition = "text")
private String usetime;

private String parking;

private double mapx;

private double mapy;

private LocalDate createdTime;

private LocalDate modifiedTime;
private String areaCode;
}

This file was deleted.

Loading