Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger annotation for shortLinkByKey #6682

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/ShortLinkController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import com.mohiva.play.silhouette.api.Silhouette
import com.scalableminds.util.tools.FoxImplicits
import io.swagger.annotations.{Api, ApiOperation, ApiParam}
import models.shortlinks.{ShortLink, ShortLinkDAO}
import oxalis.security.{RandomIDGenerator, WkEnv}
import play.api.libs.json.Json
Expand All @@ -11,12 +12,14 @@ import utils.{ObjectId, WkConf}
import javax.inject.Inject
import scala.concurrent.ExecutionContext

@Api
class ShortLinkController @Inject()(shortLinkDAO: ShortLinkDAO, sil: Silhouette[WkEnv], wkConf: WkConf)(
implicit ec: ExecutionContext,
val bodyParsers: PlayBodyParsers)
extends Controller
with FoxImplicits {

@ApiOperation(hidden = true, value = "")
def create: Action[String] = sil.SecuredAction.async(validateJson[String]) { implicit request =>
val longLink = request.body
val _id = ObjectId.generate
Expand All @@ -28,7 +31,12 @@ class ShortLinkController @Inject()(shortLinkDAO: ShortLinkDAO, sil: Silhouette[
} yield Ok(Json.toJson(inserted))
}

def getByKey(key: String): Action[AnyContent] = Action.async { implicit request =>
@ApiOperation(value = "Information about a short link, including the original long link.",
nickname = "shortLinkByKey")
def getByKey(
@ApiParam(value = "key of the shortLink, this is the short random string identifying the link.",
example = "aU7yv5Aja99T0829")
key: String): Action[AnyContent] = Action.async { implicit request =>
for {
shortLink <- shortLinkDAO.findOneByKey(key)
} yield Ok(Json.toJson(shortLink))
Expand Down