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

πŸ”¨ [Refactoring + Feature] νŒ¨λ„ν‹° 확인 API μž‘μ„± 및 νŒ¨λ„ν‹° μ •μ±… μˆ˜μ • #790 #791

Merged
merged 10 commits into from
Mar 30, 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
19 changes: 0 additions & 19 deletions gg-data/src/main/java/gg/data/party/type/RoomType.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package gg.data.party.type;

import java.util.Locale;

import com.fasterxml.jackson.annotation.JsonCreator;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -18,19 +14,4 @@ public enum RoomType {

private final String code;
private final String desc;

@JsonCreator
public static RoomType getEnumFromValue(String value) {
if (value == null) {
return null;
}
for (RoomType e : values()) {
if (e.name().equals(value)) {
return e;
} else if (e.code.toUpperCase(Locale.ROOT).equals(value.toUpperCase(Locale.ROOT))) {
return e;
}
}
return null;
}
}
2,728 changes: 2,728 additions & 0 deletions gg-pingpong-api/logs/error.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
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.category.controller.response.CategoryListResDto;
import gg.party.api.user.category.service.CategoryService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
Expand All @@ -24,7 +21,7 @@ public class CategoryController {
* @return μΉ΄ν…Œκ³ λ¦¬ 전체 리슀트
*/
@GetMapping
public ResponseEntity<CategoryListResDto> categoryList(@Parameter(hidden = true) @Login UserDto user) {
return ResponseEntity.status(HttpStatus.OK).body(categoryService.findCategoryList(user));
public ResponseEntity<CategoryListResDto> categoryList() {
return ResponseEntity.status(HttpStatus.OK).body(categoryService.findCategoryList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,22 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.auth.UserDto;
import gg.data.party.PartyPenalty;
import gg.data.user.User;
import gg.party.api.user.category.controller.response.CategoryListResDto;
import gg.party.api.user.category.controller.response.CategoryResDto;
import gg.repo.party.CategoryRepository;
import gg.repo.party.PartyPenaltyRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.party.OnPenaltyException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class CategoryService {
private final CategoryRepository categoryRepository;
private final PartyPenaltyRepository partyPenaltyRepository;
private final UserRepository userRepository;

/**
* μΉ΄ν…Œκ³ λ¦¬ 전체 쑰회
* @throws OnPenaltyException νŒ¨λ„ν‹° μƒνƒœμ˜ μœ μ € μž…λ ₯ - 403
* @return μΉ΄ν…Œκ³ λ¦¬ 전체 리슀트 (id 순으둜 μ˜€λ¦„μ°¨μˆœ μ •λ ¬)
*/
@Transactional(readOnly = true)
public CategoryListResDto findCategoryList(UserDto userDto) {
User user = userRepository.findById(userDto.getId()).get();
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
public CategoryListResDto findCategoryList() {
return new CategoryListResDto(categoryRepository.findAll(Sort.by(Sort.Direction.ASC, "id")).stream()
.map(CategoryResDto::new)
.collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gg.party.api.user.penalty.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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.penalty.controller.response.PenaltyResDto;
import gg.party.api.user.penalty.service.PartyPenaltyService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/penalty")
public class PartyPenaltyController {
private final PartyPenaltyService partyPenaltyService;

/**
* ν˜„μž¬ μœ μ €κ°€ νŒ¨λ„ν‹° μƒνƒœμΈμ§€ 쑰회
* @return μ–Έμ œκΉŒμ§€ νŒ¨λ„ν‹°μΈμ§€ DateTime으둜 리턴
*/
@GetMapping
public ResponseEntity<PenaltyResDto> findPenalty(@Parameter(hidden = true) @Login UserDto user) {
return ResponseEntity.status(HttpStatus.OK).body(partyPenaltyService.findIsPenalty(user));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gg.party.api.user.penalty.controller.response;

import java.time.LocalDateTime;

import gg.data.party.PartyPenalty;
import lombok.Getter;

@Getter
public class PenaltyResDto {
private LocalDateTime penaltyEndTime;

public PenaltyResDto(PartyPenalty partyPenalty) {
this.penaltyEndTime = partyPenalty.getStartTime().plusMinutes(partyPenalty.getPenaltyTime());
}

public PenaltyResDto() {
this.penaltyEndTime = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gg.party.api.user.penalty.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.auth.UserDto;
import gg.data.party.PartyPenalty;
import gg.party.api.user.penalty.controller.response.PenaltyResDto;
import gg.repo.party.PartyPenaltyRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class PartyPenaltyService {
private final PartyPenaltyRepository partyPenaltyRepository;

/**
* ν˜„μž¬ μœ μ €κ°€ νŒ¨λ„ν‹° μƒνƒœμΈμ§€ 쑰회
* @return μ–Έμ œκΉŒμ§€ νŒ¨λ„ν‹°μΈμ§€ DateTime으둜 리턴
*/
@Transactional
public PenaltyResDto findIsPenalty(UserDto userDto) {
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(userDto.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
return new PenaltyResDto(partyPenalty);
} else {
return new PenaltyResDto();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import gg.repo.party.UserReportRepository;
import gg.repo.party.UserRoomRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.party.AlredayReportedException;
import gg.utils.exception.party.AlreadyReportedException;
import gg.utils.exception.party.CommentNotFoundException;
import gg.utils.exception.party.OnPenaltyException;
import gg.utils.exception.party.RoomNotFoundException;
import gg.utils.exception.party.RoomNotParticipantException;
import gg.utils.exception.party.SelfReportException;
Expand Down Expand Up @@ -57,12 +58,17 @@ public class ReportService {
* @param reportReqDto μ‹ κ³  λ‚΄μš©
* @param user μ‹ κ³ μž
* @return 방 번호
* @throws OnPenaltyException νŒ¨λ„ν‹° μƒνƒœμ˜ μœ μ € μž…λ ₯ - 403
* @throws RoomNotFoundException 방을 찾을 수 μ—†μŒ - 404
* @throws AlredayReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws AlreadyReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws SelfReportException μžμ‹ μ„ μ‹ κ³ ν•œ 경우 - 400
*/
@Transactional
public void addReportRoom(Long roomId, ReportReqDto reportReqDto, UserDto user) {
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Room targetRoom = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);
User userEntity = userRepository.findById(user.getId()).get();
Expand All @@ -72,14 +78,14 @@ public void addReportRoom(Long roomId, ReportReqDto reportReqDto, UserDto user)
Optional<RoomReport> existingReport = roomReportRepository.findByReporterAndRoomId(userEntity,
targetRoom.getId());
if (existingReport.isPresent()) {
throw new AlredayReportedException();
throw new AlreadyReportedException();
}
RoomReport roomReport = new RoomReport(userEntity, targetRoom.getCreator(), targetRoom,
reportReqDto.getContent());
roomReportRepository.save(roomReport);

List<RoomReport> allReportRoom = roomReportRepository.findByRoomId(targetRoom.getId());
if (allReportRoom.size() == 3) {
if (allReportRoom.size() == 5) {
targetRoom.updateRoomStatus(RoomType.HIDDEN);
roomRepository.save(targetRoom);
User targetUser = targetRoom.getCreator();
Expand All @@ -89,17 +95,22 @@ public void addReportRoom(Long roomId, ReportReqDto reportReqDto, UserDto user)

/**
* λŒ“κΈ€μ„ μ‹ κ³ ν•œλ‹€.
*
* @param commentId 방 번호
* @param commentId 방 번호
* @param reportReqDto μ‹ κ³  λ‚΄μš©
* @param user μ‹ κ³ μž
* @param user μ‹ κ³ μž
* @return 방 번호
* @throws CommentNotFoundException 방을 찾을 수 μ—†μŒ - 404
* @throws AlredayReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws OnPenaltyException νŒ¨λ„ν‹° μƒνƒœμ˜ μœ μ € μž…λ ₯ - 403
* @throws RoomNotFoundException 방을 찾을 수 μ—†μŒ - 404
* @throws CommentNotFoundException λŒ“κΈ€μ„ 찾을 수 μ—†μŒ - 404
* @throws AlreadyReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws SelfReportException μžμ‹ μ„ μ‹ κ³ ν•œ 경우 - 400
*/
@Transactional
public void addReportComment(Long commentId, ReportReqDto reportReqDto, UserDto user) {
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Comment targetComment = commentRepository.findById(commentId)
.orElseThrow(CommentNotFoundException::new);
User userEntity = userRepository.findById(user.getId()).get();
Expand All @@ -109,7 +120,7 @@ public void addReportComment(Long commentId, ReportReqDto reportReqDto, UserDto
Optional<CommentReport> existingReport = commentReportRepository.findByReporterAndCommentId(userEntity,
targetComment.getId());
if (existingReport.isPresent()) {
throw new AlredayReportedException();
throw new AlreadyReportedException();
}
Room targetRoom = roomRepository.findById(targetComment.getRoom().getId())
.orElseThrow(RoomNotFoundException::new);
Expand All @@ -128,16 +139,15 @@ public void addReportComment(Long commentId, ReportReqDto reportReqDto, UserDto

/**
* μœ μ € λ…Έμ‡Ό μ‹ κ³ ν•œλ‹€.
*
* @param roomId 방 번호
* @param roomId 방 번호
* @param reportReqDto μ‹ κ³  λ‚΄μš©
* @param user μ‹ κ³ μž
* @param userIntraId ν”Όμ‹ κ³ μž
* @param user μ‹ κ³ μž
* @param userIntraId ν”Όμ‹ κ³ μž
* @return 방 번호
* @throws CommentNotFoundException 방을 찾을 수 μ—†μŒ - 404
* @throws AlredayReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws SelfReportException μžμ‹ μ„ μ‹ κ³ ν•œ 경우 - 400
* @throws AlreadyReportedException 이미 μ‹ κ³ ν•œ 경우 - 409
* @throws RoomNotParticipantException 방에 μ°Έμ—¬ν•˜μ§€ μ•Šμ€ 경우 - 400
* @throws SelfReportException μžμ‹ μ„ μ‹ κ³ ν•œ 경우 - 400
*/
@Transactional
public void addReportUser(Long roomId, ReportReqDto reportReqDto, String userIntraId, UserDto user) {
Expand All @@ -158,25 +168,23 @@ public void addReportUser(Long roomId, ReportReqDto reportReqDto, String userInt
throw new RoomNotFoundException();
}
// 이미 μ‹ κ³ ν•œ 경우
userReportRepository.findByReporterAndReporteeAndRoom(
reporterEntity, reporteeEntity, targetRoom)
userReportRepository.findByReporterAndReporteeAndRoom(reporterEntity, reporteeEntity, targetRoom)
.ifPresent(userReport -> {
throw new AlredayReportedException();
throw new AlreadyReportedException();
});
// μ‹ κ³  μ €μž₯
UserReport userReport = new UserReport(reporterEntity, reporteeEntity, targetRoom, reportReqDto.getContent());
userReportRepository.save(userReport);
// λ…Έμ‡Ό νŒ¨λ„ν‹° νŒλ‹¨
List<UserReport> allReportUser = userReportRepository.findByReporteeAndRoomId(reporteeEntity, roomId);
if (allReportUser.size() == targetRoom.getMaxPeople() / 2) {
if (allReportUser.size() == targetRoom.getCurrentPeople() / 2) {
partyGivePenalty(reporteeEntity.getIntraId(), NO_SHOW_PENALTY_TIME, "λ…Έμ‡Ό νŒ¨λ„ν‹°");
}
}

/**
* νŒ¨λ„ν‹° λΆ€μ—¬
*
* @param intraId μ‹ κ³ λ‹Ήν•œ μœ μ € 아이디
* @param intraId μ‹ κ³ λ‹Ήν•œ μœ μ € 아이디
* @param penaltyTime νŒ¨λ„ν‹° μ‹œκ°„
* @param penaltyType νŒ¨λ„ν‹° νƒ€μž…
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,21 @@ public class CategoryControllerTest {
@Autowired
private AuthTokenProvider tokenProvider;
User userTester;
User reportedTester;
User anotherTester;
String userAccessToken;
String reportedAccessToken;
String anotherAccessToken;

@BeforeEach
void beforeEach() {
userTester = testDataUtils.createNewUser("commentUserTester", "emailTester",
RacketType.DUAL, SnsType.SLACK, RoleType.USER);
reportedTester = testDataUtils.createNewUser("reportedTester", "reportedTester",
RacketType.DUAL, SnsType.SLACK, RoleType.USER);
anotherTester = testDataUtils.createNewUser("anotherUserTester", "anotherUserTester",
RacketType.DUAL, SnsType.SLACK, RoleType.USER);
testDataUtils.createNewPenalty(reportedTester, "test", "test",
LocalDateTime.now(), 60);
testDataUtils.createNewPenalty(anotherTester, "test1", "test1",
LocalDateTime.now(), 0);
testDataUtils.createNewPenalty(anotherTester, "test2", "test2",
LocalDateTime.now(), 0);
userAccessToken = tokenProvider.createToken(userTester.getId());
reportedAccessToken = tokenProvider.createToken(reportedTester.getId());
anotherAccessToken = tokenProvider.createToken(anotherTester.getId());
for (int i = 0; i < 10; i++) {
testDataUtils.createNewCategory("ν…ŒμŠ€νŠΈ μΉ΄ν…Œκ³ λ¦¬" + i);
Expand All @@ -92,7 +85,7 @@ void success() throws Exception {
}

@Test
@DisplayName("μΉ΄ν…Œκ³ λ¦¬ λͺ©λ‘ 쑰회 성곡 200")
@DisplayName("νŒ¨λ„ν‹° λ°›μ•˜λ‹€κ°€ ν’€λ¦° μœ μ € μΉ΄ν…Œκ³ λ¦¬ λͺ©λ‘ 쑰회 성곡 200")
void unLockPenaltySuccess() throws Exception {
//given
String uri = "/party/categories";
Expand All @@ -106,17 +99,5 @@ void unLockPenaltySuccess() throws Exception {
CategoryListResDto clrd = objectMapper.readValue(contentAsString, CategoryListResDto.class);
assertThat(clrd.getCategoryList().size()).isEqualTo(10);
}

@Test
@DisplayName("νŒ¨λ„ν‹° μƒνƒœμ˜ μœ μ € μΉ΄ν…Œκ³ λ¦¬ λͺ©λ‘ 쑰회 μ‹€νŒ¨ 403")
void penaltyUserFail() throws Exception {
//given
String uri = "/party/categories";
//when && then
mockMvc.perform(get(uri)
.header("Authorization", "Bearer " + reportedAccessToken)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isForbidden());
}
}
}
Loading
Loading