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

[FEAT] add 방 신고 API without redis logic #706

Merged
merged 4 commits into from
Mar 7, 2024
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
7 changes: 7 additions & 0 deletions gg-data/src/main/java/gg/data/party/RoomReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public class RoomReport extends BaseTimeEntity {

@Column(length = 100)
private String message;

public RoomReport(User reporter, User reportee, Room room, String message) {
this.reporter = reporter;
this.reportee = reportee;
this.room = room;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
package gg.pingpong.api.party.user.report.controller;
package gg.party.api.user.report.controller;

import javax.validation.Valid;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.party.api.user.report.request.ReportRoomReqDto;
import gg.party.api.user.report.service.ReportService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/reports")
public class ReportController {
private final ReportService reportService;

/**
* 방을 신고한다.
* @param reportRoomReqDto 신고 내용
* @param roomId 방 번호
* @return 참여중인 방 전체 List
*/
@PostMapping("/rooms/{room_id}")
public ResponseEntity<Long> reportRoomAdd(@PathVariable("room_id") Long roomId,
@RequestBody @Valid ReportRoomReqDto reportRoomReqDto,
@Parameter(hidden = true) @Login UserDto user) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(reportService.addReportRoom(roomId, reportRoomReqDto, user));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gg.party.api.user.report.request;

import javax.validation.constraints.Size;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class ReportRoomReqDto {
@Size(min = 1, max = 200)
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gg.party.api.user.report.service;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import gg.auth.UserDto;
import gg.data.party.Room;
import gg.data.party.RoomReport;
import gg.data.party.type.RoomType;
import gg.data.user.User;
import gg.party.api.user.report.request.ReportRoomReqDto;
import gg.repo.party.RoomReportRepository;
import gg.repo.party.RoomRepository;
import gg.repo.party.UserRoomRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.party.AlredayReportedRoomException;
import gg.utils.exception.party.RoomNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ReportService {
private final RoomRepository roomRepository;
private final UserRepository userRepository;
private final UserRoomRepository userRoomRepository;
private final RoomReportRepository roomReportRepository;

/**
* 방을 신고한다.
* @param roomId 방 번호
* @param reportRoomReqDto 신고 내용
* @param user 신고자
* @exception RoomNotFoundException 방을 찾을 수 없음
* @exception AlredayReportedRoomException 이미 신고한 방
* @return 방 번호
*/
@Transactional
public Long addReportRoom(Long roomId, ReportRoomReqDto reportRoomReqDto, UserDto user) {
Room targetRoom = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);
User userEntity = userRepository.findById(user.getId()).get();
Optional<RoomReport> existingReport = roomReportRepository.findByReporterAndRoomId(userEntity,
targetRoom.getId());
if (existingReport.isPresent()) {
throw new AlredayReportedRoomException();
}
RoomReport roomReport = new RoomReport(userEntity, targetRoom.getCreator(), targetRoom,
reportRoomReqDto.getContent());
roomReportRepository.save(roomReport);

List<RoomReport> allReportRoom = roomReportRepository.findByRoomId(targetRoom.getId());
if (allReportRoom.size() == 3) {
targetRoom.updateStatus(RoomType.HIDDEN);
roomRepository.save(targetRoom);
}
// 사용자 정지
//partyGivePenalty(targetRoom.getCreator().getIntraId(), 24, "신고 3회 이상");
return roomId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// package gg.party.api.user.report.utils;
//
// import java.time.LocalDateTime;
// import java.util.Optional;
//
// import org.springframework.transaction.annotation.Transactional;
//
// import gg.data.manage.Penalty;
// import gg.data.manage.redis.RedisPenaltyUser;
// import gg.data.manage.type.PenaltyType;
// import gg.data.user.User;
// import gg.repo.user.UserRepository;
//
// public class PartyGivePenalty {
//
// private final UserRepository userRepository;
//
// public PartyGivePenalty(UserRepository userRepository) {
// this.userRepository = userRepository;
// }
//
// /**
// * 패널티 부여
// * @param reporteeId 신고당한 유저 아이디
// * @param roomId 방 번호
// */
// @Transactional
// public void partyGivePenalty(String intraId, Integer penaltyTime, String reason) {
// User user = userRepository.findByIntraId(intraId).get();
// Optional<RedisPenaltyUser> redisPenaltyUser = penaltyUserAdminRedisRepository.findByIntraId(intraId);
// LocalDateTime releaseTime;
// RedisPenaltyUser penaltyUser;
// Penalty penalty;
// LocalDateTime now = LocalDateTime.now();
// if (redisPenaltyUser.isPresent()) {
// releaseTime = redisPenaltyUser.get().getReleaseTime().plusHours(penaltyTime);
// penaltyUser = new RedisPenaltyUser(intraId, redisPenaltyUser.get().getPenaltyTime() + penaltyTime * 60,
// releaseTime, redisPenaltyUser.get().getStartTime(), reason);
// penalty = new Penalty(user, PenaltyType.NOSHOW, reason, redisPenaltyUser.get().getReleaseTime(),
// penaltyTime * 60);
// } else {
// releaseTime = now.plusHours(penaltyTime);
// penaltyUser = new RedisPenaltyUser(intraId, penaltyTime * 60, releaseTime, now, reason);
// penalty = new Penalty(user, PenaltyType.NOSHOW, reason, now, penaltyTime * 60);
// }
// penaltyRepository.save(penalty);
// penaltyUserAdminRedisRepository.addPenaltyUser(penaltyUser, releaseTime);
// }
// }
15 changes: 15 additions & 0 deletions gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gg.repo.party;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import gg.data.party.RoomReport;
import gg.data.user.User;

public interface RoomReportRepository extends JpaRepository<RoomReport, Long> {
public List<RoomReport> findByRoomId(Long roomId);

public Optional<RoomReport> findByReporterAndRoomId(User reporter, Long roomId);
}
4 changes: 2 additions & 2 deletions gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public enum ErrorCode {
ROOM_SAME_STATUS(400, "PT204", "이미 처리된 방 입니다."),
ROOM_NOT_OPEN(400, "PT205", "모집중인 방이 아닙니다."),
ROOM_NOT_PARTICIPANT(400, "PT206", "참여하지 않은 방 입니다."),
USER_ALREADY_IN_ROOM(409, "PT301", "이미 참여한 방 입니다.");

USER_ALREADY_IN_ROOM(409, "PT301", "이미 참여한 방 입니다."),
ALREADY_REPORTED_ROOM(409, "PT302", "이미 신고한 방 입니다.");

private final int status;
private final String errCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gg.utils.exception.party;

import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.DuplicationException;

public class AlredayReportedRoomException extends DuplicationException {
public AlredayReportedRoomException() {
super(ErrorCode.ALREADY_REPORTED_ROOM.getMessage(), ErrorCode.ALREADY_REPORTED_ROOM);
}
}
Loading