package gaf3.core.services.user

import gaf3.core.cloud.GafCloudConfiguration
import gaf3.core.services.user.dao.GafUserInfoDAO
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Import
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
@RestController
@EnableJpaRepositories(basePackageClasses=[GafUserInfoDAO::class])
@Import(GafCloudConfiguration::class)
class ServiceUserApplication {

    @RequestMapping("/user/hello")
    fun hello(name: String?) : String {
        return """ hello, ${name ?: "user"}!"""
    }

    @GetMapping("/demo")
    fun demo() : ResponseEntity<Any> {

        return ResponseEntity.status(400)
                .contentType(MediaType.APPLICATION_JSON)
                .body(RestError(-1,"demo error"));
        // return ResponseEntity.status(400).body("this is a error demo!")
    }

    data class RestError(val errcode: Int, val errmsg: String)
}

fun main(args: Array<String>) {
    runApplication<ServiceUserApplication>(*args)
}
