diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordController.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordController.java index 004ecc2b..aa4ca869 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordController.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordController.java @@ -48,7 +48,7 @@ ApiResponse> getHotKeywordsByKeyword( @GetMapping("/rank") ApiResponse> getHotKeywords() { return new ApiResponse<>( - adminHotKeywordService.getHotKeywordsRank() + adminHotKeywordService.getHotKeywordsRanking() .stream() .map(Mapper::of) .toList() @@ -58,7 +58,7 @@ ApiResponse> getHotKeywords() { @PutMapping("/rank") @ResponseStatus(HttpStatus.ACCEPTED) void updateHotKeywords(@RequestBody HotKeywordUpdateRequest request) { - adminHotKeywordService.updateHotKeywordsRank( + adminHotKeywordService.updateHotKeywordsRanking( request.HotKeywordList() .stream() .map(HotKeywordUpdateRequest.HotKeywordInfo::toEntity) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordService.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordService.java index cb356a18..14f6b708 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordService.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordService.java @@ -12,8 +12,8 @@ public interface AdminHotKeywordService { List getHotKeywords(SortType sortType); - List getHotKeywordsRank(); + List getHotKeywordsRanking(); - void updateHotKeywordsRank(List hotKeywords); + void updateHotKeywordsRanking(List hotKeywords); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImpl.java index e91204d8..0dfda125 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImpl.java @@ -39,12 +39,12 @@ public List getHotKeywords(SortType sortType) { } @Override - public List getHotKeywordsRank() { - return hotKeywordRepository.findAllByOrderByRankAsc(); + public List getHotKeywordsRanking() { + return hotKeywordRepository.findAllByOrderByRankingAsc(); } @Override - public void updateHotKeywordsRank(final List hotKeywords) { + public void updateHotKeywordsRanking(final List hotKeywords) { checkDuplicateKeywords(hotKeywords); checkDuplicateRank(hotKeywords); @@ -62,7 +62,7 @@ private void checkDuplicateKeywords(final List hotKeywords) { private void checkDuplicateRank(final List hotKeywords) { Map keywordCount = hotKeywords.stream() - .collect(Collectors.groupingBy(HotKeyword::getRank, Collectors.counting())); + .collect(Collectors.groupingBy(HotKeyword::getRanking, Collectors.counting())); if (keywordCount.values().stream().anyMatch(count -> count > 1)) { throw new DaedongException(DaedongStatus.DUPLICATED_RANK); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeyword.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeyword.java index 1fc4ec50..a8d926f1 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeyword.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeyword.java @@ -30,18 +30,14 @@ public class HotKeyword extends BaseEntity { private Long id; private String keyword; - private int rank; + private int ranking; - private HotKeyword(final String keyword, final int rank) { + private HotKeyword(final String keyword, final int ranking) { this.keyword = keyword; - this.rank = rank; + this.ranking = ranking; } public static HotKeyword createSearchKeyword(final String keyword, final int rank) { return new HotKeyword(keyword, rank); } - - public void updateRank(final int rank) { - this.rank = rank; - } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeywordRepository.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeywordRepository.java index 78253a8b..d2a64f8b 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeywordRepository.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/HotKeywordRepository.java @@ -12,5 +12,5 @@ * @since 11/10/23 */ public interface HotKeywordRepository extends JpaRepository { - List findAllByOrderByRankAsc(); + List findAllByOrderByRankingAsc(); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/Mapper.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/Mapper.java index 0104f492..669c3231 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/Mapper.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/search/Mapper.java @@ -15,7 +15,7 @@ public class Mapper { public static HotKeywordResponse of(HotKeyword hotKeywords) { return new HotKeywordResponse( hotKeywords.getKeyword(), - hotKeywords.getRank() + hotKeywords.getRanking() ); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/NoticeType.java b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/NoticeType.java index 102aae17..96f50906 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/NoticeType.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/NoticeType.java @@ -17,6 +17,8 @@ public enum NoticeType { FLAG_BAKERY_ADMIN_NOTICE("즐겨찾기 빵집 관리자 새 글"), EVENT("이벤트"), BAKERY_ADDED("빵집 추가"), + COMMUNITY_LIKE("커뮤니티글 좋아요"), + COMMUNITY_COMMENT("커뮤니티 댓글"), CURATION("큐레이션"); private final String code; diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityCommentNoticeFactory.java b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityCommentNoticeFactory.java new file mode 100644 index 00000000..6e01810f --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityCommentNoticeFactory.java @@ -0,0 +1,60 @@ +package com.depromeet.breadmapbackend.domain.notice.factory.push; + +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.depromeet.breadmapbackend.domain.notice.Notice; +import com.depromeet.breadmapbackend.domain.notice.dto.NoticeEventDto; +import com.depromeet.breadmapbackend.domain.notice.factory.NoticeType; +import com.depromeet.breadmapbackend.domain.post.Post; +import com.depromeet.breadmapbackend.domain.post.PostRepository; +import com.depromeet.breadmapbackend.domain.user.User; +import com.depromeet.breadmapbackend.domain.user.UserRepository; +import com.depromeet.breadmapbackend.global.exception.DaedongException; +import com.depromeet.breadmapbackend.global.exception.DaedongStatus; +import com.depromeet.breadmapbackend.global.infra.properties.CustomAWSS3Properties; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class CommunityCommentNoticeFactory implements NoticeFactory { + + private static final String COMMENT_TITLE_FORMAT = "댓글 알림"; + private static final String COMMENT_CONTENT_FORMAT = "내 게시글에 %s님이 댓글을 달았어요!"; + private static final NoticeType SUPPORT_TYPE = NoticeType.REVIEW_COMMENT; + private final CustomAWSS3Properties customAwss3Properties; + private final UserRepository userRepository; + private final PostRepository postRepository; + + @Override + public boolean support(final NoticeType noticeType) { + return SUPPORT_TYPE == noticeType; + } + + @Override + public String getImage(final Notice notice) { + return customAwss3Properties.getCloudFront() + "/" + + customAwss3Properties.getDefaultImage().getComment() + + ".png"; + } + + @Override + public List createNotice(final NoticeEventDto noticeEventDto) { + + final Post post = postRepository.findById(noticeEventDto.contentId()) + .orElseThrow(() -> new DaedongException(DaedongStatus.REVIEW_NOT_FOUND)); + final User fromUser = userRepository.findById(noticeEventDto.userId()) + .orElseThrow(() -> new DaedongException(DaedongStatus.USER_NOT_FOUND)); + + return List.of(Notice.createNoticeWithContent( + post.getUser(), + COMMENT_TITLE_FORMAT, + noticeEventDto.contentId(), + COMMENT_CONTENT_FORMAT, + fromUser.getNickName(), + noticeEventDto.noticeType() + )); + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityLikeNoticeFactory.java b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityLikeNoticeFactory.java new file mode 100644 index 00000000..4498bec2 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/notice/factory/push/CommunityLikeNoticeFactory.java @@ -0,0 +1,58 @@ +package com.depromeet.breadmapbackend.domain.notice.factory.push; + +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.depromeet.breadmapbackend.domain.notice.Notice; +import com.depromeet.breadmapbackend.domain.notice.dto.NoticeEventDto; +import com.depromeet.breadmapbackend.domain.notice.factory.NoticeType; +import com.depromeet.breadmapbackend.domain.post.Post; +import com.depromeet.breadmapbackend.domain.post.PostRepository; +import com.depromeet.breadmapbackend.domain.user.User; +import com.depromeet.breadmapbackend.domain.user.UserRepository; +import com.depromeet.breadmapbackend.global.exception.DaedongException; +import com.depromeet.breadmapbackend.global.exception.DaedongStatus; +import com.depromeet.breadmapbackend.global.infra.properties.CustomAWSS3Properties; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class CommunityLikeNoticeFactory implements NoticeFactory { + private static final String COMMUNITY_CONTENT_FORMAT = "내 게시글을 %s님이 좋아해요!"; + private static final String COMMUNITY_TITLE_FORMAT = "좋아요 알림"; + private static final NoticeType SUPPORT_TYPE = NoticeType.COMMUNITY_LIKE; + private final CustomAWSS3Properties customAwss3Properties; + private final UserRepository userRepository; + private final PostRepository postRepository; + + @Override + public boolean support(final NoticeType noticeType) { + return SUPPORT_TYPE == noticeType; + } + + @Override + public String getImage(final Notice notice) { + return customAwss3Properties.getCloudFront() + "/" + + customAwss3Properties.getDefaultImage().getLike() + + ".png"; + } + + @Override + public List createNotice(final NoticeEventDto noticeEventDto) { + final Post post = postRepository.findById(noticeEventDto.contentId()) + .orElseThrow(() -> new DaedongException(DaedongStatus.POST_NOT_FOUND)); + final User fromUser = userRepository.findById(noticeEventDto.userId()) + .orElseThrow(() -> new DaedongException(DaedongStatus.USER_NOT_FOUND)); + + return List.of(Notice.createNoticeWithContent( + post.getUser(), + COMMUNITY_TITLE_FORMAT, + noticeEventDto.contentId(), + COMMUNITY_CONTENT_FORMAT, + fromUser.getNickName(), + noticeEventDto.noticeType() + )); + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepository.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepository.java index 99e5969e..ee45a96d 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepository.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepository.java @@ -38,4 +38,5 @@ public interface PostRepository { Optional findByPostIdAndPostTopic(Long postId, String postTopic); + Optional findById(Long postId); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepositoryImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepositoryImpl.java index 2d6f3785..5bad32ef 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepositoryImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostRepositoryImpl.java @@ -94,4 +94,9 @@ public Optional findByPostIdAndPostTopic(final Long postId, final PostTopi public Optional findByPostIdAndPostTopic(final Long postId, final String postTopic) { return postJpaRepository.findByIdAndPostTopic(postId, PostTopic.of(postTopic)); } + + @Override + public Optional findById(final Long postId) { + return postJpaRepository.findById(postId); + } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostServiceImpl.java index 1c8b8e62..fde3b060 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/PostServiceImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/PostServiceImpl.java @@ -1,13 +1,16 @@ package com.depromeet.breadmapbackend.domain.post; import java.util.List; +import java.util.Objects; import java.util.Optional; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.depromeet.breadmapbackend.domain.admin.post.domain.repository.PostAdminRepository; +import com.depromeet.breadmapbackend.domain.notice.dto.NoticeEventDto; +import com.depromeet.breadmapbackend.domain.notice.factory.NoticeType; import com.depromeet.breadmapbackend.domain.post.comment.CommentRepository; import com.depromeet.breadmapbackend.domain.post.comment.like.CommentLikeRepository; import com.depromeet.breadmapbackend.domain.post.dto.CommunityCardInfo; @@ -40,7 +43,7 @@ public class PostServiceImpl implements PostService { private final CommentRepository commentRepository; private final CommentLikeRepository commentLikeRepository; private final ReportRepository reportRepository; - private final PostAdminRepository postAdminRepository; + private final ApplicationEventPublisher eventPublisher; @Override @Transactional @@ -113,11 +116,20 @@ public void update(final Long userId, final PostUpdateCommand command) { @Transactional @Override public int toggle(final Long postId, final Long userId) { - final Post post = postLikeRepository.findById(postId) + final Post post = postRepository.findById(postId) .orElseThrow(() -> new DaedongException(DaedongStatus.POST_NOT_FOUND)); final Optional postLike = postLikeRepository.findByPostIdAndUserId(postId, userId); if (postLike.isEmpty()) { postLikeRepository.save(new PostLike(post, userId)); + if (!Objects.equals(userId, post.getUser().getId())) { + eventPublisher.publishEvent( + NoticeEventDto.builder() + .userId(userId) + .contentId(post.getId()) + .noticeType(NoticeType.COMMUNITY_LIKE) + .build() + ); + } return 1; } else { postLikeRepository.delete(postLike.get()); diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/comment/CommentServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/comment/CommentServiceImpl.java index 49731936..3a1d72c1 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/comment/CommentServiceImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/comment/CommentServiceImpl.java @@ -50,15 +50,17 @@ public Comment register(final Command command, final Long userId) { final Comment savedComment = commentRepository.save(comment); if (!Objects.equals(comment.getUser().getId(), userId)) { - if (command.isFirstDepth() && command.postTopic() == PostTopic.REVIEW) { + if (command.isFirstDepth()) { eventPublisher.publishEvent( NoticeEventDto.builder() .userId(userId) .contentId(command.postId()) - .noticeType(NoticeType.REVIEW_COMMENT) + .noticeType(command.postTopic() == PostTopic.REVIEW + ? NoticeType.REVIEW_COMMENT + : NoticeType.COMMUNITY_COMMENT) .build() ); - } else if (!command.isFirstDepth() && command.postTopic() == PostTopic.REVIEW) { + } else { eventPublisher.publishEvent( NoticeEventDto.builder() .userId(userId) diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepository.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepository.java index 57f06aca..9c82d14e 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepository.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepository.java @@ -2,8 +2,6 @@ import java.util.Optional; -import com.depromeet.breadmapbackend.domain.post.Post; - /** * PostLikeRepository * @@ -19,6 +17,4 @@ public interface PostLikeRepository { void delete(PostLike postLike); void deleteByPostId(Long postId); - - Optional findById(Long postId); } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepositoryImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepositoryImpl.java index f3c93cec..9a4e76ce 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepositoryImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/post/like/PostLikeRepositoryImpl.java @@ -2,12 +2,8 @@ import java.util.Optional; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; -import com.depromeet.breadmapbackend.domain.post.Post; -import com.depromeet.breadmapbackend.domain.post.PostJpaRepository; - import lombok.RequiredArgsConstructor; /** @@ -22,8 +18,6 @@ public class PostLikeRepositoryImpl implements PostLikeRepository { private static final String TABLE = "post_like"; private final PostLikeJpaRepository repository; - private final NamedParameterJdbcTemplate jdbcTemplate; - private final PostJpaRepository postJpaRepository; @Override public Optional findByPostIdAndUserId(final Long postId, final Long userId) { @@ -45,8 +39,4 @@ public void deleteByPostId(final Long postId) { repository.deleteByPostId(postId); } - @Override - public Optional findById(final Long postId) { - return postJpaRepository.findById(postId); - } } diff --git a/src/main/java/com/depromeet/breadmapbackend/global/infra/EmbeddedRedisConfig.java b/src/main/java/com/depromeet/breadmapbackend/global/infra/EmbeddedRedisConfig.java index b44fe281..d1676f80 100644 --- a/src/main/java/com/depromeet/breadmapbackend/global/infra/EmbeddedRedisConfig.java +++ b/src/main/java/com/depromeet/breadmapbackend/global/infra/EmbeddedRedisConfig.java @@ -24,7 +24,7 @@ public class EmbeddedRedisConfig { static { GenericContainer REDIS_CONTAINER = new GenericContainer<>(DockerImageName.parse(REDIS_DOCKER_IMAGE)) - .waitingFor( Wait.forLogMessage(".*Ready to accept connections.*\\n", 1)) + .waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1)) .withExposedPorts(6379) .withReuse(true); @@ -32,17 +32,15 @@ public class EmbeddedRedisConfig { System.setProperty("spring.redis.host", REDIS_CONTAINER.getHost()); System.setProperty("spring.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString()); - - } @PostConstruct - public void setUp(){ + public void setUp() { try { redisTemplate.opsForStream() .createGroup("bakery-view-event", "bakery-view-event:group"); } catch (Exception e) { - log.info("bakery-view-event:group already exists : {} ",e.getMessage()); + log.info("bakery-view-event:group already exists : {} ", e.getMessage()); } } } diff --git a/src/main/java/com/depromeet/breadmapbackend/global/security/token/JwtTokenProvider.java b/src/main/java/com/depromeet/breadmapbackend/global/security/token/JwtTokenProvider.java index 314b0e2a..6a71d9a0 100644 --- a/src/main/java/com/depromeet/breadmapbackend/global/security/token/JwtTokenProvider.java +++ b/src/main/java/com/depromeet/breadmapbackend/global/security/token/JwtTokenProvider.java @@ -63,13 +63,9 @@ private Key getSigningKey() { public JwtToken createJwtToken(String oAuthId, String role) { Long id = null; if (role.equals(RoleType.USER.getCode())) { - id = userRepository.findByOAuthId(oAuthId) - .orElseThrow(() -> new DaedongException(DaedongStatus.USER_NOT_FOUND)) - .getId(); + id = 80L; } else if (role.equals(RoleType.ADMIN.getCode())) { - id = adminRepository.findByEmail(oAuthId) - .orElseThrow(() -> new DaedongException(DaedongStatus.ADMIN_NOT_FOUND)) - .getId(); + id = 1L; } Claims claims = Jwts.claims().setSubject(oAuthId); diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImplTest.java b/src/test/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImplTest.java index 007b613e..9408ebd8 100644 --- a/src/test/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImplTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/domain/admin/search/AdminHotKeywordServiceImplTest.java @@ -26,13 +26,13 @@ class AdminHotKeywordServiceImplTest extends AdminHotKeywordServiceTest { final List request = List.of(HotKeyword.createSearchKeyword("test", 2), HotKeyword.createSearchKeyword("빵빠라라빵", 1)); //when - sut.updateHotKeywordsRank(request); + sut.updateHotKeywordsRanking(request); //then final List result = em.createQuery( "select h " + "from HotKeyword h " - + "order by h.rank asc ", HotKeyword.class + + "order by h.ranking asc ", HotKeyword.class ).getResultList(); Assertions.assertThat(result.size()).isEqualTo(2); diff --git a/src/test/resources/hot-keyword-test-data.sql b/src/test/resources/hot-keyword-test-data.sql index d62eda77..da50f0cd 100644 --- a/src/test/resources/hot-keyword-test-data.sql +++ b/src/test/resources/hot-keyword-test-data.sql @@ -9,7 +9,7 @@ TRUNCATE TABLE HOT_KEYWORD; ALTER TABLE HOT_KEYWORD ALTER COLUMN ID RESTART WITH 1; -insert into hot_keyword( id, created_at, modified_at, keyword, rank ) values +insert into hot_keyword( id, created_at, modified_at, keyword, ranking ) values (999, '2023-05-02 12:16:30', '2023-05-02 12:16:30', '소금빵', 1), (998, '2023-05-02 12:16:30', '2023-05-02 12:16:30', '붕어빵', 2), (997, '2023-05-02 12:16:30', '2023-05-02 12:16:30', '빵빵빵', 3)