From a8415252cd477cd14bb9ef9fc60f5fe4a6e2d53d Mon Sep 17 00:00:00 2001 From: Shashank Verma Date: Sun, 24 Sep 2023 14:11:36 +0530 Subject: [PATCH] controller: Merge ViewController to PostController Signed-off-by: Shashank Verma --- .../moticlubs/controller/PostController.kt | 23 +++++++++ .../moticlubs/controller/ViewController.kt | 51 ------------------- 2 files changed, 23 insertions(+), 51 deletions(-) delete mode 100644 src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt index b1b471b..c3cd6f2 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/PostController.kt @@ -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 @@ -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 { @@ -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> = 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 = pathAuthorization + .userAuthorization() + .flatMap { + LOGGER.info("addView: view: $view") + viewService.saveView(view) + } + .wrapError() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt deleted file mode 100644 index 44435e6..0000000 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ViewController.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.mnnit.moticlubs.controller - -import com.mnnit.moticlubs.dao.View -import com.mnnit.moticlubs.service.ViewService -import com.mnnit.moticlubs.utils.Constants.BASE_PATH -import com.mnnit.moticlubs.utils.Constants.VIEWS_ROUTE -import com.mnnit.moticlubs.utils.ServiceLogger -import com.mnnit.moticlubs.utils.wrapError -import com.mnnit.moticlubs.web.security.PathAuthorization -import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.GetMapping -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.RequestParam -import org.springframework.web.bind.annotation.RestController -import reactor.core.publisher.Mono - -@RestController -@RequestMapping("/$BASE_PATH/$VIEWS_ROUTE") -@Tag(name = "ViewRoute") -class ViewController( - private val pathAuthorization: PathAuthorization, - private val viewService: ViewService, -) { - - companion object { - private val LOGGER = ServiceLogger.getLogger(ViewController::class.java) - } - - @GetMapping - @Operation(summary = "Get number of views of a post") - fun getViews(@RequestParam postId: Long): Mono> = pathAuthorization - .userAuthorization() - .flatMap { - LOGGER.info("getViews: pid: $postId") - viewService.getViewsByPid(postId) - } - .wrapError() - - @PostMapping - @Operation(summary = "Add views of a post") - fun addView(@RequestBody view: View): Mono = pathAuthorization - .userAuthorization() - .flatMap { - LOGGER.info("addView: view: $view") - viewService.saveView(view) - } - .wrapError() -}