Skip to content

Commit

Permalink
refactor: 방 컨트롤러 @CurrentMember 적용, 통합 테스트 리팩토링 (#89)
Browse files Browse the repository at this point in the history
* feat: 방장 위임 기능 구현

* test: 방장 위임 기능 테스트 작성

* test: 방장이 아닌 유저의 요청인 경우 추가

* feat: participant deletedAt null일때 찾도록 추가

* feat: 방 추방 기능 구현

* test: 방 추방 통합 테스트 구현

* refactor: nginx conf 수정

* refactor: nginx conf 추가 수정

* refactor: BugSearchRepository 위치 변경

* refactor: RoomController @CurrentMember 적용

* refactor: 메서드명 변경

* refactor: 테스트 코드 리팩토링

* refactor: 테스트 패키지 구조 변경
  • Loading branch information
ymkim97 authored Nov 15, 2023
1 parent 1d63d81 commit c28a033
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.moabam.api.application.member.MemberService;
import com.moabam.api.domain.bug.BugHistory;
import com.moabam.api.domain.bug.BugType;
import com.moabam.api.domain.bug.repository.BugHistorySearchRepository;
import com.moabam.api.domain.member.Member;
import com.moabam.api.domain.repository.BugHistorySearchRepository;
import com.moabam.api.dto.TodayBugResponse;
import com.moabam.api.dto.bug.BugResponse;
import com.moabam.global.common.util.ClockHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public RoomDetailsResponse getRoomDetails(Long memberId, Long roomId) {
}

private List<RoutineResponse> getRoutineResponses(Long roomId) {
List<Routine> roomRoutines = routineSearchRepository.findByRoomId(roomId);
List<Routine> roomRoutines = routineSearchRepository.findAllByRoomId(roomId);

return RoutineMapper.toRoutineResponses(roomRoutines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void modifyRoom(Long memberId, Long roomId, ModifyRoomRequest modifyRoomR
room.changeCertifyTime(modifyRoomRequest.certifyTime());
room.changeMaxCount(modifyRoomRequest.maxUserCount());

List<Routine> routines = routineSearchRepository.findByRoomId(roomId);
List<Routine> routines = routineSearchRepository.findAllByRoomId(roomId);
routineRepository.deleteAll(routines);

List<Routine> newRoutines = RoutineMapper.toRoutineEntities(room, modifyRoomRequest.routines());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moabam.api.domain.repository;
package com.moabam.api.domain.bug.repository;

import static com.moabam.api.domain.bug.QBugHistory.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RoutineSearchRepository {

private final JPAQueryFactory jpaQueryFactory;

public List<Routine> findByRoomId(Long roomId) {
public List<Routine> findAllByRoomId(Long roomId) {
return jpaQueryFactory
.selectFrom(routine)
.where(
Expand Down
49 changes: 32 additions & 17 deletions src/main/java/com/moabam/api/presentation/RoomController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.moabam.api.dto.room.EnterRoomRequest;
import com.moabam.api.dto.room.ModifyRoomRequest;
import com.moabam.api.dto.room.RoomDetailsResponse;
import com.moabam.global.auth.annotation.CurrentMember;
import com.moabam.global.auth.model.AuthorizationMember;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -37,50 +39,63 @@ public class RoomController {

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Long createRoom(@Valid @RequestBody CreateRoomRequest createRoomRequest) {
return roomService.createRoom(1L, createRoomRequest);
public Long createRoom(@CurrentMember AuthorizationMember authorizationMember,
@Valid @RequestBody CreateRoomRequest createRoomRequest) {

return roomService.createRoom(authorizationMember.id(), createRoomRequest);
}

@PutMapping("/{roomId}")
@ResponseStatus(HttpStatus.OK)
public void modifyRoom(@Valid @RequestBody ModifyRoomRequest modifyRoomRequest,
@PathVariable("roomId") Long roomId) {
roomService.modifyRoom(1L, roomId, modifyRoomRequest);
public void modifyRoom(@CurrentMember AuthorizationMember authorizationMember,
@Valid @RequestBody ModifyRoomRequest modifyRoomRequest, @PathVariable("roomId") Long roomId) {

roomService.modifyRoom(authorizationMember.id(), roomId, modifyRoomRequest);
}

@PostMapping("/{roomId}")
@ResponseStatus(HttpStatus.OK)
public void enterRoom(@PathVariable("roomId") Long roomId, @Valid @RequestBody EnterRoomRequest enterRoomRequest) {
roomService.enterRoom(1L, roomId, enterRoomRequest);
public void enterRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId,
@Valid @RequestBody EnterRoomRequest enterRoomRequest) {

roomService.enterRoom(authorizationMember.id(), roomId, enterRoomRequest);
}

@DeleteMapping("/{roomId}")
@ResponseStatus(HttpStatus.OK)
public void exitRoom(@PathVariable("roomId") Long roomId) {
roomService.exitRoom(1L, roomId);
public void exitRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId) {
roomService.exitRoom(authorizationMember.id(), roomId);
}

@GetMapping("/{roomId}")
@ResponseStatus(HttpStatus.OK)
public RoomDetailsResponse getRoomDetails(@PathVariable("roomId") Long roomId) {
return roomSearchService.getRoomDetails(1L, roomId);
public RoomDetailsResponse getRoomDetails(@CurrentMember AuthorizationMember authorizationMember,
@PathVariable("roomId") Long roomId) {

return roomSearchService.getRoomDetails(authorizationMember.id(), roomId);
}

@PostMapping("/{roomId}/certification")
@ResponseStatus(HttpStatus.CREATED)
public void certifyRoom(@PathVariable("roomId") Long roomId, @RequestPart List<MultipartFile> multipartFiles) {
roomCertificationService.certifyRoom(1L, roomId, multipartFiles);
public void certifyRoom(@CurrentMember AuthorizationMember authorizationMember, @PathVariable("roomId") Long roomId,
@RequestPart List<MultipartFile> multipartFiles) {

roomCertificationService.certifyRoom(authorizationMember.id(), roomId, multipartFiles);
}

@PutMapping("/{roomId}/members/{memberId}/mandate")
@ResponseStatus(HttpStatus.OK)
public void mandateManager(@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) {
roomService.mandateRoomManager(1L, roomId, memberId);
public void mandateManager(@CurrentMember AuthorizationMember authorizationMember,
@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) {

roomService.mandateRoomManager(authorizationMember.id(), roomId, memberId);
}

@DeleteMapping("/{roomId}/members/{memberId}")
@ResponseStatus(HttpStatus.OK)
public void deportParticipant(@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) {
roomService.deportParticipant(1L, roomId, memberId);
public void deportParticipant(@CurrentMember AuthorizationMember authorizationMember,
@PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) {

roomService.deportParticipant(authorizationMember.id(), roomId, memberId);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/coupon.html
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ <h3 id="_쿠폰_사용_진행_중">쿠폰 사용 (진행 중)</h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-13 18:48:03 +0900
Last updated 2023-11-12 16:01:40 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ <h4 id="_상태코드httpstatus"><a class="link" href="#_상태코드httpstatus"
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-13 18:48:03 +0900
Last updated 2023-11-07 00:27:34 +0900
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/docs/notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ <h4 id="_응답" class="discrete">응답</h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-13 18:48:03 +0900
Last updated 2023-11-12 16:01:40 +0900
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.moabam.api.application;
package com.moabam.api.application.room;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;

import java.time.LocalDate;
Expand All @@ -23,7 +23,6 @@

import com.moabam.api.application.image.ImageService;
import com.moabam.api.application.member.MemberService;
import com.moabam.api.application.room.RoomCertificationService;
import com.moabam.api.domain.image.ImageType;
import com.moabam.api.domain.member.Member;
import com.moabam.api.domain.room.DailyMemberCertification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moabam.api.application;
package com.moabam.api.application.room;

import static com.moabam.api.domain.room.RoomType.*;
import static org.assertj.core.api.Assertions.*;
Expand All @@ -17,7 +17,6 @@
import org.mockito.junit.jupiter.MockitoExtension;

import com.moabam.api.application.member.MemberService;
import com.moabam.api.application.room.RoomService;
import com.moabam.api.application.room.mapper.RoomMapper;
import com.moabam.api.domain.member.Member;
import com.moabam.api.domain.room.Participant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.moabam.api.domain.entity;
package com.moabam.api.domain.room;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.moabam.api.domain.room.Certification;
import com.moabam.api.domain.room.Room;
import com.moabam.api.domain.room.RoomType;
import com.moabam.api.domain.room.Routine;

class CertificationTest {

String content = "물 마시기";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moabam.api.domain.entity;
package com.moabam.api.domain.room;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -7,8 +7,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import com.moabam.api.domain.room.Room;
import com.moabam.api.domain.room.RoomType;
import com.moabam.global.error.exception.BadRequestException;
import com.moabam.global.error.model.ErrorMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moabam.api.domain.repository;
package com.moabam.api.domain.room.repository;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -16,13 +16,6 @@
import com.moabam.api.domain.room.Participant;
import com.moabam.api.domain.room.Room;
import com.moabam.api.domain.room.Routine;
import com.moabam.api.domain.room.repository.CertificationRepository;
import com.moabam.api.domain.room.repository.CertificationsSearchRepository;
import com.moabam.api.domain.room.repository.DailyMemberCertificationRepository;
import com.moabam.api.domain.room.repository.DailyRoomCertificationRepository;
import com.moabam.api.domain.room.repository.ParticipantRepository;
import com.moabam.api.domain.room.repository.RoomRepository;
import com.moabam.api.domain.room.repository.RoutineRepository;
import com.moabam.support.annotation.QuerydslRepositoryTest;
import com.moabam.support.fixture.RoomFixture;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moabam.api.domain.repository;
package com.moabam.api.domain.room.repository;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -13,9 +13,6 @@

import com.moabam.api.domain.room.Participant;
import com.moabam.api.domain.room.Room;
import com.moabam.api.domain.room.repository.ParticipantRepository;
import com.moabam.api.domain.room.repository.ParticipantSearchRepository;
import com.moabam.api.domain.room.repository.RoomRepository;
import com.moabam.global.config.JpaConfig;

@DataJpaTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.moabam.api.application.bug.BugMapper;
import com.moabam.api.application.member.MemberService;
import com.moabam.api.domain.bug.repository.BugHistoryRepository;
import com.moabam.api.domain.repository.BugHistorySearchRepository;
import com.moabam.api.domain.bug.repository.BugHistorySearchRepository;
import com.moabam.api.dto.TodayBugResponse;
import com.moabam.api.dto.bug.BugResponse;
import com.moabam.support.annotation.WithMember;
Expand Down
Loading

0 comments on commit c28a033

Please sign in to comment.