Skip to content

Commit

Permalink
Merge pull request #45 from Team-Wable/feat/#44
Browse files Browse the repository at this point in the history
[FEAT] 밴기능 개발
  • Loading branch information
Hong0329 authored Nov 16, 2024
2 parents ed03f0b + b40eb51 commit d136cad
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class Comment extends BaseTimeEntity {
@OneToMany(mappedBy = "comment", cascade = CascadeType.REMOVE)
private List<CommentLiked> commentLikeds = new ArrayList<>();

@Column(name = "is_blind", columnDefinition = "BOOLEAN DEFAULT false")
private boolean isBlind;

@Builder
public Comment(Member member, Content content, String commentText) {
this.member = member;
Expand All @@ -60,4 +63,8 @@ public void softDelete() {
this.isDeleted = true;
this.deleteAt = LocalDateTime.now().plusDays(COMMENT_RETENTION_PERIOD);
}

public void blindComment() {
this.isBlind = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ public void softDelete() {
this.isDeleted = true;
this.deleteAt = LocalDateTime.now().plusDays(CONTENT_RETENTION_PERIOD);
}

public void blindContent() {
this.isBlind = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class Member extends BaseTimeEntity {
@OneToMany(mappedBy = "reportTargetMember", cascade = ALL)
private List<Report> targetReport = new ArrayList<>();

@Column(name = "member_ban_count", columnDefinition = "INT DEFAULT 0")
private int memberBanCount;

@Builder
private Member(String nickname, SocialPlatform socialPlatform, String socialId, String profileUrl, String memberEmail, String socialNickname) {
this.nickname = nickname;
Expand All @@ -112,6 +115,7 @@ private Member(String nickname, SocialPlatform socialPlatform, String socialId,
this.memberFanTeam = "";
this.memberLckYears = 0;
this.memberExp = 0;
this.memberBanCount = 0;
}

public void decreaseGhost() {
Expand Down Expand Up @@ -166,4 +170,6 @@ public void softDelete() {
public void increaseExpPostComment() { this.memberExp += 1.0;}

public void increaseExpPostLike() { this.memberExp += 0.6;}

public void banMember() {this.memberBanCount += 1;}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wable.www.WableServer.api.report.controller;

import com.wable.www.WableServer.api.report.dto.BanRequestDto;
import com.wable.www.WableServer.api.report.dto.ReportSlackRequestDto;
import com.wable.www.WableServer.api.report.service.ReportCommandService;
import com.wable.www.WableServer.common.response.ApiResponse;
import com.wable.www.WableServer.common.util.MemberUtil;
import com.wable.www.WableServer.external.slack.service.SlackService;
Expand All @@ -13,6 +15,7 @@

import java.security.Principal;

import static com.wable.www.WableServer.common.response.SuccessStatus.BAN_MEMBER_SUCCESS;
import static com.wable.www.WableServer.common.response.SuccessStatus.REPORT_SLACK_ALARM_SUCCESS;


Expand All @@ -23,6 +26,7 @@
@Tag(name="신고 관련",description = "Report Api Document")
public class ReportController {
private final SlackService slackService;
private final ReportCommandService reportCommandService;

@PostMapping("report/slack")
@Operation(summary = "신고 시에 슬랙 알림 API입니다.",description = "ReportSlack")
Expand All @@ -31,4 +35,11 @@ public ResponseEntity<ApiResponse<Object>> SlackReportMember(Principal principal
slackService.sendReportSlackMessage(memberId, reportSlackRequestDto);
return ApiResponse.success(REPORT_SLACK_ALARM_SUCCESS);
}

@PostMapping("report/ban")
@Operation(summary = "사용자 밴 기능.",description = "MemberBan")
public ResponseEntity<ApiResponse<Object>> banMember(Principal principal, @RequestBody BanRequestDto banRequestDto) {
reportCommandService.blindText(banRequestDto);
return ApiResponse.success(BAN_MEMBER_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wable.www.WableServer.api.report.dto;

public record BanRequestDto(
Long memberId,
String triggerType,
Long triggerId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.wable.www.WableServer.api.report.service;

import com.wable.www.WableServer.api.comment.domain.Comment;
import com.wable.www.WableServer.api.comment.repository.CommentRepository;
import com.wable.www.WableServer.api.content.domain.Content;
import com.wable.www.WableServer.api.content.repository.ContentRepository;
import com.wable.www.WableServer.api.member.domain.Member;
import com.wable.www.WableServer.api.member.repository.MemberRepository;
import com.wable.www.WableServer.api.report.dto.BanRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
@Transactional
public class ReportCommandService {
private final CommentRepository commentRepository;
private final ContentRepository contentRepository;
private final MemberRepository memberRepository;

public void blindText(BanRequestDto banRequestDto) {
Member member = memberRepository.findMemberByIdOrThrow(banRequestDto.memberId());
if(banRequestDto.triggerType().equals("content")) {
if(member.getMemberBanCount() == 0) {
Content content = contentRepository.findContentByIdOrThrow(banRequestDto.triggerId());
content.blindContent();
member.banMember();
}
else {
blindAllByMember(member);
member.banMember();
}
}
else {
if(member.getMemberBanCount() == 0) {
Comment comment = commentRepository.findCommentByIdOrThrow(banRequestDto.triggerId());
comment.blindComment();
member.banMember();
}
else {
blindAllByMember(member);
member.banMember();
}
}
}

private void blindAllByMember(Member member) {
List<Content> memberContents = contentRepository.findContentByMember(member);
for (Content content : memberContents) {
content.blindContent();
}

List<Comment> memberComments = commentRepository.findAllByMember(member);
for (Comment comment : memberComments) {
comment.blindComment();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public enum SuccessStatus {
* report
*/
REPORT_SLACK_ALARM_SUCCESS(HttpStatus.CREATED, "신고 관련 슬랙 알림 발생 성공"),
BAN_MEMBER_SUCCESS(HttpStatus.CREATED, "블라인드 처리 및 밴처리 성공"),
/**
* Lck Game
*/
Expand Down

0 comments on commit d136cad

Please sign in to comment.