This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ralf Ueberfuhr
committed
Dec 18, 2023
1 parent
8938544
commit 9e597dc
Showing
5 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
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
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,14 @@ | ||
POST http://localhost:9080/blogposts | ||
Accept: application/json | ||
Content-Type: application/json | ||
|
||
{ | ||
"title": "test", | ||
"content": "Das ist ein Test" | ||
} | ||
|
||
> {% | ||
client.test("BlogPosts returned", () => { | ||
client.assert(response.status === 201); | ||
}); | ||
%} |
28 changes: 21 additions & 7 deletions
28
src/main/java/de/sample/schulung/spring/blog/BlogPostController.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 |
---|---|---|
@@ -1,18 +1,32 @@ | ||
package de.sample.schulung.spring.blog; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Controller | ||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/blogposts") | ||
public class BlogPostController { | ||
|
||
@GetMapping | ||
@ResponseBody | ||
@GetMapping( | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
String sayHello() { | ||
return "Hello World"; | ||
} | ||
|
||
@PostMapping( | ||
consumes = MediaType.APPLICATION_JSON_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
@ResponseStatus(HttpStatus.CREATED) | ||
BlogPostDto createBlogPost(@RequestBody BlogPostDto blogPostDto) { | ||
blogPostDto.setId(UUID.randomUUID()); | ||
blogPostDto.setTimestamp(LocalDateTime.now()); | ||
return blogPostDto; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/de/sample/schulung/spring/blog/BlogPostDto.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,19 @@ | ||
package de.sample.schulung.spring.blog; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
|
||
@Data | ||
public class BlogPostDto { | ||
|
||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
private UUID id; | ||
private String title; | ||
private String content; | ||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
private LocalDateTime timestamp; | ||
|
||
} |
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