Skip to content
Snippets Groups Projects

Resolve "Rename controller methods and remove creates with ids"

11 files
+ 43
179
Compare changes
  • Side-by-side
  • Inline

Files

@@ -22,7 +22,6 @@ import javax.validation.Valid;
import nl.tudelft.labracore.dto.create.AssignmentCreateDTO;
import nl.tudelft.labracore.dto.patch.AssignmentPatchDTO;
import nl.tudelft.labracore.model.Assignment;
import nl.tudelft.labracore.repository.AssignmentRepository;
import org.slf4j.Logger;
@@ -53,31 +52,10 @@ public class AssignmentController {
@Validated
@PostMapping
@PreAuthorize("hasAuthority('ASSIGNMENT_CREATE')")
public Long add(@Valid @RequestBody AssignmentCreateDTO dto, Errors errors) {
// TODO: Make function usable by making Assignment ID an auto generated value.
public Long addAssignment(@Valid @RequestBody AssignmentCreateDTO dto, Errors errors) {
return ar.save(dto.apply(errors)).getId();
}
/**
* Adds a assignment by processing the sent assignment creation object with the given id.
*
* @param id the id of the object to create
* @param dto The assignment creation transfer object.
* @param errors The result of validating the create DTO.
* @return The id under which the assignment was added.
*/
@Validated
@PostMapping("{id}")
@PreAuthorize("hasAuthority('ASSIGNMENT_CREATE')")
public Long addWithId(@PathVariable Long id,
@Valid @RequestBody AssignmentCreateDTO dto,
Errors errors) {
// TODO: Remove when Queue is dependent on Assignment creation happening in Labracore
Assignment assignment = dto.apply(errors);
assignment.setId(id);
return ar.save(assignment).getId();
}
/**
* Patches the assignment with the given id to match the given patch.
*
@@ -88,7 +66,7 @@ public class AssignmentController {
*/
@PatchMapping("{id}")
@PreAuthorize("hasAuthority('ASSIGNMENT_UPDATE')")
public Long patch(@PathVariable Long id,
public Long patchAssignment(@PathVariable Long id,
@Valid @RequestBody AssignmentPatchDTO patch,
Errors errors) {
return patch.apply(ar.findByIdOrThrow(id), errors).getId();
Loading