Skip to content

Commit

Permalink
hotfix: timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
doxxx93 committed Feb 21, 2024
1 parent b52583c commit 7e4c83e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.palette.easeltimelineservice;

import org.palette.aop.EaselAuthenticationContext;
import org.palette.aop.LoggingAspect;
import org.palette.aop.PassportAspect;
import org.palette.config.CommonModuleConfig;
import org.palette.config.KafkaConsumerConfig;
Expand All @@ -15,7 +16,8 @@
EaselAuthenticationContext.class,
PassportAspect.class,
KafkaConsumerConfig.class,
KafkaProducerConfig.class
KafkaProducerConfig.class,
LoggingAspect.class
})
public class EaselTimelineServiceApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.palette.aop.EaselAuthenticationContext;
import org.palette.aop.InjectEaselAuthentication;
import org.palette.aop.InternalErrorLogging;
import org.palette.easeltimelineservice.service.PaintResponse;
import org.palette.easeltimelineservice.usecase.TimelineUsecase;
import org.springframework.http.ResponseEntity;
Expand All @@ -19,13 +20,15 @@ public class TimelineController {

@GetMapping("/following")
@InjectEaselAuthentication
@InternalErrorLogging
public ResponseEntity<List<PaintResponse>> getFollowingTimeline() {
final Long userId = EaselAuthenticationContext.getUserInfo().id();
return ResponseEntity.ok(timelineUsecase.getFollowingTimeline(userId));
}

@GetMapping("/for-you")
@InjectEaselAuthentication
@InternalErrorLogging
public ResponseEntity<List<PaintResponse>> getForYouTimeline() {
final Long userId = EaselAuthenticationContext.getUserInfo().id();
return ResponseEntity.ok(timelineUsecase.getForYouTimeline(userId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public List<Paint> getPaints(final List<Long> paintIds) {

public List<Paint> getRandomPaints() {
return Optional.ofNullable(redistemplate.opsForSet().randomMembers(PAINT_PREFIX.getKey(), 200))
.orElseGet(Collections::emptyList)
.stream()
.map(Paint.class::cast)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ public void handleUnlikedPaintEvent(final UnlikedPaintEvent unlikedPaintEvent) {
public List<PaintResponse> getForYouTimeline(final Long userId) {
List<Paint> paints = paintCacheService.getRandomPaints();
List<Long> paintIds = followerPaintMapService.getFollowingTimelinePaintIds(userId);
paints.removeIf(paint -> paintIds.contains(paint.getId()));
paints.removeIf(paint -> paint.getAuthorId().equals(userId));
return paints.stream().map(paint -> {

List<Paint> filteredPaints = paints.stream()
.filter(paint -> !paintIds.contains(paint.getId()))
.filter(paint -> !paint.getAuthorId().equals(userId))
.toList();

return filteredPaints.stream().map(paint -> {
PaintMetrics metrics = paintMetricsService.getPaintMetrics(paint.getId());
return PaintResponse.of(paint, metrics);
}
Expand Down

0 comments on commit 7e4c83e

Please sign in to comment.