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

Feat/api for swaggger #90

Merged
merged 3 commits into from
Jan 11, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,42 @@ 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.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api")
@Tag(name = "User Controller", description = "User Controller API")
class UserController(
private val userService: UserService
) {

@PostMapping("/v1/ping")
@PostMapping("/api/v1/ping")
@Operation(summary = "Ping pong", description = "Sample ping pong api for testing")
fun ping(): ResponseEntity<String> {
return ResponseEntity.ok("pong")
}

@GetMapping("/v1/ping")
@GetMapping("/api/v1/ping")
fun getPing(): ResponseEntity<String> {
return ResponseEntity.ok("pong")
}

@PostMapping("/auth/register")
@PostMapping("/api/auth/register")
fun register(
@RequestBody request: RegisterRequest
): ResponseEntity<Unit> {
userService.register(username = request.username, password = request.password)
return ResponseEntity.ok().build()
}

// a mapping just for swagger testing
// token parameter is passed as a query parameter
// just return the token parameter in body
@Operation(summary = "Redirect", description = "Redirect to the token", hidden = true)
@GetMapping("/redirect")
fun redirect(@RequestParam token: String): ResponseEntity<String> {
return ResponseEntity.ok(token)
}
}

data class RegisterRequest(
Expand Down
Loading