Skip to content

Commit

Permalink
controller: Merge ViewController to PostController
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Verma <[email protected]>
  • Loading branch information
shank03 committed Sep 24, 2023
1 parent 5aa56bd commit a841525
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 51 deletions.
23 changes: 23 additions & 0 deletions src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mnnit.moticlubs.controller

import com.mnnit.moticlubs.dao.Post
import com.mnnit.moticlubs.dao.View
import com.mnnit.moticlubs.dto.request.UpdatePostDTO
import com.mnnit.moticlubs.service.PostService
import com.mnnit.moticlubs.service.ViewService
import com.mnnit.moticlubs.utils.Constants
import com.mnnit.moticlubs.utils.Constants.BASE_PATH
import com.mnnit.moticlubs.utils.Constants.POSTS_ROUTE
Expand Down Expand Up @@ -35,6 +37,7 @@ import reactor.core.publisher.Mono
class PostController(
private val pathAuthorization: PathAuthorization,
private val postService: PostService,
private val viewService: ViewService,
) {

companion object {
Expand Down Expand Up @@ -100,4 +103,24 @@ class PostController(
}
.invalidateStamp { ResponseStamp.POST }
.wrapError()

@GetMapping("/views")
@Operation(summary = "Get number of views of a post")
fun getViews(@RequestParam postId: Long): Mono<List<View>> = pathAuthorization
.userAuthorization()
.flatMap {
LOGGER.info("getViews: pid: $postId")
viewService.getViewsByPid(postId)
}
.wrapError()

@PostMapping("/views")
@Operation(summary = "Add views of a post")
fun addView(@RequestBody view: View): Mono<View> = pathAuthorization
.userAuthorization()
.flatMap {
LOGGER.info("addView: view: $view")
viewService.saveView(view)
}
.wrapError()
}
51 changes: 0 additions & 51 deletions src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt

This file was deleted.

0 comments on commit a841525

Please sign in to comment.