-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 (TestimonialController) create controller
- Loading branch information
1 parent
edf21d5
commit 1b4d491
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/ecureuill/milhasapi/controller/TestimonialController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ecureuill.milhasapi.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import ecureuill.milhasapi.domain.testimonial.Testimonial; | ||
import ecureuill.milhasapi.domain.testimonial.TestimonialCreateRecord; | ||
import ecureuill.milhasapi.domain.testimonial.TestimonialDetailRecord; | ||
import ecureuill.milhasapi.domain.testimonial.TestimonialRepository; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/depoimentos") | ||
public class TestimonialController { | ||
|
||
@Autowired | ||
private TestimonialRepository repository; | ||
|
||
@PostMapping | ||
@Transactional | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ResponseEntity<TestimonialDetailRecord> save(@RequestBody @Valid TestimonialCreateRecord record, UriComponentsBuilder uriBuilder){ | ||
var doctor = repository.save(new Testimonial(record)); | ||
var uri = uriBuilder.path("/doctors/{id}").buildAndExpand(doctor.getId()).toUri(); | ||
var dto = new TestimonialDetailRecord(doctor); | ||
|
||
return ResponseEntity.created(uri).body(dto); | ||
} | ||
|
||
} |