Skip to content

Commit

Permalink
Setup a blog controller containing the seven RESTful routes:
Browse files Browse the repository at this point in the history
- index
- new
- create
- show
- edit
- update
- destroy
  • Loading branch information
lidimayra committed Jan 10, 2025
1 parent ad4bc9e commit 9636d6f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
48 changes: 48 additions & 0 deletions myapp/src/main/java/com/example/myapp/BlogController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.myapp;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.DeleteMapping;

@Controller
public class BlogController {
@GetMapping("/posts")
public String listPosts() {
return "blog/index";
}

@GetMapping("/posts/new")
public String newPost() {
return "blog/new";
}

@PostMapping("/posts")
public String createPost() {
//TODO: logic responsible for saving a post
return null;
}

@GetMapping("/posts/{postId}")
public String showPost() {
return "blog/show";
}

@GetMapping("/posts/{postId}/edit")
public String editPost() {
return "blog/edit";
}

@PatchMapping("/posts/{postId}")
public String updatePost() {
//TODO: logic responsible for updating a post
return null;
}

@DeleteMapping("/posts/{postId}")
public String deletePost() {
//TODO: logic responsible for deleting a post
return null;
}
}
1 change: 1 addition & 0 deletions myapp/src/main/resources/templates/blog/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Edit Post</p>
1 change: 1 addition & 0 deletions myapp/src/main/resources/templates/blog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>List of Posts</p>
1 change: 1 addition & 0 deletions myapp/src/main/resources/templates/blog/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>New Post</p>
1 change: 1 addition & 0 deletions myapp/src/main/resources/templates/blog/show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Post title</p>

0 comments on commit 9636d6f

Please sign in to comment.