43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
"gitea-issue/giteaClient"
|
|
"gitea-issue/model"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/savaki/swag/endpoint"
|
|
"github.com/savaki/swag/swagger"
|
|
"net/http"
|
|
)
|
|
|
|
func PostUser(c *gin.Context) {
|
|
var userProxy model.PostUserProxy
|
|
|
|
if err := c.BindJSON(&userProxy); err != nil {
|
|
c.AsciiJSON(http.StatusBadRequest, gin.H{
|
|
"message": "CREATE_USER_ERROR",
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
response, err := giteaClient.CreateUser(userProxy.TransformToGiteaUser())
|
|
if err != nil {
|
|
c.AsciiJSON(http.StatusUnprocessableEntity, gin.H{
|
|
"message": "CREATE_USER_ERROR",
|
|
"error": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.AsciiJSON(http.StatusOK, response)
|
|
}
|
|
|
|
func PostUserSwagger() (*swagger.Endpoint) {
|
|
return endpoint.New("post", "/user", "Create user",
|
|
endpoint.Handler(PostUser),
|
|
endpoint.Description("Post new user"),
|
|
endpoint.Body(model.PostUserProxy{}, "User object", true),
|
|
endpoint.Tags("user"),
|
|
endpoint.Response(http.StatusOK, gitea.User{}, "Gitea User"),
|
|
)
|
|
}
|