Return user on create user

This commit is contained in:
Jannis Mattheis 2018-02-11 13:21:42 +01:00 committed by Jannis Mattheis
parent 08dbacd71b
commit 8ad22b1280
2 changed files with 3 additions and 0 deletions

View File

@ -59,6 +59,7 @@ func (a *UserAPI) CreateUser(ctx *gin.Context) {
internal := toInternal(&user, []byte{})
if a.DB.GetUserByName(internal.Name) == nil {
a.DB.CreateUser(internal)
ctx.JSON(200, toExternal(internal))
} else {
ctx.AbortWithError(400, errors.New("username already exists"))
}

View File

@ -136,6 +136,8 @@ func (s *UserSuite) Test_CreateUser() {
s.a.CreateUser(s.ctx)
s.db.AssertCalled(s.T(), "CreateUser", &model.User{Name: "tom", Pass: pwByte, Admin: true})
s.expectJSON(`{"id":0, "name":"tom", "admin":true}`)
}
func (s *UserSuite) Test_CreateUser_NoPassword() {