|
1 | 1 | package api |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bridgerton.audius.co/api/dbv1" |
5 | 4 | "github.com/gofiber/fiber/v2" |
6 | 5 | ) |
7 | 6 |
|
8 | 7 | // todo: in python this route requires auth |
9 | 8 | func (app *ApiServer) v1UsersAccount(c *fiber.Ctx) error { |
10 | | - // resolve wallet to user id |
11 | | - var userId int32 |
12 | | - |
13 | | - // todo: this is a duplicate of the authMiddleware, make it common? |
14 | | - err := app.pool.QueryRow( |
15 | | - c.Context(), |
16 | | - ` |
17 | | - SELECT user_id FROM users |
18 | | - WHERE |
19 | | - wallet = lower($1) |
20 | | - AND is_current = true |
21 | | - ORDER BY handle IS NOT NULL, created_at ASC |
22 | | - LIMIT 1 |
23 | | - `, |
24 | | - c.Params("wallet"), |
25 | | - ).Scan(&userId) |
26 | | - |
27 | | - if err != nil { |
28 | | - return err |
| 9 | + wallet := c.Params("wallet") |
| 10 | + if wallet == "" { |
| 11 | + return fiber.NewError(fiber.StatusBadRequest, "Missing wallet parameter") |
29 | 12 | } |
30 | 13 |
|
31 | | - users, err := app.queries.FullUsers(c.Context(), dbv1.GetUsersParams{ |
32 | | - Ids: []int32{userId}, |
33 | | - MyID: userId, |
34 | | - }) |
| 14 | + account, err := app.queries.FullAccount(c.Context(), wallet) |
35 | 15 | if err != nil { |
36 | 16 | return err |
37 | 17 | } |
38 | | - if len(users) == 0 { |
39 | | - return sendError(c, 404, "wallet not found") |
40 | | - } |
41 | | - |
42 | | - playlists, err := app.queries.FullAccountPlaylists(c.Context(), userId) |
43 | | - if err != nil { |
44 | | - return err |
45 | | - } |
46 | | - |
47 | | - // Extract playlist_library from user record |
48 | | - playlistLibrary := users[0].PlaylistLibrary |
49 | | - trackSaveCount := users[0].TrackSaveCount |
50 | | - // Create a copy of the user without playlist_library/track_save_count as |
51 | | - // they are deprecated fields and we will return them as siblings |
52 | | - userWithoutLibrary := users[0] |
53 | | - userWithoutLibrary.PlaylistLibrary = nil |
54 | | - userWithoutLibrary.TrackSaveCount = nil |
55 | 18 |
|
56 | | - // this route does not have a non-full version... |
57 | | - // and also nests user under data.user |
58 | | - // and there are some additional fields |
59 | | - // so we don't use the v1UserResponse helper |
60 | 19 | return c.JSON(fiber.Map{ |
61 | | - "data": fiber.Map{ |
62 | | - "track_save_count": trackSaveCount, |
63 | | - "playlists": playlists, |
64 | | - "playlist_library": playlistLibrary, |
65 | | - "user": userWithoutLibrary, |
66 | | - }, |
| 20 | + "data": account, |
67 | 21 | }) |
68 | 22 | } |
0 commit comments