-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 리액션 API 추가 및 추천리스트 API, 리스트 상세조회 API 재구현
- Loading branch information
Showing
17 changed files
with
381 additions
and
116 deletions.
There are no files selected for viewing
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/listywave/list/application/domain/reaction/Reaction.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.listywave.list.application.domain.reaction; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum Reaction { | ||
|
||
COOL("멋져요"), | ||
AGREE("공감해요"), | ||
THANKS("감사해요") | ||
; | ||
|
||
private final String name; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/listywave/list/application/domain/reaction/ReactionStats.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,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; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/listywave/list/application/domain/reaction/UserReaction.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,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(); | ||
} | ||
} |
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
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
33 changes: 0 additions & 33 deletions
33
src/main/java/com/listywave/list/application/dto/response/ListTrandingResponse.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/listywave/list/application/dto/response/ReactionResponse.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,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(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/listywave/list/application/dto/response/RecommendedListResponse.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,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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.