Skip to content

Instantly share code, notes, and snippets.

@0001vrn
Created April 11, 2020 10:24
Show Gist options
  • Save 0001vrn/43477aecb17898b8afc94db0b0eddd79 to your computer and use it in GitHub Desktop.
Save 0001vrn/43477aecb17898b8afc94db0b0eddd79 to your computer and use it in GitHub Desktop.
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