Skip to content

Commit

Permalink
feat: 리액션 API 추가 및 추천리스트 API, 리스트 상세조회 API 재구현
Browse files Browse the repository at this point in the history
  • Loading branch information
pparkjs committed Sep 29, 2024
1 parent 56a278b commit 0fd13dc
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class AuthorizationInterceptor implements HandlerInterceptor {

private static final UriAndMethod[] whiteList = {
new UriAndMethod("/lists/explore", GET),
new UriAndMethod("/lists/recommended", GET),
new UriAndMethod("/lists/search", GET),
new UriAndMethod("/lists/{listId}/comments", GET),
new UriAndMethod("/lists/upload-url", GET),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ public void validateUpdateAuthority(User loginUser, Collaborators beforeCollabor
public void increaseUpdateCount(){
this.updateCount++;
}

public boolean isOwner(User loginUser) {
return this.user.equals(loginUser);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.listywave.list.application.domain.reaction;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Reaction {

COOL("멋져요"),
AGREE("공감해요"),
THANKS("감사해요")
;

private final String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.listywave.list.application.domain.reaction;

import com.listywave.common.BaseEntity;
import com.listywave.list.application.domain.list.ListEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import static jakarta.persistence.FetchType.LAZY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@Entity
@Builder
@AllArgsConstructor
@Table(name = "reaction_stats")
@NoArgsConstructor(access = PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class ReactionStats extends BaseEntity {

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "list_id", nullable = false)
private ListEntity list;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Reaction reaction;

@Column(nullable = false)
private int count;

public void updateCount(int changeCount) {
this.count += changeCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.listywave.list.application.domain.reaction;

import com.listywave.list.application.domain.list.ListEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.TemporalType.TIMESTAMP;
import static lombok.AccessLevel.PROTECTED;

@Getter
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
@EntityListeners(AuditingEntityListener.class)
@Table(name = "user_reaction",
uniqueConstraints= {
@UniqueConstraint(
name = "UniqueIdAndUserIdAndReaction",
columnNames = {"id", "user_id", "reaction"}
)
}
)
public class UserReaction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "user_id", nullable = false)
private Long userId;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "list_id", nullable = false)
private ListEntity list;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Reaction reaction;

@CreatedDate
@Temporal(TIMESTAMP)
@Column(updatable = false)
private LocalDateTime createdDate;

public static UserReaction create(Long userId, ListEntity list, Reaction reaction) {
return UserReaction.builder()
.userId(userId)
.list(list)
.reaction(reaction)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ public record ListDetailResponse(
boolean isPublic,
String backgroundPalette,
String backgroundColor,
int collectCount,
int viewCount
Integer collectCount,
int viewCount,
int updateCount,
List<ReactionResponse> reactions
) {

public static ListDetailResponse of(
ListEntity list,
User owner,
boolean isOwner,
boolean isCollected,
List<Collaborator> collaborators
List<Collaborator> collaborators,
List<ReactionResponse> reactions
) {
return ListDetailResponse.builder()
.categoryEngName(list.getCategory().name().toLowerCase())
Expand All @@ -54,8 +58,10 @@ public static ListDetailResponse of(
.isPublic(list.isPublic())
.backgroundColor(list.getBackgroundColor().name())
.backgroundPalette(list.getBackgroundPalette().name())
.collectCount(list.getCollectCount())
.collectCount(isOwner ? list.getCollectCount() : null)
.viewCount(list.getViewCount())
.updateCount(list.getUpdateCount())
.reactions(reactions)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.listywave.list.application.domain.item.Item;
import com.listywave.list.application.domain.list.ListEntity;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import lombok.Builder;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.listywave.list.application.dto.response;

import lombok.Builder;

@Builder
public record ReactionResponse(
String reaction,
Integer count,
boolean isReacted
) {

public static ReactionResponse of(String name, Integer count, boolean isReacted) {
return ReactionResponse.builder()
.reaction(name)
.count(count)
.isReacted(isReacted)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.listywave.list.application.dto.response;

import com.listywave.list.application.domain.item.Item;
import com.listywave.list.application.domain.list.ListEntity;
import lombok.Builder;

import java.util.List;

@Builder
public record RecommendedListResponse(
Long id,
Long ownerId,
String ownerNickname,
String title,
String itemImageUrl,
String category,
String backgroundColor,
List<Top3ItemResponse> items
) {
public static RecommendedListResponse of(ListEntity list) {
return RecommendedListResponse.builder()
.id(list.getId())
.ownerId(list.getUser().getId())
.ownerNickname(list.getUser().getNickname())
.title(list.getTitle().getValue())
.itemImageUrl(list.getRepresentImageUrl())
.category(list.getCategory().getViewName())
.backgroundColor(list.getBackgroundColor().name())
.items(Top3ItemResponse.toList(list.getTop3Items().getValues()))
.build();
}

@Builder
public record Top3ItemResponse(
Long id,
int rank,
String title
) {

public static List<Top3ItemResponse> toList(List<Item> items) {
return items.stream()
.map(Top3ItemResponse::of)
.toList();
}

public static Top3ItemResponse of(Item item) {
return Top3ItemResponse.builder()
.id(item.getId())
.rank(item.getRanking())
.title(item.getTitle().getValue())
.build();
}
}
}
Loading

0 comments on commit 0fd13dc

Please sign in to comment.