Skip to content

Commit

Permalink
feat: implements getting memo recommendations api
Browse files Browse the repository at this point in the history
  • Loading branch information
comolove committed Nov 9, 2023
1 parent 9aa8d33 commit 65ce3af
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void removeMemo(@PathVariable @Min(1) Long id) {
memoService.deleteMemo(id);
}

@GetMapping("/{id}/recommendations")
public List<MemoListDto> getMemoRecommendationsByTags(
@PathVariable @Min(1) Long id
) {
return memoService.getMemoRecommendations(id);
}

@PostMapping("/{id}/image")
public ImageDto uploadImageInMemo(
@PathVariable @Min(1) Long id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface MemoRepository {
List<Memo> findAllOrderById(Long pageNum, Long resultCntPerPage);
List<Memo> findAllByUserIdOrderById(Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllLikedMemosByUserId(Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllByTagsOrderByMatchesAndLikes(Long memoId);
List<Memo> findAllDraftMemosByUserId(Long userId);
List<Memo> findAllBySearchQuery(List<String> searchStringList, OrderType orderType, Long userId, Long pageNum, Long resultCntPerPage);
List<Memo> findAllByTag(String tagText, OrderType orderType, Long pageNum, Long resultCntPerPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public List<Memo> findAllLikedMemosByUserId(Long userId, Long pageNum, Long resu
return template.query(sql, memoRowMapper(), userId, resultCntPerPage, resultCntPerPage*pageNum);
}

@Override
public List<Memo> findAllByTagsOrderByMatchesAndLikes(Long memoId) {
String sql = "SELECT m.* " +
"FROM post.memo m , UNNEST(m.tags) tag_element " +
"WHERE tag_element ILIKE ANY(ARRAY(SELECT tags FROM post.memo WHERE id = ? AND array_length(tags, 1) >= 1)) " +
"AND NOT id = ? " +
"AND is_temporary = false " +
"GROUP BY id " +
"ORDER BY COUNT(tag_element) desc, likes desc, id desc";

return template.query(sql, memoRowMapper(), memoId, memoId);
}

@Override
public List<Memo> findAllDraftMemosByUserId(Long userId) {
String sql = "select * from post.memo where author_id = ? and is_temporary = true order by id desc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ public MemoDto getMemoBy(Long memoId) {
return responseDto;
}

public List<MemoListDto> getMemoRecommendations(Long id) {

return memoRepository.findAllByTagsOrderByMatchesAndLikes(id).stream()
.map(MemoListDto::new)
.toList();
}

@Transactional
public MemoDto updateMemo(Long memoId, MemoSaveDto form) {

Expand Down

0 comments on commit 65ce3af

Please sign in to comment.