-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] add 방 신고 API without redis logic (#706)
- Loading branch information
Showing
8 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 33 additions & 1 deletion
34
gg-pingpong-api/src/main/java/gg/party/api/user/report/controller/ReportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
gg-pingpong-api/src/main/java/gg/party/api/user/report/request/ReportRoomReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
64 changes: 64 additions & 0 deletions
64
gg-pingpong-api/src/main/java/gg/party/api/user/report/service/ReportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
gg-pingpong-api/src/main/java/gg/party/api/user/report/utils/PartyGivePenalty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
gg-utils/src/main/java/gg/utils/exception/party/AlredayReportedRoomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |