Skip to content

Instantly share code, notes, and snippets.

@dvliman
Last active March 25, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvliman/007f400e82f28ab65d2696fd473e118f to your computer and use it in GitHub Desktop.
Save dvliman/007f400e82f28ab65d2696fd473e118f to your computer and use it in GitHub Desktop.
// src/main/kotlin/com/dvliman/demo/user/UserModels.kt
package com.dvliman.demo.user
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.http.MediaType.APPLICATION_JSON
import reactor.core.publisher.Mono
data class User(
val user_id: Int,
val name : String,
val email : String
)
data class CreateUserRequest (
val name : String,
val email: String
)
data class FetchUserRequest (
val user_id: Int
)
typealias CreateUserResponse = FetchUserRequest
fun toServerResponse(resp: CreateUserResponse) = ServerResponse
.ok()
.contentType(APPLICATION_JSON)
.body(Mono.just(resp), CreateUserResponse::class.java)
fun toServerResponse(user: User) = ServerResponse
.ok()
.contentType(APPLICATION_JSON)
.body(Mono.just(user), User::class.java)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment