Skip to content

Commit bcad4d7

Browse files
committed
fix users handle endpoint.
as it turns out python would return an array here.
1 parent 0680ac9 commit bcad4d7

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

api/resolve_middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (app *ApiServer) requireHandleMiddleware(c *fiber.Ctx) error {
3535
if err != nil {
3636
return err
3737
}
38-
c.Locals("userId", userId)
38+
c.Locals("userId", int(userId))
3939
return c.Next()
4040
}
4141

api/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func NewApiServer(config Config) *ApiServer {
126126
g.Get("/users", app.v1Users)
127127

128128
g.Use("/users/handle/:handle", app.requireHandleMiddleware)
129+
g.Get("/users/handle/:handle", app.v1User)
129130
g.Get("/users/handle/:handle/tracks", app.v1UserTracks)
130131
g.Get("/users/handle/:handle/reposts", app.v1UsersReposts)
131132

api/server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func Test200(t *testing.T) {
9292
"/v1/full/users/7eP5n/supporting",
9393
"/v1/full/users/7eP5n/tracks",
9494

95+
"/v1/full/users/handle/rayjacobson",
9596
"/v1/full/users/handle/rayjacobson/tracks",
9697
"/v1/full/users/handle/rayjacobson/reposts",
9798

api/v1_user.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ func (app *ApiServer) v1User(c *fiber.Ctx) error {
2222
return sendError(c, 404, "user not found")
2323
}
2424

25-
user := users[0]
26-
27-
return v1UserResponse(c, user)
25+
return v1UsersResponse(c, users)
2826
}

api/v1_user_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestGetUser(t *testing.T) {
1212
var userResponse struct {
13-
Data dbv1.FullUser
13+
Data []dbv1.FullUser
1414
}
1515

1616
status, body := testGet(t, "/v1/full/users/7eP5n", &userResponse)
@@ -23,5 +23,5 @@ func TestGetUser(t *testing.T) {
2323

2424
// but we also unmarshaled into userResponse
2525
// for structured testing
26-
assert.Equal(t, userResponse.Data.ID, "7eP5n")
26+
assert.Equal(t, userResponse.Data[0].ID, "7eP5n")
2727
}

apidiff.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const testPaths = [
1010
"/v1/users/0EoAm",
1111
"/v1/full/users?id=invalid_id1&id=aNzoj",
1212

13+
"/v1/full/users/handle/stereosteve",
14+
15+
"/v1/full/tracks/ZaXp01y",
16+
1317
"/v1/full/tracks?id=ZaXp01y&user_id=aNzoj",
1418
"/v1/full/tracks?id=ZaXp01y&user_id=7eP5n",
1519
"/v1/full/tracks?id=ZaXp01y&id=5zdbywJ&id=Pb4MbAX&id=YVog04p&id=7Mv7ZMP&id=g5yzMy2&id=P7dlqNR&id=RR7krAG&id=O7OdxYV&id=72oXyvr&id=jYWyGG0&id=W6KOm8k&id=Xj554dq&id=gbOmq7k&id=G0z4Ap7&id=Yo0XYMm&id=80jlRwP&id=X63z9Wq&id=lZYWRKb&id=JEz6V0o&id=JZq6550&id=b9rbNdM&id=yy71xr7&id=JGNob5Z&id=VpxQ2Aa&id=qGbEZdz&id=B94qO0j&id=oRGgBka&id=jzwlVj0&id=Y5PNmOr&id=5zRm7dx&id=r3KjOg&id=WVP8qav&id=Nvayj1Y&id=V6GZJ3b&id=YoWO0MJ&id=JboVK8Y&id=9bbRG02&id=QRgjAJR&id=gWaBbkW&id=79q1xY7&id=51o1r9J&id=AMJ7d3k&id=O6ZKK0V&id=RpVzBx1&id=VPdaGdQ&id=lv7Obol&id=GQpBNxw&id=83xb96v&id=BJoM2Qx&id=bQoMKlK&id=8E1QjMW&id=O5OVlK4&id=63Gz0yQ&user_id=aNzoj",
@@ -65,14 +69,17 @@ import * as jsondiffpatch from "https://esm.sh/jsondiffpatch@0.6.0";
6569
import * as htmlFormatter from "https://esm.sh/jsondiffpatch@0.6.0/formatters/html";
6670

6771
Deno.serve({ port: 62185 }, async (req) => {
72+
const oldHost = "https://discoveryprovider.audius.co";
73+
const newHost = "http://localhost:1323";
74+
6875
const reqUrl = new URL(req.url);
6976
const idx = parseInt(reqUrl.searchParams.get("idx") || "0");
7077
const path = testPaths[idx];
7178
if (!path || path == "/favicon.ico") return new Response("not found");
7279

7380
const [r1, r2] = await Promise.all([
74-
fetchJson("https://discoveryprovider.audius.co" + path),
75-
fetchJson("http://localhost:1323" + path),
81+
fetchJson(oldHost + path),
82+
fetchJson(newHost + path),
7683
]);
7784

7885
const json1 = r1.data;
@@ -99,7 +106,7 @@ Deno.serve({ port: 62185 }, async (req) => {
99106
<style>
100107
del {
101108
background: #ffbbbb;
102-
text-decoration: line-through;
109+
text-decoration: none;
103110
}
104111
ins {
105112
background: #bbffbb;
@@ -125,8 +132,12 @@ Deno.serve({ port: 62185 }, async (req) => {
125132
126133
<pre>${path}</pre>
127134
<div>
128-
<del>${r1.took}ms</del>
129-
<ins>${r2.took}ms</ins>
135+
<a href="${oldHost + path}" target="_blank">
136+
<del>${r1.took}ms</del>
137+
</a>
138+
<a href="${newHost + path}" target="_blank">
139+
<ins>${r2.took}ms</ins>
140+
</a>
130141
</div>
131142
<div>${htmlFormatter.format(delta, json1)}</div>
132143
</body>

0 commit comments

Comments
 (0)