-
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.
Browse files
Browse the repository at this point in the history
- 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.