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
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ public ResponseEntity<ApiResponse<PostsResponse>> recommendPosts(@Authentication
public ResponseEntity<ApiResponse<SaveRecommendLikesResponse>> likeRecommendation(@AuthenticationPrincipal User user, @PathVariable Long postId) {
return ResponseEntity.ok().body(ApiResponse.success(likeService.likesAtRecommendation(user == null ? null : user.getUsername(), postId)));
}

@PatchMapping("/vector/update/all")
public ResponseEntity<ApiResponse<String>> updateAllPostVector() {
return ResponseEntity.ok().body(ApiResponse.success(recommendService.updateAllPostVector()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.TwoSeaU.BaData.global.dto.CursorPageResponse;

import java.util.List;
import java.util.Set;

public interface PostQueryRepository {

Expand All @@ -16,5 +17,5 @@ public interface PostQueryRepository {

CursorPageResponse<PostResponse> searchPostsByDeadLine(final String username, final Long cursor, final int size);

List<Post> getRecentPostsBySize(final int size);
List<Post> getRecentPostsBySize(final int size, final Set<Long> excludedPostIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;

import com.TwoSeaU.BaData.domain.trade.dto.response.PostResponse;
import com.TwoSeaU.BaData.domain.trade.entity.*;
Expand Down Expand Up @@ -199,13 +200,16 @@ public CursorPageResponse<PostResponse> searchPostsByDeadLine(final String usern
}

@Override
public List<Post> getRecentPostsBySize(final int size) {
public List<Post> getRecentPostsBySize(final int size, final Set<Long> excludedPostIds) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
final QPost qpost = QPost.post;
final BooleanBuilder where = new BooleanBuilder();

where.and(qpost.isDeleted.isFalse());
where.and(qpost.isSold.isFalse());
where.and(qpost.deadLine.goe(java.time.LocalDate.now()));
if (excludedPostIds != null && !excludedPostIds.isEmpty()){
where.and(qpost.id.notIn(excludedPostIds));
}

return queryFactory.selectFrom(qpost)
.where(where)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.TwoSeaU.BaData.domain.user.exception.UserException;
import com.TwoSeaU.BaData.domain.user.repository.UserRepository;
import com.TwoSeaU.BaData.global.response.GeneralException;
import jakarta.transaction.Transactional;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -152,22 +151,6 @@ public void clearRecommendationCache(Long userId) {
}
}

@Transactional
public String updateAllPostVector() {
for (Gifticon gifticon : gifticonRepository.findAll()) {
double[] vector = postVectorizer.vectorizePost(
gifticon.getPrice(),
gifticon.getDeadLine(),
gifticon.getCategory(),
gifticon.getPartner()
);

gifticon.updateVector(vector);
}

return "success";
}

@Data
@AllArgsConstructor
public static class RecommendationResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -57,7 +58,10 @@ public List<PostResponse> getTrendingPosts(String username) {
}

if (resultPosts.size() < POSTS_LIMIT) {
resultPosts.addAll(postsRepository.getRecentPostsBySize(POSTS_LIMIT - resultPosts.size()));
final Set<Long> postIdSet = resultPosts.stream()
.map(Post::getId)
.collect(Collectors.toSet());
resultPosts.addAll(postsRepository.getRecentPostsBySize(POSTS_LIMIT - resultPosts.size(), postIdSet));
}

return resultPosts
Expand Down