fix: Ctx must be public
This commit is contained in:
parent
44d0a90ca0
commit
a0d747fdf4
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
ctx iris.Context
|
Ctx iris.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegisterRequest struct {
|
type RegisterRequest struct {
|
||||||
|
@ -34,15 +34,15 @@ func hashPassword(password string) (string, error) {
|
||||||
func (a *AccountService) PostRegister() {
|
func (a *AccountService) PostRegister() {
|
||||||
var r RegisterRequest
|
var r RegisterRequest
|
||||||
|
|
||||||
if err := a.ctx.ReadJSON(&r); err != nil {
|
if err := a.Ctx.ReadJSON(&r); err != nil {
|
||||||
a.ctx.StopWithError(iris.StatusBadRequest, err)
|
a.Ctx.StopWithError(iris.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash the password before saving it to the database.
|
// Hash the password before saving it to the database.
|
||||||
hashedPassword, err := hashPassword(r.Password)
|
hashedPassword, err := hashPassword(r.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.ctx.StopWithError(iris.StatusInternalServerError, err)
|
a.Ctx.StopWithError(iris.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ func (a *AccountService) PostRegister() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// An account with the same email address already exists.
|
// An account with the same email address already exists.
|
||||||
// Return an error response to the client.
|
// Return an error response to the client.
|
||||||
a.ctx.StopWithError(iris.StatusConflict, errors.New("an account with this email address already exists"))
|
a.Ctx.StopWithError(iris.StatusConflict, errors.New("an account with this email address already exists"))
|
||||||
return
|
return
|
||||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
// An unexpected error occurred while querying the database.
|
// An unexpected error occurred while querying the database.
|
||||||
// Return an error response to the client.
|
// Return an error response to the client.
|
||||||
a.ctx.StopWithError(iris.StatusInternalServerError, err)
|
a.Ctx.StopWithError(iris.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +70,10 @@ func (a *AccountService) PostRegister() {
|
||||||
// Save the new account to the database.
|
// Save the new account to the database.
|
||||||
err = db.Get().Create(&account).Error
|
err = db.Get().Create(&account).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.ctx.StopWithError(iris.StatusInternalServerError, err)
|
a.Ctx.StopWithError(iris.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a success response to the client.
|
// Return a success response to the client.
|
||||||
a.ctx.StatusCode(iris.StatusCreated)
|
a.Ctx.StatusCode(iris.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue