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

Hubobe 24 be 검색 #13

Merged
merged 14 commits into from
Jul 23, 2024
2 changes: 1 addition & 1 deletion BE-hubo-gillajabi-resources
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ dependencies {
// https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.754'

implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'


implementation 'org.springframework.boot:spring-boot-starter-batch'

// // https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa
// implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
// annotationProcessor "com.querydsl:querydsl-apt:5.1.0:jakarta"
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/hubo/gillajabi/HuboApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableJpaAuditing
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableScheduling
public class HuboApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.hubo.gillajabi.admin.application.presenation;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

//TODO
@RestController
@RequestMapping("/api/admin/search")
@RequiredArgsConstructor
@Tag(name = "adminSearch", description = "관리자 검색 API")
public class AdminSearchController {

private final Job courseSearchJob;
private final JobLauncher jobLauncher;

@Operation(summary = "검색 인덱싱", description = "검색 인덱싱을 수행합니다.")
@PostMapping("/indexing")
public ResponseEntity<String> runSearchIndexing() {
try {
JobParameters parameters = new JobParametersBuilder()
.addDate("date", new Date())
.toJobParameters();
jobLauncher.run(courseSearchJob, parameters);
return ResponseEntity.ok("검색 인덱싱이 성공적으로 시작되었습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("검색 인덱싱 시작 실패: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.hubo.gillajabi.city.domain.entity;

import com.hubo.gillajabi.crawl.domain.constant.Province;
import com.hubo.gillajabi.crawl.domain.entity.Course;
import com.hubo.gillajabi.crawl.infrastructure.dto.request.CityRequest;
import jakarta.persistence.*;
import lombok.*;

import java.util.Set;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -35,8 +38,11 @@ public class City {
@Column(length = 8)
private String cityCode;

@OneToMany(mappedBy = "city", fetch = FetchType.LAZY)
private Set<Course> courses;

public static City createCity(final CityRequest cityRequest) {
return new City(null, cityRequest.getName(), cityRequest.getProvince(), cityRequest.getDescription(),null
,null,null);
,null,null,null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ public static Province fromValue(String value) {
}
throw new IllegalArgumentException("해당 지역명이 enum에 없습니다. " + value);
}
}

public boolean isBigCity() {
return switch (this) {
case SEOUL, BUSAN, DAEGU, INCHEON, GWANGJU, DAEJEON, ULSAN, SEJONG -> true;
default -> false;
};
}}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ public class Course extends BaseEntity {
@Column(length = 40)
private String courseNumber;

@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) // TODO : eager로 설정 : courseDetail을 조회할 때마다 조회 다른 도메인에서 Course 엔티티에 대해 재정의 할것
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
// TODO : eager로 설정 : courseDetail을 조회할 때마다 조회 다른 도메인에서 Course 엔티티에 대해 재정의 할것
@JoinColumn(name = "detail_id", unique = true)
private CourseDetail courseDetail;

@OneToMany(mappedBy = "course", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<CourseSection> courseSections;

@OneToMany(mappedBy = "course", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<CourseTag> courseTags;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "theme_id")
private CourseTheme courseTheme;
Expand All @@ -61,7 +59,7 @@ public class Course extends BaseEntity {
public static Course createCourse(final CourseRequest request) {
return new Course(null, request.getCourseName(), request.getDistance(), request.getTotalRequiredHours(),
request.getLevel(), request.getShortDescription(), request.getCourseNumber(),
null, null, null, request.getCourseTheme(), request.getCity());
null, null, request.getCourseTheme(), request.getCity());
}

public boolean checkUpdate(final CourseRequest request) {
Expand Down Expand Up @@ -115,7 +113,7 @@ public void update(final CourseRequest request) {


public void addCourseDetail(CourseDetail existingDetail) {
this.courseDetail =existingDetail;
this.courseDetail = existingDetail;
}

public void addCourseSection(CourseSection courseSection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public class CourseTag {
private String name;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id")
private Course course;
@JoinColumn(name = "course_theme_id")
private CourseTheme courseTheme;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "section_id")
private CourseSection courseSection;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.persistence.*;
import lombok.*;

import java.util.List;
import java.util.Objects;

@Entity
Expand All @@ -28,8 +29,11 @@ public class CourseTheme extends BaseEntity {
@Column(columnDefinition = "TEXT")
private String description;

@OneToMany(mappedBy = "courseTheme", fetch = FetchType.LAZY)
private List<CourseTag> courseTags;

public static CourseTheme createCourseTheme(CourseThemeRequest requestDTO) {
return new CourseTheme(null, requestDTO.getName(), requestDTO.getShortDescription(), requestDTO.getDescription());
return new CourseTheme(null, requestDTO.getName(), requestDTO.getShortDescription(), requestDTO.getDescription(),null);
}

public void update(CourseThemeRequest requestDTO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hubo.gillajabi.crawl.infrastructure.persistence;

import org.springframework.data.jpa.repository.JpaRepository;
import com.hubo.gillajabi.crawl.domain.entity.CourseTag;

public interface CourseTagRepository extends JpaRepository<CourseTag, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@Setter
public class PageInfo {
private int totalPages;
private int totalElements;
private long totalElements;
private int size;
private int number;

public PageInfo(int totalPages, int totalElements, int size, int number) {
public PageInfo(int totalPages, long totalElements, int size, int number) {
this.totalPages = totalPages;
this.totalElements = totalElements;
this.size = size;
Expand All @@ -22,7 +22,7 @@ public PageInfo(int totalPages, int totalElements, int size, int number) {
public static PageInfo from(Page<?> page) {
return new PageInfo(
page.getTotalPages(),
(int) page.getTotalElements(),
page.getTotalElements(),
page.getSize(),
page.getNumber()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hubo.gillajabi.search.application.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SearchCityInfoDTO {
private Long id;
private String name;
private String province;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hubo.gillajabi.search.application.dto;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class SearchResultDTO {
private String id;
private SearchCityInfoDTO city;
private List<String> images;
private List<SearchThemeInfoDTO> themes;
private SearchWeatherInfoDTO weather;
private SearchThemeInfoDTO theme; // 테마 기반 검색 결과일 때 사용
private List<String> tags; // 테마 기반 검색 결과일 때 사용
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hubo.gillajabi.search.application.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SearchThemeInfoDTO {
private Long id;
private String name;
private String shortDescription;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hubo.gillajabi.search.application.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SearchWeatherInfoDTO {

private Float lowestTemperature;

private Float highestTemperature;

private String condition;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hubo.gillajabi.search.application.dto.response;

import com.hubo.gillajabi.search.application.dto.SearchResultDTO;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class SearchResponse {
private List<SearchResultDTO> results;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hubo.gillajabi.search.application.resolver;

import com.hubo.gillajabi.search.application.dto.response.SearchResponse;
import com.hubo.gillajabi.search.domain.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;

@Controller
@RequiredArgsConstructor
public class SearchResolver {

private final SearchService searchService;

@QueryMapping
public SearchResponse searchCourseByKeyword(@Argument String keyword) {
return searchService.searchByKeyword(keyword);
}
}
Loading
Loading