feat: now GetUser returnes all the image info
This commit is contained in:
parent
673ce48fac
commit
3aafab36c2
6 changed files with 63 additions and 33 deletions
|
|
@ -27,16 +27,25 @@ import (
|
|||
// return int32(i), err
|
||||
// }
|
||||
|
||||
func mapUser(u sqlc.GetUserByIDRow) oapi.User {
|
||||
func mapUser(u sqlc.GetUserByIDRow) (oapi.User, error) {
|
||||
i := oapi.Image{
|
||||
Id: u.AvatarID,
|
||||
ImagePath: u.ImagePath,
|
||||
}
|
||||
s, err := sql2StorageType(u.StorageType)
|
||||
if err != nil {
|
||||
return oapi.User{}, fmt.Errorf("mapUser, storage type: %v", err)
|
||||
}
|
||||
i.StorageType = s
|
||||
return oapi.User{
|
||||
AvatarId: u.AvatarID,
|
||||
Image: &i,
|
||||
CreationDate: &u.CreationDate,
|
||||
DispName: u.DispName,
|
||||
Id: &u.ID,
|
||||
Mail: StringToEmail(u.Mail),
|
||||
Nickname: u.Nickname,
|
||||
UserDesc: u.UserDesc,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s Server) GetUsersUserId(ctx context.Context, req oapi.GetUsersUserIdRequestObject) (oapi.GetUsersUserIdResponseObject, error) {
|
||||
|
|
@ -44,14 +53,19 @@ func (s Server) GetUsersUserId(ctx context.Context, req oapi.GetUsersUserIdReque
|
|||
if err != nil {
|
||||
return oapi.GetUsersUserId404Response{}, nil
|
||||
}
|
||||
user, err := s.db.GetUserByID(context.TODO(), int64(userID))
|
||||
_user, err := s.db.GetUserByID(context.TODO(), int64(userID))
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return oapi.GetUsersUserId404Response{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return oapi.GetUsersUserId200JSONResponse(mapUser(user)), nil
|
||||
user, err := mapUser(_user)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
return oapi.GetUsersUserId500Response{}, err
|
||||
}
|
||||
return oapi.GetUsersUserId200JSONResponse(user), nil
|
||||
}
|
||||
|
||||
func sqlDate2oapi(p_date pgtype.Timestamptz) *time.Time {
|
||||
|
|
@ -327,7 +341,7 @@ func (s Server) UpdateUser(ctx context.Context, request oapi.UpdateUserRequestOb
|
|||
}
|
||||
|
||||
oapi_user := oapi.User{ // maybe its possible to make one sqlc type and use one map func iinstead of this shit
|
||||
AvatarId: user.AvatarID,
|
||||
// AvatarId: user.AvatarID,
|
||||
CreationDate: &user.CreationDate,
|
||||
DispName: user.DispName,
|
||||
Id: &user.ID,
|
||||
|
|
|
|||
|
|
@ -9,9 +9,19 @@ VALUES ($1, $2)
|
|||
RETURNING id, storage_type, image_path;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT id, avatar_id, mail, nickname, disp_name, user_desc, creation_date
|
||||
FROM users
|
||||
WHERE id = $1;
|
||||
SELECT
|
||||
t.id as id,
|
||||
t.avatar_id as avatar_id,
|
||||
t.mail as mail,
|
||||
t.nickname as nickname,
|
||||
t.disp_name as disp_name,
|
||||
t.user_desc as user_desc,
|
||||
t.creation_date as creation_date,
|
||||
i.storage_type as storage_type,
|
||||
i.image_path as image_path
|
||||
FROM users as t
|
||||
LEFT JOIN images as i ON (t.avatar_id = i.id)
|
||||
WHERE id = sqlc.arg('id')::bigint;
|
||||
|
||||
|
||||
-- name: GetStudioByID :one
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue