-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ feat(api): add search term recommend (#327)
* ♻️ feat(api): add search term recommend * ✨ feat(api) : add textcolor vo and dto * 🐛 fix(api) : add api to text color dto * ♻️ chore(admin): fix to var * ♻️ chore(admin): fix to builder pattern * ♻️ chore(admin): fix to protected
- Loading branch information
1 parent
b830d26
commit 4da3c11
Showing
15 changed files
with
269 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ain/java/com/depromeet/domains/recommend/search/controller/SearchRecommendController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.depromeet.domains.recommend.search.controller; | ||
|
||
import com.depromeet.domains.recommend.search.dto.CreateSearchRecommendDto; | ||
import com.depromeet.domains.recommend.search.service.SearchRecommendService; | ||
import com.depromeet.domains.user.dto.ResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/search-term/recommend") | ||
@RequiredArgsConstructor | ||
public class SearchRecommendController { | ||
|
||
private final SearchRecommendService searchRecommendService; | ||
@PostMapping | ||
public ResponseEntity<Integer> addRecommendSearchTerm( | ||
@RequestBody CreateSearchRecommendDto createSearchRecommendDto | ||
) { | ||
var response = searchRecommendService.createSearchRecommendTerm(createSearchRecommendDto); | ||
return ResponseDto.created(response); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...er/src/main/java/com/depromeet/domains/recommend/search/dto/CreateSearchRecommendDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.depromeet.domains.recommend.search.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
public class CreateSearchRecommendDto { | ||
private String title; | ||
private List<TextColorDto> description; | ||
private List<TextColorDto> terms; | ||
} |
15 changes: 15 additions & 0 deletions
15
...p-admin-server/src/main/java/com/depromeet/domains/recommend/search/dto/TextColorDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.depromeet.domains.recommend.search.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class TextColorDto { | ||
private String text; | ||
private String color; | ||
} |
7 changes: 7 additions & 0 deletions
7
...java/com/depromeet/domains/recommend/search/repository/SearchRecommendTermRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.depromeet.domains.recommend.search.repository; | ||
|
||
import com.depromeet.recommend.search.SearchRecommendTerm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SearchRecommendTermRepository extends JpaRepository<SearchRecommendTerm, Long> { | ||
} |
29 changes: 29 additions & 0 deletions
29
.../src/main/java/com/depromeet/domains/recommend/search/service/SearchRecommendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.depromeet.domains.recommend.search.service; | ||
|
||
import com.depromeet.domains.recommend.search.dto.CreateSearchRecommendDto; | ||
import com.depromeet.domains.recommend.search.repository.SearchRecommendTermRepository; | ||
import com.depromeet.recommend.search.SearchRecommendTerm; | ||
import com.depromeet.recommend.search.TextColorVo; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SearchRecommendService { | ||
private final SearchRecommendTermRepository searchRecommendTermRepository; | ||
|
||
@Transactional | ||
public int createSearchRecommendTerm(CreateSearchRecommendDto createSearchRecommendDto) { | ||
var title = createSearchRecommendDto.getTitle(); | ||
var description = createSearchRecommendDto.getDescription().stream() | ||
.map(textColorDto -> new TextColorVo(textColorDto.getText(), textColorDto.getColor())) | ||
.toList(); | ||
var terms = createSearchRecommendDto.getTerms().stream() | ||
.map(textColorDto -> new TextColorVo(textColorDto.getText(), textColorDto.getColor())) | ||
.toList(); | ||
var searchRecommendTerm = SearchRecommendTerm.builder().title(title).description(description).terms(terms).build(); | ||
var result = searchRecommendTermRepository.save(searchRecommendTerm); | ||
return result.getId().intValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...i/src/main/java/com/depromeet/domains/recommend/controller/SearchRecommendController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.depromeet.domains.recommend.controller; | ||
|
||
import com.depromeet.common.dto.ResponseDto; | ||
import com.depromeet.domains.recommend.dto.response.SearchTermRecommendResponseDto; | ||
import com.depromeet.domains.recommend.service.SearchRecommendService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/search-term/recommend") | ||
@RequiredArgsConstructor | ||
@Tag(name = "SearchRecommend", description = "Search Recommend API") | ||
public class SearchRecommendController { | ||
private final SearchRecommendService searchRecommendService; | ||
|
||
@Operation(summary = "Recommend Search Term") | ||
@GetMapping | ||
public ResponseEntity<SearchTermRecommendResponseDto> recommendSearchTerm() { | ||
var response = searchRecommendService.recommendSearchTerm(); | ||
return ResponseDto.ok(response); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ain/java/com/depromeet/domains/recommend/dto/response/SearchTermRecommendResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.depromeet.domains.recommend.dto.response; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class SearchTermRecommendResponseDto { | ||
private final List<TextColorDto> description; | ||
private final List<TextColorDto> terms; | ||
} |
11 changes: 11 additions & 0 deletions
11
...reetdrop-api/src/main/java/com/depromeet/domains/recommend/dto/response/TextColorDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.depromeet.domains.recommend.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class TextColorDto { | ||
String text; | ||
String color; | ||
} |
12 changes: 12 additions & 0 deletions
12
...c/main/java/com/depromeet/domains/recommend/repository/SearchRecommendTermRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.depromeet.domains.recommend.repository; | ||
|
||
import com.depromeet.recommend.search.SearchRecommendTerm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.Optional; | ||
|
||
public interface SearchRecommendTermRepository extends JpaRepository<SearchRecommendTerm, Long> { | ||
@Query(value = "SELECT s FROM SearchRecommendTerm s ORDER BY RAND() LIMIT 1") | ||
Optional<SearchRecommendTerm> getRandomSearchRecommendTerm(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...rop-api/src/main/java/com/depromeet/domains/recommend/service/SearchRecommendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.depromeet.domains.recommend.service; | ||
|
||
import com.depromeet.common.error.dto.ErrorCode; | ||
import com.depromeet.common.error.exception.common.BusinessException; | ||
import com.depromeet.domains.recommend.dto.response.SearchTermRecommendResponseDto; | ||
import com.depromeet.domains.recommend.dto.response.TextColorDto; | ||
import com.depromeet.domains.recommend.repository.SearchRecommendTermRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SearchRecommendService { | ||
|
||
private final SearchRecommendTermRepository searchRecommendTermRepository; | ||
|
||
public SearchTermRecommendResponseDto recommendSearchTerm() { | ||
var recommendTerm = searchRecommendTermRepository.getRandomSearchRecommendTerm() | ||
.orElseThrow(() -> new BusinessException(ErrorCode.SEARCH_TERM_NOT_FOUND)); | ||
|
||
var description = recommendTerm.getDescription().stream() | ||
.map((textColorVo) -> | ||
new TextColorDto(textColorVo.getText(), textColorVo.getColor())) | ||
.toList(); | ||
|
||
var termList = recommendTerm.getTerms().stream() | ||
.map((textColorVo) -> | ||
new TextColorDto(textColorVo.getText(), textColorVo.getColor())) | ||
.toList(); | ||
|
||
return new SearchTermRecommendResponseDto(description, termList); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...d/streetdrop-api/src/main/resources/db/migration/V20230822__add_search_term_recommend.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE search_recommend_term ( | ||
search_recommend_term_id BIGINT NOT NULL AUTO_INCREMENT, | ||
title VARCHAR(255) NOT NULL, | ||
description JSON NOT NULL, | ||
terms JSON NOT NULL, | ||
PRIMARY KEY (search_recommend_term_id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...d/streetdrop-domain/src/main/java/com/depromeet/recommend/search/SearchRecommendTerm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.depromeet.recommend.search; | ||
|
||
import io.hypersistence.utils.hibernate.type.json.JsonType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Type; | ||
|
||
import java.util.List; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Entity | ||
public class SearchRecommendTerm { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "search_recommend_term_id") | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String title; | ||
|
||
@Column(nullable = false, columnDefinition = "json") | ||
@Type(value = JsonType.class) | ||
private List<TextColorVo> description; | ||
|
||
@Column(nullable = false, columnDefinition = "json") | ||
@Type(value = JsonType.class) | ||
private List<TextColorVo> terms; | ||
|
||
@Column(nullable = false) | ||
private boolean active; | ||
|
||
@Builder | ||
public SearchRecommendTerm(String title, List<TextColorVo> description, List<TextColorVo> terms) { | ||
this.title = title; | ||
this.description = description; | ||
this.terms = terms; | ||
this.active = true; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/streetdrop-domain/src/main/java/com/depromeet/recommend/search/TextColorVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.depromeet.recommend.search; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@AllArgsConstructor | ||
public class TextColorVo { | ||
private String text; | ||
|
||
private String color; | ||
} |