-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #21-변수명 변경 phone -> phoneNumber * #21-타입변경 Integer -> int * #21-안쓰는 파일 삭제 * #21-사용하지않는 필드 제거 * #21-QuingService 일부 구현 append getList countForward doneWaiting * #21-QuingService test 일부 구현 * #21-주석 삭제 * #21-append 중복 방지 로직 추가 * #21-waiting cancel 구현 * #21-exception 패키지 이동 * #21-test코드 작성 * Feature #22-waiting - 사용자에게 메시지 send 구현 (#27) * #21-cancel 리턴 타입 변경 * #22-message 전송 관련 부분 print로 임시 구현 * #22-message 전송 관련 부분 test 작성 * #22-test에 불필요한 공백 제거 * #22- test코드 logger 적용 * #22- test코드 given, when, then 분리 * #22- test코드 logger 적용 * #22-리뷰반영 - 테스트 공백, 주석 정리 - 테스트 이름 변경 appendExistThrowDuplicateException * # Conflicts: # src/main/java/flab/quing/user/User.java # src/main/java/flab/quing/user/UserRepository.java * #21-user response import * #37-storeManager가 관리하는 store 연결 (1:1) - response에서 password 삭제 * #28-QuingController 작성 - 로그인한 가게(storeManager-store)의 대기열 목록(get quing) - 로그인한 유저의 현재 대기순서(get quing/count-forward) - 대기 생성 (post quing) - WaitingRequest 생성자 추가(jackson에서 필요) * #28-리뷰반영 - 기본경로 의미없는 ("") 삭제 - method private로 변경 * #28-Waiting done, cancel 추가 * #28-getByuser 추가 - done, cancel을 하기위해 userid로 waiting을 가져오는게 필요해서 추가 * #28-append request 추가 * #28-storeId로 변경 * #28-QuingController test 작성 * #28-private 제거 - controller는 다른데서 호출될일이 없겠거니 하고 private를 달았는데 이것 때문에 테스트가 불가하여 Access Modifier를 defualt로 변경..
- Loading branch information
Showing
6 changed files
with
296 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package flab.quing.waiting; | ||
|
||
import flab.quing.user.dto.StoreManagerResponse; | ||
import flab.quing.user.dto.UserResponse; | ||
import flab.quing.waiting.dto.WaitingAppendRequest; | ||
import flab.quing.waiting.dto.WaitingRequest; | ||
import flab.quing.waiting.dto.WaitingResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
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.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.SessionAttribute; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/quing") | ||
public class QuingController { | ||
|
||
private final QuingService quingService; | ||
|
||
|
||
@GetMapping | ||
List<WaitingResponse> list( | ||
@SessionAttribute(name = "AUTH_STORE") | ||
StoreManagerResponse storeManagerResponse | ||
) { | ||
long storeId = storeManagerResponse.getStoreId(); | ||
|
||
return quingService.getList(storeId); | ||
} | ||
|
||
@GetMapping("count-forward") | ||
long countForward(@SessionAttribute(name = "AUTH_USER") | ||
UserResponse userResponse | ||
) { | ||
return quingService.countForward(userResponse.getUserId()); | ||
} | ||
|
||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
WaitingResponse append( | ||
@SessionAttribute(name = "AUTH_USER") | ||
UserResponse userResponse, | ||
@RequestBody WaitingAppendRequest waitingAppendRequest | ||
) { | ||
WaitingRequest waitingRequest = WaitingRequest.builder() | ||
.userId(userResponse.getUserId()) | ||
.storeId(waitingAppendRequest.getStoreId()) | ||
.build(); | ||
|
||
WaitingResponse waitingResponse = quingService.append(waitingRequest); | ||
|
||
quingService.sendRegisterMessage(waitingResponse.getId()); | ||
|
||
return waitingResponse; | ||
} | ||
|
||
@PatchMapping | ||
WaitingResponse doneWaiting( | ||
@SessionAttribute(name = "AUTH_USER") | ||
UserResponse userResponse | ||
) { | ||
WaitingResponse waitingResponseByUserId = quingService.getByUserId(userResponse.getUserId()); | ||
|
||
return quingService.doneWaiting(waitingResponseByUserId.getId()); | ||
} | ||
|
||
@DeleteMapping | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
void cancelWaiting( | ||
@SessionAttribute(name = "AUTH_USER") | ||
UserResponse userResponse | ||
) { | ||
WaitingResponse waitingResponseByUserId = quingService.getByUserId(userResponse.getUserId()); | ||
|
||
quingService.cancelWaiting(waitingResponseByUserId.getId()); | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/flab/quing/waiting/dto/WaitingAppendRequest.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,18 @@ | ||
package flab.quing.waiting.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@Setter(AccessLevel.NONE) | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class WaitingAppendRequest { | ||
|
||
long storeId; | ||
} |
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
178 changes: 178 additions & 0 deletions
178
src/test/java/flab/quing/waiting/QuingControllerTest.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,178 @@ | ||
package flab.quing.waiting; | ||
|
||
import flab.quing.DummyDataMaker; | ||
import flab.quing.store.Store; | ||
import flab.quing.store.StoreRepository; | ||
import flab.quing.user.StoreManager; | ||
import flab.quing.user.StoreManagerRepository; | ||
import flab.quing.user.User; | ||
import flab.quing.user.UserRepository; | ||
import flab.quing.waiting.dto.WaitingAppendRequest; | ||
import flab.quing.waiting.dto.WaitingResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
import org.springframework.boot.test.system.OutputCaptureExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Slf4j | ||
@Transactional | ||
@ExtendWith(OutputCaptureExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class QuingControllerTest { | ||
|
||
@Autowired | ||
QuingController quingController; | ||
|
||
@Autowired | ||
UserRepository userRepository; | ||
|
||
@Autowired | ||
StoreRepository storeRepository; | ||
|
||
@Autowired | ||
WaitingRepository waitingRepository; | ||
|
||
@Autowired | ||
StoreManagerRepository storeManagerRepository; | ||
|
||
|
||
@Test | ||
void 대기_등록(CapturedOutput output) { | ||
//given | ||
Store store = DummyDataMaker.store(); | ||
storeRepository.save(store); | ||
|
||
User user = DummyDataMaker.user(); | ||
userRepository.save(user); | ||
|
||
Waiting waiting = DummyDataMaker.waiting(user, store); | ||
|
||
WaitingAppendRequest waitingAppendRequest = WaitingAppendRequest.builder() | ||
.storeId(store.getId()) | ||
.build(); | ||
|
||
//when | ||
WaitingResponse append = quingController.append(waiting.getUser().toResponse(), waitingAppendRequest); | ||
|
||
//then | ||
assertThat(append.getUserName()).isEqualTo(user.getName()); | ||
assertThat(output).contains("등록되었습니다."); | ||
} | ||
|
||
@Test | ||
void 내_앞에_대기중인_손님의_수() { | ||
//given | ||
final long userCount = 5; | ||
|
||
Store store = DummyDataMaker.store(); | ||
storeRepository.save(store); | ||
|
||
List<User> users = new ArrayList<>(); | ||
|
||
for (int i = 0; i < userCount; i++) { | ||
User user = userRepository.save(DummyDataMaker.user()); | ||
users.add(user); | ||
|
||
WaitingAppendRequest waitingAppendRequest = WaitingAppendRequest.builder() | ||
.storeId(store.getId()) | ||
.build(); | ||
|
||
quingController.append(user.toResponse(), waitingAppendRequest); | ||
} | ||
|
||
//when | ||
long countForward = quingController.countForward(users.get((int) userCount - 1).toResponse()); | ||
|
||
//then | ||
assertThat(countForward).isEqualTo(userCount - 1); | ||
} | ||
|
||
@Test | ||
void 가게에_대기중인_손님_리스트() { | ||
//given | ||
final long userCount = 5; | ||
|
||
Store store = DummyDataMaker.store(); | ||
storeRepository.save(store); | ||
|
||
StoreManager storeManager = StoreManager.builder() | ||
.store(store) | ||
.build(); | ||
storeManagerRepository.save(storeManager); | ||
|
||
for (int i = 0; i < userCount; i++) { | ||
User user = userRepository.save(DummyDataMaker.user()); | ||
|
||
WaitingAppendRequest waitingAppendRequest = WaitingAppendRequest.builder() | ||
.storeId(store.getId()) | ||
.build(); | ||
|
||
quingController.append(user.toResponse(), waitingAppendRequest); | ||
} | ||
|
||
//when | ||
List<WaitingResponse> waitingResponseList = quingController.list(storeManager.toResponse()); | ||
waitingResponseList.forEach(w-> log.info("waiting = " + w)); | ||
//then | ||
assertThat(waitingResponseList.size()).isEqualTo(userCount); | ||
} | ||
|
||
@Test | ||
void 입장_완료() { | ||
//given | ||
Store store = DummyDataMaker.store(); | ||
storeRepository.save(store); | ||
|
||
User user = DummyDataMaker.user(); | ||
userRepository.save(user); | ||
|
||
WaitingAppendRequest waitingAppendRequest = WaitingAppendRequest.builder() | ||
.storeId(store.getId()) | ||
.build(); | ||
|
||
WaitingResponse waitingResponse = quingController.append(user.toResponse(), waitingAppendRequest); | ||
|
||
//when | ||
WaitingResponse doneWaiting = quingController.doneWaiting(user.toResponse()); | ||
|
||
List<Waiting> all = waitingRepository.findAll(); | ||
|
||
//then | ||
assertThat(all.size()).isEqualTo(1); | ||
assertThat(all.get(0).getWaitingQueueStatus()).isEqualTo(WaitingQueueStatus.DONE); | ||
} | ||
|
||
@Test | ||
void 대기_취소() { | ||
//given | ||
Store store = DummyDataMaker.store(); | ||
storeRepository.save(store); | ||
|
||
User user = DummyDataMaker.user(); | ||
userRepository.save(user); | ||
|
||
WaitingAppendRequest waitingAppendRequest = WaitingAppendRequest.builder() | ||
.storeId(store.getId()) | ||
.build(); | ||
|
||
WaitingResponse waitingResponse = quingController.append(user.toResponse(), waitingAppendRequest); | ||
|
||
//when | ||
quingController.cancelWaiting(user.toResponse()); | ||
|
||
List<Waiting> all = waitingRepository.findAll(); | ||
|
||
//then | ||
assertThat(all.size()).isEqualTo(1); | ||
assertThat(all.get(0).getWaitingQueueStatus()).isEqualTo(WaitingQueueStatus.CANCELED); | ||
} | ||
} |