-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openapi-generator): add openapi-generator for server and refacto…
…r get profile endpoint to use it
- Loading branch information
1 parent
d4090f2
commit f81cbac
Showing
8 changed files
with
121 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 15 additions & 8 deletions
23
server/app/src/main/kotlin/mu/muse/rest/profile/GetProfileEndpoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
package mu.muse.rest.profile | ||
|
||
import mu.muse.domain.user.Username | ||
import mu.muse.rest.API_PROFILE | ||
import mu.muse.rest.api.ProfileApi | ||
import mu.muse.rest.dto.ProfileDetails | ||
import mu.muse.usecase.GetProfile | ||
import mu.muse.usecase.dto.ProfileDetails | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.context.SecurityContextHolder | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.security.Principal | ||
|
||
@RestController | ||
class GetProfileEndpoint(private val showProfile: GetProfile) { | ||
class GetProfileEndpoint(private val showProfile: GetProfile) : ProfileApi { | ||
|
||
@GetMapping(API_PROFILE) | ||
fun getProfile(principal: Principal): ProfileDetails { | ||
override fun getProfile(): ResponseEntity<ProfileDetails> { | ||
val principal = SecurityContextHolder.getContext().authentication | ||
val username = Username.from(principal.name) | ||
return showProfile.execute(username) | ||
val user = showProfile.execute(username) | ||
return ResponseEntity.ok().body( | ||
ProfileDetails( | ||
username = user.username.toStringValue(), | ||
role = user.role.toStringValue(), | ||
fullName = user.fullName.toStringValue(), | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
server/app/src/main/kotlin/mu/muse/usecase/scenario/profile/GetProfileUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package mu.muse.usecase.scenario.profile | ||
|
||
import mu.muse.domain.user.User | ||
import mu.muse.domain.user.Username | ||
import mu.muse.usecase.GetProfile | ||
import mu.muse.usecase.ShowProfileError | ||
import mu.muse.usecase.access.user.UserExtractor | ||
import mu.muse.usecase.dto.ProfileDetails | ||
|
||
class GetProfileUseCase(private val userExtractor: UserExtractor) : GetProfile { | ||
|
||
override fun execute(username: Username): ProfileDetails { | ||
val user = userExtractor.findByUsername(username) ?: throw ShowProfileError.UserNotFound(username) | ||
return ProfileDetails.from(user) | ||
override fun execute(username: Username): User { | ||
return userExtractor.findByUsername(username) | ||
?: throw ShowProfileError.UserNotFound(username) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
openapi: "3.0.0" | ||
|
||
info: | ||
version: 1.0.0 | ||
title: Get Profile | ||
servers: | ||
- url: http://localhost:8080/ | ||
|
||
paths: | ||
/api/profile: | ||
get: | ||
summary: Get Profile Info | ||
operationId: getProfile | ||
tags: | ||
- profile | ||
responses: | ||
"200": | ||
description: Profile Details | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ProfileDetails" | ||
default: | ||
description: server error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ServerError" | ||
|
||
components: | ||
schemas: | ||
ProfileDetails: | ||
type: object | ||
required: [ username, role, fullName ] | ||
properties: | ||
username: | ||
type: string | ||
role: | ||
type: string | ||
fullName: | ||
type: string | ||
ServerError: | ||
type: object |