mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
PUT username now returns also 409
This commit is contained in:
parent
d068a5389e
commit
758be58b31
24 changed files with 19 additions and 1154 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/notherealmarco/WASAPhoto/service/api/authorization"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/helpers"
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
||||
"github.com/notherealmarco/WASAPhoto/service/database"
|
||||
"github.com/notherealmarco/WASAPhoto/service/structures"
|
||||
)
|
||||
|
||||
|
@ -21,7 +22,12 @@ func (rt *_router) UpdateUsername(w http.ResponseWriter, r *http.Request, ps htt
|
|||
return
|
||||
}
|
||||
|
||||
err := rt.db.UpdateUsername(uid, req.Name)
|
||||
status, err := rt.db.UpdateUsername(uid, req.Name)
|
||||
|
||||
if status == database.ERR_EXISTS {
|
||||
helpers.SendStatus(http.StatusConflict, w, "Username already exists", rt.baseLogger)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
helpers.SendInternalError(err, "Database error: UpdateUsername", w, rt.baseLogger)
|
||||
|
|
|
@ -47,7 +47,7 @@ type AppDatabase interface {
|
|||
|
||||
SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.UIDName, error)
|
||||
|
||||
UpdateUsername(uid, name string) error
|
||||
UpdateUsername(uid, name string) (QueryResult, error)
|
||||
|
||||
GetUserFollowers(uid string, requesting_uid string, start_index int, limit int) (QueryResult, *[]structures.UIDName, error)
|
||||
GetUserFollowing(uid string, requesting_uid string, start_index int, offset int) (QueryResult, *[]structures.UIDName, error)
|
||||
|
|
|
@ -56,9 +56,18 @@ func (db *appdbimpl) CreateUser(name string) (string, error) {
|
|||
}
|
||||
|
||||
// Update username
|
||||
func (db *appdbimpl) UpdateUsername(uid string, name string) error {
|
||||
func (db *appdbimpl) UpdateUsername(uid string, name string) (QueryResult, error) {
|
||||
_, err := db.c.Exec(`UPDATE "users" SET "name" = ? WHERE "uid" = ?`, name, uid)
|
||||
return err
|
||||
|
||||
if db_errors.UniqueViolation(err) {
|
||||
return ERR_EXISTS, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return ERR_INTERNAL, err
|
||||
}
|
||||
|
||||
return SUCCESS, err
|
||||
}
|
||||
|
||||
// Get user followers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue