Skip to content

Commit

Permalink
add /all/users and /all/packages endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Jan 29, 2022
1 parent 25961c1 commit a322fb2
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/db/Package.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub fn create(alloc: std.mem.Allocator, owner: User, name: string, remote: Remot
});
}

pub fn all(alloc: std.mem.Allocator, comptime ord: _internal.Order) ![]const Package {
return try db.collect(alloc, Package, "select * from packages order by id " ++ @tagName(ord), .{});
}

usingnamespace _internal.TableTypeMixin(Package);
usingnamespace _internal.ByKeyGen(Package);

Expand Down
4 changes: 4 additions & 0 deletions src/db/User.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub fn create(alloc: std.mem.Allocator, provider: u64, snowflake: string, name:
});
}

pub fn all(alloc: std.mem.Allocator, comptime ord: _internal.Order) ![]const User {
return try db.collect(alloc, User, "select * from users order by id " ++ @tagName(ord), .{});
}

usingnamespace _internal.TableTypeMixin(User);
usingnamespace _internal.ByKeyGen(User);

Expand Down
3 changes: 3 additions & 0 deletions src/handler/_handler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const _import = @import("./import.zig");
const _do_import = @import("./do_import.zig");
const _hook = @import("./hook.zig");
const _version = @import("./version.zig");
const _all = @import("./all.zig");

pub fn init(alloc: std.mem.Allocator) !void {
_internal.jwt_secret = try extras.randomSlice(alloc, std.crypto.random, u8, 64);
Expand All @@ -40,6 +41,8 @@ pub fn getHandler(comptime oa2: type) http.RequestHandler(void) {
http.router.get("/dashboard", Middleware(_dashboard.get).next),
http.router.get("/import", Middleware(_import.get).next),
http.router.get("/do_import", Middleware(_do_import.get).next),
http.router.get("/all/users", Middleware(_all.users).next),
http.router.get("/all/packages", Middleware(_all.packages).next),
http.router.get("/:remote/:user", Middleware(_user.get).next),
http.router.get("/:remote/:user/:package", Middleware(_package.get).next),
http.router.post("/:remote/:user/:package/hook", Middleware(_hook.post).next),
Expand Down
29 changes: 29 additions & 0 deletions src/handler/all.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const http = @import("apple_pie");

const db = @import("./../db/_db.zig");

const _internal = @import("./_internal.zig");

pub fn users(_: void, response: *http.Response, request: http.Request, args: struct {}) !void {
_ = args;
const alloc = request.arena;

try _internal.writePageResponse(alloc, response, request, "/all_users.pek", .{
.aquila_version = @import("root").version,
.title = "All Users",
.user = try _internal.getUserOp(response, request),
.list = try db.User.all(alloc, .asc),
});
}

pub fn packages(_: void, response: *http.Response, request: http.Request, args: struct {}) !void {
_ = args;
const alloc = request.arena;

try _internal.writePageResponse(alloc, response, request, "/all_packages.pek", .{
.aquila_version = @import("root").version,
.title = "All Packages",
.user = try _internal.getUserOp(response, request),
.list = try db.Package.all(alloc, .desc),
});
}
23 changes: 23 additions & 0 deletions www/all_packages.pek
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
h1("All Packages")
div(
{#each list}
div[class="terminal-card"](
div(
h3[class="wide-title" style="margin-bottom: 0;"](
a[href=("../"{#get_user_path this.owner}"/"{this.name})]({#get_user_path this.owner}"/"{this.name})
div(
i[class="tag icon"]{this.latest_version}" "
i[class="balance scale icon"]" "{#if this.license}{this.license}<else>"No"/if/" License"
)
div
)
{#if this.description}
div({this.description}"&nbsp;")
/if/
)
)
/each/
)
)
)
)
9 changes: 9 additions & 0 deletions www/all_users.pek
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
h1("All Users")
ul(
{#each list}
li(a[href=("../"{this.provider}"/"{this.name})]({this.provider}"/"{this.name}))
/each/
)
)
)
)
2 changes: 1 addition & 1 deletion www/index.pek
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
h1("Aquila")
p("A federated package index and CI system for the Zig programming language built around the "a[href="https://github.com/nektro/zigmod"]("Zigmod")" package manager.")
p("Join the "a({user_count}" users")" and "a({pkg_count}" packages")" already on Aquila to get started today!")
p("Join the "a[href="./all/users"]({user_count}" users")" and "a[href="./all/packages"]({pkg_count}" packages")" already on Aquila to get started today!")
p(a[href="./dashboard" class="btn btn-primary"]("Login"))
hr
div[class="home-cols"](
Expand Down
11 changes: 11 additions & 0 deletions www/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ img.badge {
height: 15px;
image-rendering: pixelated;
}
.wide-title {
margin-bottom: 0;
display: flex;
justify-content: space-between;
}
.wide-title a {
display: block;
}
.wide-title div {
font-weight: normal;
}

0 comments on commit a322fb2

Please sign in to comment.