From e45241fa20414980d53de854719784e4355ac53e Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 07:57:22 +0100 Subject: [PATCH] Fix issues and namings Fix a few issues with users and accounts caused by reusing code without changing it correctly. Also changed some naming mistakes that made the documentation invalid. --- api/openapi/openapi.yaml | 2 +- internal/api/services/accounts/accounts_verify.go | 1 + internal/api/services/users/users_getbyuuid.go | 8 ++++---- internal/api/services/users/users_getself.go | 4 ++-- internal/database/models.go | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/openapi/openapi.yaml b/api/openapi/openapi.yaml index 85ecff5..9e4ad33 100644 --- a/api/openapi/openapi.yaml +++ b/api/openapi/openapi.yaml @@ -98,7 +98,7 @@ paths: application/json: schema: $ref: "#/components/schemas/AccountSigninResponse" - /account/logout: + /account/signout: post: tags: - account diff --git a/internal/api/services/accounts/accounts_verify.go b/internal/api/services/accounts/accounts_verify.go index 4228a58..905f521 100755 --- a/internal/api/services/accounts/accounts_verify.go +++ b/internal/api/services/accounts/accounts_verify.go @@ -90,6 +90,7 @@ func AccountVerify_Service(ctx iris.Context, req types.AccountVerifyRequest) { ctx.JSON(types.CommonErrorResponse{ Error: "Something went wrong, please try again", }) + logboi.Err("Failed to commit transaction: " + err.Error()) return } diff --git a/internal/api/services/users/users_getbyuuid.go b/internal/api/services/users/users_getbyuuid.go index d167ab0..6795d4a 100755 --- a/internal/api/services/users/users_getbyuuid.go +++ b/internal/api/services/users/users_getbyuuid.go @@ -33,9 +33,9 @@ import ( // UsersGetByUuid_Service gets all users from the database by uuid func UsersGetByUuid_Service(ctx iris.Context) { - // Get user ID from URL parameters - uuid, err := ctx.Params().GetUint64("uuid") - if err != nil { + // Get user UUID from URL parameters + uuid := ctx.Params().GetString("uuid") + if uuid != "" { ctx.StatusCode(iris.StatusBadRequest) ctx.JSON(types.CommonErrorResponse{ Error: "Invalid uuid parameter", @@ -45,7 +45,7 @@ func UsersGetByUuid_Service(ctx iris.Context) { // Get user from database var user db.User - err = db.Db.Model(&db.User{}).Where("uuid = ?", uuid).Select("id", "username", "email", "uuid", "role", "first_name", "last_name", "verified", "friends").Find(&user).Error + err := db.Db.Model(&db.User{}).Where("uuid = ?", uuid).Select("id", "username", "email", "uuid", "role", "first_name", "last_name", "verified", "friends").Find(&user).Error if err != nil { ctx.StatusCode(iris.StatusInternalServerError) ctx.JSON(types.CommonErrorResponse{ diff --git a/internal/api/services/users/users_getself.go b/internal/api/services/users/users_getself.go index d774d83..77369c4 100755 --- a/internal/api/services/users/users_getself.go +++ b/internal/api/services/users/users_getself.go @@ -39,8 +39,8 @@ func UsersGetSelf_Service(ctx iris.Context) { id := claims.UserId // Get user from database - var user []db.User - err := db.Db.Model(&db.User{}).Where("id = ?", id).Select("id", "username", "email", "uuid", "role", "first_name", "last_name", "verified", "friends").Find(&user).Error + var user db.User + err := db.Db.Model(&db.User{}).Where("id = ?", id).Select("id", "username", "email", "uuid", "role", "first_name", "last_name", "verified", "friends").First(&user).Error if err != nil { ctx.StatusCode(iris.StatusInternalServerError) ctx.JSON(types.CommonErrorResponse{ diff --git a/internal/database/models.go b/internal/database/models.go index d11ee38..09cd46f 100755 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -37,7 +37,7 @@ type User struct { Uuid string `json:"uuid"` Role string `json:"role"` Friends Friends `gorm:"type:VARCHAR(255)" json:"friends"` - Hash string `json:"hash"` + Hash string `json:"hash,omitempty"` Verified bool `json:"verified"` }