Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
chae33 committed Feb 5, 2024
1 parent 098d280 commit ae062b8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void uploadPostFileList(MultipartFile multipartFile, Post post) throws IO
.post(post).build());
}

//뱃지 카운트
//뱃지 카운트 (게시글 작성)
private void updateBadgeCount(Badge badge, Category category, Tag tag) {

LocalDateTime currentTime = LocalDateTime.now();
Expand All @@ -97,11 +97,56 @@ private void updateBadgeCount(Badge badge, Category category, Tag tag) {
if (category.equals(Category.ETC)) { badge.setEtcCount(badge.getEtcCount() + 1);}
if (category.equals(Category.QUESTION)) { badge.setMentorCount(badge.getMentorCount() + 1);}
}
updateIsAchieved(badge);
}


//뱃지조건에 따라 isAchieved update ->
// + 삭제했을 떄 처리 코드도 작성

//isAchieved update
private void updateIsAchieved(Badge badge){
if(badge.getEarlybirdCount() >= 3) { badge.setEarlybirdIsAchieved(true);}

// 질문카테고리 댓글 n회 이상 → mentorCount
// 질문 카테고리 글 작성 n회 이상 → menteeCount

if(badge.getReceiptCount() >= 3) { badge.setReceipt3IsAchieved(true);
if(badge.getReceiptCount() >= 10) { badge.setReceipt10IsAchieved(true);}}
if(badge.getReusableCount() >= 3) { badge.setReusable3IsAchieved(true);
if(badge.getReusableCount() >= 10) { badge.setReusable10IsAchieved(true);}}
if(badge.getPlasticCount() >= 3) { badge.setPlastic3IsAchieved(true);
if(badge.getPlasticCount() >= 10) { badge.setPlastic10IsAchieved(true);}}
if(badge.getPloggingCount() >= 3) { badge.setPlogging3IsAchieved(true);
if(badge.getPloggingCount() >= 10) { badge.setPlogging10IsAchieved(true);}}
if(badge.getReformCount() >= 3) { badge.setReform3IsAchieved(true);
if(badge.getReformCount() >= 10) { badge.setReform10IsAchieved(true);}}
if(badge.getTransportCount() >= 3) { badge.setTransport3IsAchieved(true);
if(badge.getTransportCount() >= 10) { badge.setTransport10IsAchieved(true);}}
if(badge.getEtcCount() >= 3) { badge.setEtc3IsAchieved(true);
if(badge.getEtcCount() >= 10) { badge.setEtc10IsAchieved(true);}}
}

// 뱃지 카운트 (게시글 삭제)
private void decreaseBadgeCount(Badge badge, Category category, Tag tag) {

LocalDateTime currentTime = LocalDateTime.now();
boolean isBefore9AM = currentTime.toLocalTime().isBefore(LocalTime.of(9, 0));

if (isBefore9AM && tag.equals(Tag.CERTIFY)) {
badge.setEarlybirdCount(Math.max(badge.getEarlybirdCount() - 1, 0));
}
if (tag.equals(Tag.CERTIFY)){
badge.setCertificationCount(Math.max(badge.getCertificationCount() - 1, 0));
if (category.equals(Category.RECEIPT)) { badge.setReceiptCount(Math.max(badge.getReceiptCount() - 1, 0));}
if (category.equals(Category.REUSABLE)) { badge.setReusableCount(Math.max(badge.getReusableCount() - 1, 0));}
if (category.equals(Category.PLASTIC)) { badge.setPlasticCount(Math.max(badge.getPlasticCount() - 1, 0));}
if (category.equals(Category.PLOGGING)) { badge.setPloggingCount(Math.max(badge.getPloggingCount() - 1, 0));}
if (category.equals(Category.REFORM)) { badge.setReformCount(Math.max(badge.getReformCount() - 1, 0));}
if (category.equals(Category.TRANSPORT)) { badge.setTransportCount(Math.max(badge.getTransportCount() - 1, 0));}
if (category.equals(Category.ETC)) { badge.setEtcCount(Math.max(badge.getEtcCount() - 1, 0));}
if (category.equals(Category.QUESTION)) { badge.setMentorCount(Math.max(badge.getMentorCount() - 1, 0));}
}
updateIsAchieved(badge);
}



Expand Down Expand Up @@ -152,10 +197,12 @@ public List<GetPostInfoResponseDto> getPostlist(Category category, Tag tag) {
List<GetPostInfoResponseDto> postList = new ArrayList<>();

for (Post post : posts) {
/*
if (post.getTag() != Tag.DAILY || !post.getCategory().equals(category)) {
continue;
}
*/

Member member = post.getMember();
List<Likes> likeList = post.getLikes();
Expand Down Expand Up @@ -191,8 +238,12 @@ public List<GetPostInfoResponseDto> getPostlist(Category category, Tag tag) {
public void deletePost(Long postId) {
Member member = memberService.getCurrentMember();
Post post = postRepository.findById(postId).orElseThrow(PostNotFound::new);
Badge badge = badgeRepository.findByMember(member);

// 게시글 삭제
postRepository.delete(post);
decreaseBadgeCount(badge, post.getCategory(), post.getTag());

}

//게시글 수정하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Badge extends AuditEntity {

@Column(name="earlybird_count",columnDefinition = "int default 0" )
private int earlybirdCount;
@Column(name="ealrybird_is_achieved",columnDefinition = "boolean default false")
@Column(name="earlybird_is_achieved",columnDefinition = "boolean default false")
private boolean earlybirdIsAchieved;

@Column(name="mentor_count",columnDefinition = "int default 0")
Expand Down

0 comments on commit ae062b8

Please sign in to comment.