Skip to content

Commit 1e888f6

Browse files
committed
feat: add /undo-patch endpoint
1 parent 3e99019 commit 1e888f6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/main/java/io/papermc/patchroulette/controller/RESTController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ public ResponseEntity<String> cancelPatch(@RequestBody final PatchId input) {
115115
return ResponseEntity.ok("Patch cancelled.");
116116
}
117117

118+
@PreAuthorize("hasRole('PATCH')")
119+
@PostMapping(
120+
value = "/undo-patch",
121+
consumes = "application/json",
122+
produces = "text/plain"
123+
)
124+
public ResponseEntity<String> undoPatch(final Authentication auth, @RequestBody final PatchId input) {
125+
final String user = this.getUser(auth);
126+
this.patchService.undoPatch(input, user);
127+
return ResponseEntity.ok("Patch moved to WIP.");
128+
}
129+
118130
@PreAuthorize("hasRole('PATCH')")
119131
@PostMapping(
120132
value = "/login",

src/main/java/io/papermc/patchroulette/service/PatchService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ public void finishWorkOnPatch(final PatchId patchId, final String user) {
7878
this.patchRepository.save(patch);
7979
}
8080

81+
@Transactional
82+
public void undoPatch(final PatchId patchId, final String user) {
83+
final Patch patch = this.patchRepository.getReferenceById(patchId);
84+
if (patch.getStatus() != Status.DONE) {
85+
throw new IllegalStateException("Patch " + patchId + " is not DONE");
86+
}
87+
patch.setStatus(Status.WIP);
88+
patch.setResponsibleUser(user);
89+
this.patchRepository.save(patch);
90+
}
91+
8192
public void clearPatches(final String minecraftVersion) {
8293
this.patchRepository.deleteAllByMinecraftVersion(minecraftVersion);
8394
}

0 commit comments

Comments
 (0)