Creating a post's HTTP requests

Now create the HTTP request functions for the Post

Here is the function for creating a post's POST request:

// Post status by Profile ID
@PostMapping("/post/{profile_id}/new")
fun submitPost(@PathVariable("profile_id") profile_id: Long, @RequestParam text: String): Any {
val mPost = Post(text, Profile(profile_id))
postRepository.save(mPost)

return mPost
}

Here is the function for the creating a post's GET request to fetch all the posts:

// Get all posted status
@GetMapping("/posts")
fun getPostList(): Any {
return postRepository.findAll()
}

Here is the function for creating a post's GET request to fetch one post:

// Get all posted status by Profile ID
@GetMapping("/post/{id}")
fun getPostById(@PathVariable("id") id: Long): Any {
return postRepository.findById(id)
}

Here is the function for the creating a post's PUT request to update one post:

// Update all posted status by Profile ID
@PutMapping("/post/{profile_id}")
fun updatePostById(@PathVariable("profile_id") id: Long, @RequestParam text: String): Any {
val modifiedPost = postRepository.getOne(id)
modifiedPost.text = text
return postRepository.save(modifiedPost)
}

Here is the function for creating a post's  DELETE request:

// Delete a posted status by Profile ID
@DeleteMapping("/post/{id}")
fun deletePostByUserId(@PathVariable("id") id: Long): Any {
return postRepository.deleteById(id)
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.216.75