feat: handler for get /users is implemented
All checks were successful
Build and Deploy Go App / build (push) Successful in 7m0s
Build and Deploy Go App / deploy (push) Successful in 44s

This commit is contained in:
Iron_Felix 2025-12-05 20:15:05 +03:00
parent fe18c0d865
commit 6a5994e33e
2 changed files with 67 additions and 0 deletions

View file

@ -485,3 +485,39 @@ func (s Server) GetUserTitle(ctx context.Context, request oapi.GetUserTitleReque
return oapi.GetUserTitle200JSONResponse(oapi_usertitle), nil return oapi.GetUserTitle200JSONResponse(oapi_usertitle), nil
} }
// GetUsers implements oapi.StrictServerInterface.
func (s *Server) GetUsers(ctx context.Context, request oapi.GetUsersRequestObject) (oapi.GetUsersResponseObject, error) {
params := sqlc.SearchUserParams{
Word: request.Params.Word,
Cursor: request.Params.CursorId,
Limit: request.Params.Limit,
}
_users, err := s.db.SearchUser(ctx, params)
if err != nil {
log.Errorf("%v", err)
return oapi.GetUsers500Response{}, nil
}
if len(_users) == 0 {
return oapi.GetUsers204Response{}, nil
}
var users []oapi.User
var cursor int64
for _, user := range _users {
oapi_user := oapi.User{ // maybe its possible to make one sqlc type and use one map func iinstead of this shit
// add image
CreationDate: &user.CreationDate,
DispName: user.DispName,
Id: &user.ID,
Mail: StringToEmail(user.Mail),
Nickname: user.Nickname,
UserDesc: user.UserDesc,
}
users = append(users, oapi_user)
cursor = user.ID
}
return oapi.GetUsers200JSONResponse{Data: users, Cursor: cursor}, nil
}

View file

@ -23,6 +23,37 @@ FROM users as t
LEFT JOIN images as i ON (t.avatar_id = i.id) LEFT JOIN images as i ON (t.avatar_id = i.id)
WHERE t.id = sqlc.arg('id')::bigint; WHERE t.id = sqlc.arg('id')::bigint;
-- name: SearchUser :many
SELECT
u.id AS id,
u.avatar_id AS avatar_id,
u.mail AS mail,
u.nickname AS nickname,
u.disp_name AS disp_name,
u.user_desc AS user_desc,
u.creation_date AS creation_date,
i.storage_type AS storage_type,
i.image_path AS image_path
FROM users AS u
LEFT JOIN images AS i ON u.avatar_id = i.id
WHERE
(
sqlc.narg('word')::text IS NULL
OR (
SELECT bool_and(
u.nickname ILIKE ('%' || term || '%')
OR u.disp_name ILIKE ('%' || term || '%')
)
FROM unnest(string_to_array(trim(sqlc.narg('word')::text), ' ')) AS term
WHERE term <> ''
)
)
AND (
sqlc.narg('cursor')::int IS NULL
OR u.id > sqlc.narg('cursor')::int
)
ORDER BY u.id ASC
LIMIT COALESCE(sqlc.narg('limit')::int, 20);
-- name: GetStudioByID :one -- name: GetStudioByID :one
SELECT * SELECT *