dev vouch dev on at. thats about it atvouch.dev
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

add count to getEntireGraph

Luna 9d4108d8 58b119f8

+62 -1
+6
appview/lib/atvouch/vouch.ex
··· 57 57 |> Atvouch.Repo.replica().all() 58 58 end 59 59 60 + def count do 61 + import Ecto.Query 62 + from(v in __MODULE__, select: count(v.at_uri)) 63 + |> Atvouch.Repo.replica().one() 64 + end 65 + 60 66 def paginated(limit, offset) do 61 67 import Ecto.Query 62 68
+13 -1
appview/lib/atvouch/xrpc_router.ex
··· 46 46 end 47 47 end 48 48 49 + options "/dev.atvouch.graph.getEntireGraph" do 50 + conn 51 + |> put_resp_header("access-control-allow-origin", "*") 52 + |> put_resp_header("access-control-allow-methods", "GET, OPTIONS") 53 + |> put_resp_header("access-control-allow-headers", "content-type") 54 + |> send_resp(204, "") 55 + end 56 + 49 57 get "/dev.atvouch.graph.getEntireGraph" do 50 58 conn = fetch_query_params(conn) 51 59 params = conn.query_params ··· 56 64 Atvouch.Vouch.paginated(limit, offset) 57 65 |> Enum.map(&to_vouch_view/1) 58 66 67 + total = Atvouch.Vouch.count() 68 + 59 69 next_cursor = 60 70 if length(vouches) == limit do 61 71 Integer.to_string(offset + limit) 62 72 end 63 73 64 - output = %GetEntireGraph.Output{vouches: vouches, cursor: next_cursor} 74 + output = %GetEntireGraph.Output{vouches: vouches, cursor: next_cursor, total: total} 65 75 66 76 conn 77 + |> put_resp_header("access-control-allow-origin", "*") 78 + |> put_resp_header("access-control-allow-methods", "GET, OPTIONS") 67 79 |> put_resp_content_type("application/json") 68 80 |> send_resp(200, Jason.encode!(output)) 69 81 else
+43
appview/test/atvouch/xrpc_vouches_test.exs
··· 194 194 refute body["cursor"] 195 195 end 196 196 197 + test "returns total count of vouches" do 198 + conn = 199 + conn(:get, "/xrpc/dev.atvouch.graph.getEntireGraph") 200 + |> Atvouch.Router.call(@opts) 201 + 202 + assert conn.status == 200 203 + body = Jason.decode!(conn.resp_body) 204 + assert body["total"] == 3 205 + end 206 + 207 + test "total count is consistent across paginated requests" do 208 + conn = 209 + conn(:get, "/xrpc/dev.atvouch.graph.getEntireGraph?limit=1") 210 + |> Atvouch.Router.call(@opts) 211 + 212 + assert conn.status == 200 213 + body = Jason.decode!(conn.resp_body) 214 + assert body["total"] == 3 215 + assert length(body["vouches"]) == 1 216 + end 217 + 218 + test "returns CORS headers allowing any origin" do 219 + conn = 220 + conn(:get, "/xrpc/dev.atvouch.graph.getEntireGraph") 221 + |> put_req_header("origin", "https://example.com") 222 + |> Atvouch.Router.call(@opts) 223 + 224 + assert conn.status == 200 225 + assert get_resp_header(conn, "access-control-allow-origin") == ["*"] 226 + assert "GET" in String.split(hd(get_resp_header(conn, "access-control-allow-methods")), ", ") 227 + end 228 + 229 + test "responds to CORS preflight OPTIONS request" do 230 + conn = 231 + conn(:options, "/xrpc/dev.atvouch.graph.getEntireGraph") 232 + |> put_req_header("origin", "https://example.com") 233 + |> put_req_header("access-control-request-method", "GET") 234 + |> Atvouch.Router.call(@opts) 235 + 236 + assert conn.status in [200, 204] 237 + assert get_resp_header(conn, "access-control-allow-origin") == ["*"] 238 + end 239 + 197 240 test "paginates with limit" do 198 241 conn = 199 242 conn(:get, "/xrpc/dev.atvouch.graph.getEntireGraph?limit=2")