Fix: various bug fix

This commit is contained in:
2025-10-16 07:12:01 +08:00
parent 5bbab63a2c
commit 0dea850cfa
16 changed files with 185 additions and 56 deletions

View File

@@ -11,6 +11,11 @@ import (
"github.com/uptrace/bunrouter"
)
type PostRegisterInput struct {
Username string `json:"username"`
Password string `json:"password"`
}
func (self *Handlers) PostRegister(
w http.ResponseWriter,
req bunrouter.Request,
@@ -26,15 +31,20 @@ func (self *Handlers) PostRegister(
}
}
var user models.User
if err := json.Unmarshal(b, &user); err != nil {
var input PostRegisterInput
if err := json.Unmarshal(b, &input); err != nil {
return middlewares.HTTPError{
StatusCode: http.StatusBadRequest,
Message: "failed to unmarshal json into user",
Message: "failed to unmarshal json",
OriginError: err,
}
}
user := models.User{
Username: input.Username,
Password: input.Password,
LoginCount: 0,
}
res, err := self.db.NewInsert().
Model(&user).
On("CONFLICT (username) DO NOTHING").