-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 공개된 여행 단건 조회 로직 변경 * refactor: 좋아요 여부 변경 기능 redis 사용한로직으로 변경 * feat: 게시물 좋아요 여부 cache write back 스케줄링 기능 추가 * feat: 게시물 좋아요 수 캐싱 및 스케줄링 기능 추가 * feat: 게시물 좋아요 변경 시 캐싱된 좋아요 수 업데이트 로직 추가 * test: 게시물 좋아요 변경 테스트 수정 * chore: Like Repository 패키지 위치 변경 * refactor: 변수 네이밍 변경
- Loading branch information
Showing
13 changed files
with
262 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hanglog.like.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "likeCount") | ||
public class LikeCount { | ||
|
||
@Id | ||
private Long tripId; | ||
|
||
private Long count; | ||
} |
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,18 @@ | ||
package hanglog.like.domain; | ||
|
||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "memberLike", timeToLive = 5400) | ||
public class MemberLike { | ||
|
||
@Id | ||
private Long memberId; | ||
|
||
private Map<Long, Boolean> likeStatusForTrip; | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/hanglog/like/domain/repository/CustomLikeRepository.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,9 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.Likes; | ||
import java.util.List; | ||
|
||
public interface CustomLikeRepository { | ||
|
||
void saveAll(final List<Likes> likes); | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/hanglog/like/domain/repository/LikeCountRepository.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,10 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.LikeCount; | ||
import java.util.List; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface LikeCountRepository extends CrudRepository<LikeCount, Long> { | ||
|
||
List<LikeCount> findLikeCountsByTripIdIn(final List<Long> tripIds); | ||
} |
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
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/hanglog/like/domain/repository/MemberLikeRepository.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,7 @@ | ||
package hanglog.like.domain.repository; | ||
|
||
import hanglog.like.domain.MemberLike; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface MemberLikeRepository extends CrudRepository<MemberLike, Long> { | ||
} |
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,12 @@ | ||
package hanglog.like.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class TripLikeCount { | ||
|
||
private final long tripId; | ||
private final long count; | ||
} |
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/hanglog/like/infrastrcutrue/CustomLikeRepositoryImpl.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,37 @@ | ||
package hanglog.like.infrastrcutrue; | ||
|
||
import hanglog.like.domain.Likes; | ||
import hanglog.like.domain.repository.CustomLikeRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class CustomLikeRepositoryImpl implements CustomLikeRepository { | ||
|
||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; | ||
|
||
@Override | ||
public void saveAll(final List<Likes> likes) { | ||
final String sql = """ | ||
INSERT INTO likes (trip_id, member_id) | ||
VALUES (:tripId, :memberId) | ||
"""; | ||
namedParameterJdbcTemplate.batchUpdate(sql, getLikesToSqlParameterSources(likes)); | ||
} | ||
|
||
private MapSqlParameterSource[] getLikesToSqlParameterSources(final List<Likes> likes) { | ||
return likes.stream() | ||
.map(this::getLikeToSqlParameterSource) | ||
.toArray(MapSqlParameterSource[]::new); | ||
} | ||
|
||
private MapSqlParameterSource getLikeToSqlParameterSource(final Likes likes) { | ||
return new MapSqlParameterSource() | ||
.addValue("tripId", likes.getTripId()) | ||
.addValue("memberId", likes.getMemberId()); | ||
} | ||
} |
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
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
Oops, something went wrong.