Created
April 11, 2020 10:24
-
-
Save 0001vrn/43477aecb17898b8afc94db0b0eddd79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class ChgRequestServiceImpl implements ChgRequestService { | |
private final ChgRequestRepository chgRequestRepository; | |
public ChgRequestServiceImpl(ChgRequestRepository chgRequestRepository) { | |
this.chgRequestRepository = chgRequestRepository; | |
} | |
@Override | |
public List<ChgRequest> findAll() { | |
return chgRequestRepository.findAll(); | |
} | |
@Override | |
public ChgRequest findById(UUID id) { | |
return getChgRequest(id); | |
} | |
@Override | |
public UUID createChgRequest(AppMetadata appMetadata) { | |
final ChgRequest chgRequest = new ChgRequest(UUID.randomUUID(), appMetadata); | |
chgRequestRepository.save(chgRequest); | |
return chgRequest.getId(); | |
} | |
@Override | |
public void beginChgRequest(UUID id) { | |
var chgReq = getChgRequest(id); | |
chgReq.beginChgRequest(); | |
chgRequestRepository.save(chgReq); | |
} | |
@Override | |
public void doneChgRequest(UUID id) { | |
var chgReq = getChgRequest(id); | |
chgReq.markChgRequestAsDone(); | |
chgRequestRepository.save(chgReq); | |
} | |
@Override | |
public void rollbackChgRequest(UUID id) { | |
var chgReq = getChgRequest(id); | |
chgReq.rollingBackChgReq(); | |
chgRequestRepository.save(chgReq); | |
} | |
private ChgRequest getChgRequest(UUID id) { | |
return chgRequestRepository | |
.findById(id) | |
.orElseThrow(() -> new RuntimeException("ChgRequest with given id doesn't exist")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment