-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersController.kt
More file actions
38 lines (34 loc) · 1.76 KB
/
Copy pathUsersController.kt
File metadata and controls
38 lines (34 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.genspectrum.dashboardsbackend.controller
import io.swagger.v3.oas.annotations.Operation
import org.genspectrum.dashboardsbackend.api.PublicUser
import org.genspectrum.dashboardsbackend.api.User
import org.genspectrum.dashboardsbackend.api.UserSyncRequest
import org.genspectrum.dashboardsbackend.model.user.UserModel
import org.springframework.http.MediaType
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.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
class UsersController(private val userModel: UserModel) {
@PostMapping("/users/sync", produces = [MediaType.APPLICATION_JSON_VALUE])
@Operation(
summary = "Sync user from external auth provider",
description = "Upserts a user record by github_id. Returns the user with their internal ID.",
)
fun syncUser(@RequestBody request: UserSyncRequest): User = userModel.syncUser(request)
@GetMapping("/users/me", produces = [MediaType.APPLICATION_JSON_VALUE])
@Operation(
summary = "Get the authenticated user",
description = "Returns public info for the currently authenticated user, resolved from the session or API key.",
)
fun getMe(@RequestParam userId: Long): PublicUser = userModel.getUser(userId)
@GetMapping("/users/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
@Operation(
summary = "Get user by internal ID",
description = "Returns public user info by internal ID.",
)
fun getUser(@PathVariable id: Long): PublicUser = userModel.getUser(id)
}