Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix : 알림 & 검색 키워드 오류 수정 #366

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ApiResponse<List<KeywordStatResponse>> getHotKeywordsByKeyword(
@GetMapping("/rank")
ApiResponse<List<HotKeywordResponse>> getHotKeywords() {
return new ApiResponse<>(
adminHotKeywordService.getHotKeywordsRank()
adminHotKeywordService.getHotKeywordsRanking()
.stream()
.map(Mapper::of)
.toList()
Expand All @@ -58,7 +58,7 @@ ApiResponse<List<HotKeywordResponse>> getHotKeywords() {
@PutMapping("/rank")
@ResponseStatus(HttpStatus.ACCEPTED)
void updateHotKeywords(@RequestBody HotKeywordUpdateRequest request) {
adminHotKeywordService.updateHotKeywordsRank(
adminHotKeywordService.updateHotKeywordsRanking(
request.HotKeywordList()
.stream()
.map(HotKeywordUpdateRequest.HotKeywordInfo::toEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public interface AdminHotKeywordService {
List<Keyword> getHotKeywords(SortType sortType);

List<HotKeyword> getHotKeywordsRank();
List<HotKeyword> getHotKeywordsRanking();

void updateHotKeywordsRank(List<HotKeyword> hotKeywords);
void updateHotKeywordsRanking(List<HotKeyword> hotKeywords);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public List<Keyword> getHotKeywords(SortType sortType) {
}

@Override
public List<HotKeyword> getHotKeywordsRank() {
return hotKeywordRepository.findAllByOrderByRankAsc();
public List<HotKeyword> getHotKeywordsRanking() {
return hotKeywordRepository.findAllByOrderByRankingAsc();
}

@Override
public void updateHotKeywordsRank(final List<HotKeyword> hotKeywords) {
public void updateHotKeywordsRanking(final List<HotKeyword> hotKeywords) {
checkDuplicateKeywords(hotKeywords);
checkDuplicateRank(hotKeywords);

Expand All @@ -62,7 +62,7 @@ private void checkDuplicateKeywords(final List<HotKeyword> hotKeywords) {

private void checkDuplicateRank(final List<HotKeyword> hotKeywords) {
Map<Integer, Long> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
* @since 11/10/23
*/
public interface HotKeywordRepository extends JpaRepository<HotKeyword, Long> {
List<HotKeyword> findAllByOrderByRankAsc();
List<HotKeyword> findAllByOrderByRankingAsc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Mapper {
public static HotKeywordResponse of(HotKeyword hotKeywords) {
return new HotKeywordResponse(
hotKeywords.getKeyword(),
hotKeywords.getRank()
hotKeywords.getRanking()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum NoticeType {
FLAG_BAKERY_ADMIN_NOTICE("즐겨찾기 빵집 관리자 새 글"),
EVENT("이벤트"),
BAKERY_ADDED("빵집 추가"),
COMMUNITY_LIKE("커뮤니티글 좋아요"),
COMMUNITY_COMMENT("커뮤니티 댓글"),
CURATION("큐레이션");

private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Notice> 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()
));
}
}
Original file line number Diff line number Diff line change
@@ -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<Notice> 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()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ public interface PostRepository {

Optional<Post> findByPostIdAndPostTopic(Long postId, String postTopic);

Optional<Post> findById(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,9 @@ public Optional<Post> findByPostIdAndPostTopic(final Long postId, final PostTopi
public Optional<Post> findByPostIdAndPostTopic(final Long postId, final String postTopic) {
return postJpaRepository.findByIdAndPostTopic(postId, PostTopic.of(postTopic));
}

@Override
public Optional<Post> findById(final Long postId) {
return postJpaRepository.findById(postId);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Optional;

import com.depromeet.breadmapbackend.domain.post.Post;

/**
* PostLikeRepository
*
Expand All @@ -19,6 +17,4 @@ public interface PostLikeRepository {
void delete(PostLike postLike);

void deleteByPostId(Long postId);

Optional<Post> findById(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<PostLike> findByPostIdAndUserId(final Long postId, final Long userId) {
Expand All @@ -45,8 +39,4 @@ public void deleteByPostId(final Long postId) {
repository.deleteByPostId(postId);
}

@Override
public Optional<Post> findById(final Long postId) {
return postJpaRepository.findById(postId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@ 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);

REDIS_CONTAINER.start();

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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading