Skip to content

Commit

Permalink
๐Ÿ› [Bug] ๋ฐฉ ์ƒ์„ฑ์‹œ ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ํ”„๋ก ํŠธ์—์„œ ๋ฐ›์ง€ ๋ชปํ•˜๋Š” ๋ฒ„๊ทธ (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Mar 28, 2024
1 parent d2117ee commit 6613d12
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CategoryService {
@Transactional(readOnly = true)
public CategoryListResDto findCategoryList(UserDto userDto) {
User user = userRepository.findById(userDto.getId()).get();
PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId());
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void addCreateComment(Long roomId, CommentCreateReqDto reqDto, Long userI
throw new RoomNotOpenException();
}

PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(userId);
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(userId);
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void addReportUser(Long roomId, ReportReqDto reportReqDto, String userInt
@Transactional
public void partyGivePenalty(String intraId, Integer penaltyTime, String penaltyType) {
User user = userRepository.findByIntraId(intraId).get();
PartyPenalty pPenalty = partyPenaltyRepository.findLatestByUserId(user.getId());
PartyPenalty pPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());

if (pPenalty != null && LocalDateTime.now().isBefore(pPenalty.getStartTime()
.plusMinutes(pPenalty.getPenaltyTime()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class RoomManagementService {
@Transactional
public RoomCreateResDto addCreateRoom(RoomCreateReqDto roomCreateReqDto, UserDto userDto) {
User user = userRepository.findById(userDto.getId()).get();
PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId());
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public RoomStartResDto modifyStartRoom(Long roomId, UserDto user) {
public RoomJoinResDto addJoinRoom(Long roomId, UserDto userDto) {
User user = userRepository.findById(userDto.getId()).get();
Room room = roomRepository.findById(roomId).orElseThrow(RoomNotFoundException::new);
PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId());
PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId());
if (PartyPenalty.isOnPenalty(partyPenalty)) {
throw new OnPenaltyException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,28 @@ public class CategoryControllerTest {
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 @@ -82,6 +91,22 @@ void success() throws Exception {
assertThat(clrd.getCategoryList().size()).isEqualTo(10);
}

@Test
@DisplayName("์นดํ…Œ๊ณ ๋ฆฌ ๋ชฉ๋ก ์กฐํšŒ ์„ฑ๊ณต 200")
void unLockPenaltySuccess() throws Exception {
//given
String uri = "/party/categories";
//when
String contentAsString = mockMvc.perform(get(uri)
.header("Authorization", "Bearer " + anotherAccessToken)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
//then
CategoryListResDto clrd = objectMapper.readValue(contentAsString, CategoryListResDto.class);
assertThat(clrd.getCategoryList().size()).isEqualTo(10);
}

@Test
@DisplayName("ํŒจ๋„ํ‹ฐ ์ƒํƒœ์˜ ์œ ์ € ์นดํ…Œ๊ณ ๋ฆฌ ๋ชฉ๋ก ์กฐํšŒ ์‹คํŒจ 403")
void penaltyUserFail() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import gg.data.party.PartyPenalty;

public interface PartyPenaltyRepository extends JpaRepository<PartyPenalty, Long> {
@Query("SELECT p FROM PartyPenalty p WHERE p.user.id = :userId ORDER BY p.startTime DESC")
PartyPenalty findLatestByUserId(@Param("userId") Long userId);
PartyPenalty findTopByUserIdOrderByStartTimeDesc(@Param("userId") Long userId);

List<PartyPenalty> findAllByUserId(Long userId);

Expand Down

0 comments on commit 6613d12

Please sign in to comment.