Skip to content

Commit

Permalink
controller: Merge UrlController into ClubController
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 1e26a8c commit a14c15b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 69 deletions.
38 changes: 38 additions & 0 deletions src/main/kotlin/com/mnnit/moticlubs/controller/ClubController.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -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<ResponseEntity<List<Url>>> = 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<ResponseEntity<List<Url>>> = 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()
}
68 changes: 0 additions & 68 deletions src/main/kotlin/com/mnnit/moticlubs/controller/UrlController.kt

This file was deleted.

1 change: 0 additions & 1 deletion src/main/kotlin/com/mnnit/moticlubs/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit a14c15b

Please sign in to comment.