Skip to content
Snippets Groups Projects
Commit ac6924a8 authored by Michael Ruderer's avatar Michael Ruderer
Browse files

-

parent 0e470a99
No related branches found
No related tags found
No related merge requests found
Pipeline #9914 failed
package de.thd.pms.controller;
import java.net.URI;
import java.time.LocalDateTime;
import java.util.List;
......@@ -12,15 +13,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import de.thd.pms.model.Person;
import de.thd.pms.service.DaoException;
import de.thd.pms.service.PersonService;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@Controller
@RequestMapping("/person")
......@@ -104,5 +103,24 @@ public class PersonController {
return ResponseEntity.ok(personService.findAll());
}
@Operation(summary = "Create or modify a Person")
@io.swagger.v3.oas.annotations.parameters.RequestBody(description="Person")
@RequestMapping(value="/", method={RequestMethod.POST, RequestMethod.PUT})
@ResponseBody
public ResponseEntity<Person> rest_save(
@RequestBody Person person
) {
// Wenn das Feld created der Instanz boot null ist,
// dann wird das aktuelle Datum in dieses Feld geschrieben
if (person.getCreated() == null) {
person.setCreated(LocalDateTime.now());
}
Person p = personService.save(person);
URI uri = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(b.getId())
.toUri();
return ResponseEntity.created(uri).body(p);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment