diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt index 336e28b..628d410 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt @@ -1,8 +1,11 @@ package com.mnnit.moticlubs.controller import com.mnnit.moticlubs.dao.Club +import com.mnnit.moticlubs.dao.Url +import com.mnnit.moticlubs.dto.request.SaveUrlsDTO import com.mnnit.moticlubs.dto.request.UpdateClubDTO import com.mnnit.moticlubs.service.ClubService +import com.mnnit.moticlubs.service.UrlService import com.mnnit.moticlubs.utils.Constants import com.mnnit.moticlubs.utils.Constants.BASE_PATH import com.mnnit.moticlubs.utils.Constants.CLUBS_ROUTE @@ -18,10 +21,12 @@ import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestHeader 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 @@ -31,6 +36,7 @@ import reactor.core.publisher.Mono class ClubController( private val pathAuthorization: PathAuthorization, private val clubService: ClubService, + private val urlService: UrlService, ) { companion object { @@ -64,4 +70,36 @@ class ClubController( } .invalidateStamp { ResponseStamp.CLUB } .wrapError() + + @GetMapping("/url") + @Operation(summary = "Returns list of urls for the club") + fun getUrls( + @RequestParam clubId: Long, + @RequestHeader(Constants.STAMP_HEADER) stamp: Long, + ): Mono>> = apiWrapper( + key = ResponseStamp.URL.withKey("$clubId"), + stampValue = stamp, + authorization = pathAuthorization::userAuthorization, + serviceCall = { + LOGGER.info("getUrls: cid: $clubId") + urlService.getUrlsByCid(clubId) + }, + ) + + @PostMapping("/url") + @Operation(summary = "Updates the list of urls for the club") + fun updateUrls( + @RequestBody dto: SaveUrlsDTO, + @RequestParam clubId: Long + ): Mono>> = pathAuthorization + .clubAuthorization(clubId) + .flatMap { + LOGGER.info("updateUrls: cid: $clubId") + urlService.saveUrl( + clubId, + dto.urls.map { url -> Url(url.urlid, clubId, url.name, url.color, url.url) }, + ) + } + .invalidateStamp { ResponseStamp.URL.withKey("$clubId") } + .wrapError() } diff --git a/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt b/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt deleted file mode 100644 index ec8db6d..0000000 --- a/src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.mnnit.moticlubs.controller - -import com.mnnit.moticlubs.dao.Url -import com.mnnit.moticlubs.dto.request.SaveUrlsDTO -import com.mnnit.moticlubs.service.UrlService -import com.mnnit.moticlubs.utils.Constants -import com.mnnit.moticlubs.utils.Constants.BASE_PATH -import com.mnnit.moticlubs.utils.Constants.URL_ROUTE -import com.mnnit.moticlubs.utils.ResponseStamp -import com.mnnit.moticlubs.utils.ServiceLogger -import com.mnnit.moticlubs.utils.apiWrapper -import com.mnnit.moticlubs.utils.invalidateStamp -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.http.ResponseEntity -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.RequestHeader -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/$URL_ROUTE") -@Tag(name = "UrlRoute") -class UrlController( - private val pathAuthorization: PathAuthorization, - private val urlService: UrlService, -) { - - companion object { - private val LOGGER = ServiceLogger.getLogger(UrlController::class.java) - } - - @GetMapping - @Operation(summary = "Returns list of urls for the club") - fun getUrls( - @RequestParam clubId: Long, - @RequestHeader(Constants.STAMP_HEADER) stamp: Long, - ): Mono>> = apiWrapper( - key = ResponseStamp.URL.withKey("$clubId"), - stampValue = stamp, - authorization = pathAuthorization::userAuthorization, - serviceCall = { - LOGGER.info("getUrls: cid: $clubId") - urlService.getUrlsByCid(clubId) - }, - ) - - @PostMapping - @Operation(summary = "Updates the list of urls for the club") - fun updateUrls(@RequestBody dto: SaveUrlsDTO, @RequestParam clubId: Long): Mono>> = - pathAuthorization - .clubAuthorization(clubId) - .flatMap { - LOGGER.info("updateUrls: cid: $clubId") - urlService.saveUrl( - clubId, - dto.urls.map { url -> Url(url.urlid, clubId, url.name, url.color, url.url) }, - ) - } - .invalidateStamp { ResponseStamp.URL.withKey("$clubId") } - .wrapError() -} diff --git a/src/main/kotlin/com/mnnit/moticlubs/utils/Constants.kt b/src/main/kotlin/com/mnnit/moticlubs/utils/Constants.kt index 6c8f576..ab5ad4c 100644 --- a/src/main/kotlin/com/mnnit/moticlubs/utils/Constants.kt +++ b/src/main/kotlin/com/mnnit/moticlubs/utils/Constants.kt @@ -11,7 +11,6 @@ object Constants { const val POSTS_ROUTE = "posts" const val SUPER_ADMIN_ROUTE = "admin" const val CHANNEL_ROUTE = "channel" - const val URL_ROUTE = "url" const val VIEWS_ROUTE = "views" const val REPLY_ROUTE = "reply"