-
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
- Loading branch information
Showing
14 changed files
with
519 additions
and
34 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
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
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,96 @@ | ||
package flab.quing.waiting; | ||
|
||
import flab.quing.store.NoSuchStoreException; | ||
import flab.quing.store.Store; | ||
import flab.quing.store.StoreRepository; | ||
import flab.quing.store.exception.NoSuchUserException; | ||
import flab.quing.user.User; | ||
import flab.quing.user.UserRepository; | ||
import flab.quing.waiting.dto.WaitingRequest; | ||
import flab.quing.waiting.dto.WaitingResponse; | ||
import flab.quing.waiting.exception.DuplicateWaitingException; | ||
import flab.quing.waiting.exception.NoSuchWaitingException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class QuingServiceImpl implements QuingService { | ||
|
||
private final WaitingRepository waitingRepository; | ||
private final UserRepository userRepository; | ||
private final StoreRepository storeRepository; | ||
|
||
@Override | ||
@Transactional | ||
public WaitingResponse append(WaitingRequest waitingRequest) { | ||
User user = userRepository.findById(waitingRequest.getUserId()).orElseThrow(NoSuchUserException::new); | ||
Store store = storeRepository.findById(waitingRequest.getStoreId()).orElseThrow(NoSuchStoreException::new); | ||
Waiting waiting = Waiting.of(user, store); | ||
|
||
Optional<Waiting> exist = waitingRepository.findByUserIdAndWaitingQueueStatusIs(user.getId(), WaitingQueueStatus.WAITING); | ||
if(exist.isPresent()) { | ||
throw new DuplicateWaitingException(); | ||
} | ||
Waiting save = waitingRepository.save(waiting); | ||
return save.toResponse(); | ||
} | ||
|
||
@Override | ||
public List<WaitingResponse> getList(long storeId) { | ||
return waitingRepository.findAllByStoreIdAndWaitingQueueStatusIs(storeId, WaitingQueueStatus.WAITING) | ||
.stream() | ||
.map(Waiting::toResponse) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public int countForward(long waitingId) { | ||
Waiting waiting = waitingRepository.findById(waitingId).orElseThrow(NoSuchWaitingException::new); | ||
List<WaitingResponse> list = getList(waiting.getStore().getId()); | ||
return list.indexOf(waiting.toResponse()); | ||
} | ||
|
||
@Override | ||
public void sendMessage(long waitingId, String message) { | ||
//ncloud sms | ||
Waiting waiting = waitingRepository.findById(waitingId).orElseThrow(NoSuchWaitingException::new); | ||
User user = waiting.getUser(); | ||
System.out.println("phoneNumber = " + user.getPhoneNumber()); | ||
System.out.println("message = " + user.getName()+"님 "+message); | ||
} | ||
|
||
@Override | ||
public void sendEnterMessage(long waitingId) { | ||
sendMessage(waitingId, "입장해주세요!"); | ||
} | ||
|
||
@Override | ||
public void sendRegisterMessage(long waitingId) { | ||
sendMessage(waitingId, "등록되었습니다."); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public WaitingResponse doneWaiting(long waitingId) { | ||
Waiting waiting = waitingRepository.findById(waitingId).orElseThrow(NoSuchWaitingException::new); | ||
waiting.done(); | ||
return waiting.toResponse(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public WaitingResponse cancelWaiting(long waitingId) { | ||
Waiting waiting = waitingRepository.findById(waitingId).orElseThrow(NoSuchWaitingException::new); | ||
waiting.cancel(); | ||
return waiting.toResponse(); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,5 @@ public class WaitingRequest { | |
|
||
private long userId; | ||
|
||
private String phoneNumber; | ||
|
||
private 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
4 changes: 4 additions & 0 deletions
4
src/main/java/flab/quing/waiting/exception/DuplicateWaitingException.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,4 @@ | ||
package flab.quing.waiting.exception; | ||
|
||
public class DuplicateWaitingException extends RuntimeException { | ||
} |
2 changes: 1 addition & 1 deletion
2
...quing/waiting/NoSuchWaitingException.java → ...ing/exception/NoSuchWaitingException.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,4 +1,4 @@ | ||
package flab.quing.waiting; | ||
package flab.quing.waiting.exception; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
|
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
Oops, something went wrong.