79 lines
2.3 KiB
Zig
79 lines
2.3 KiB
Zig
const std = @import("std");
|
|
const util = @import("util");
|
|
|
|
const Uuid = util.Uuid;
|
|
const DateTime = util.DateTime;
|
|
|
|
const communities = @import("./services/communities.zig");
|
|
const actors = @import("./services/actors.zig");
|
|
const drive = @import("./services/drive.zig");
|
|
const files = @import("./services/files.zig");
|
|
const invites = @import("./services/invites.zig");
|
|
const notes = @import("./services/notes.zig");
|
|
const follows = @import("./services/follows.zig");
|
|
const accounts = @import("./services/accounts.zig");
|
|
const tokens = @import("./services/tokens.zig");
|
|
|
|
pub const Token = tokens.Token;
|
|
pub const Account = accounts.Account;
|
|
pub const Credentials = accounts.Credentials;
|
|
|
|
pub fn Services(comptime Db: type) type {
|
|
return struct {
|
|
const Self = @This();
|
|
|
|
db: Db,
|
|
|
|
pub fn beginTx(self: Self) !Services(Db.BeginOrSavepoint) {
|
|
return Services(Db.BeginOrSavepoint){
|
|
.db = try self.db.beginOrSavepoint(),
|
|
};
|
|
}
|
|
|
|
pub fn commitTx(self: Self) !void {
|
|
return try self.db.commitOrRelease();
|
|
}
|
|
|
|
pub fn rollbackTx(self: Self) void {
|
|
return self.db.rollback();
|
|
}
|
|
|
|
pub fn createAccount(
|
|
self: Self,
|
|
alloc: std.mem.Allocator,
|
|
actor: Uuid,
|
|
password_hash: []const u8,
|
|
options: accounts.CreateOptions,
|
|
) !Account {
|
|
return try accounts.create(self.db, actor, password_hash, options, alloc);
|
|
}
|
|
|
|
pub fn getCredentialsByUsername(
|
|
self: Self,
|
|
alloc: std.mem.Allocator,
|
|
username: []const u8,
|
|
community_id: Uuid,
|
|
) !Credentials {
|
|
return try accounts.getCredentialsByUsername(self.db, username, community_id, alloc);
|
|
}
|
|
|
|
pub fn createToken(
|
|
self: Self,
|
|
alloc: std.mem.Allocator,
|
|
account_id: Uuid,
|
|
hash: []const u8,
|
|
) !void {
|
|
return try tokens.create(self.db, account_id, hash, alloc);
|
|
}
|
|
|
|
pub fn getTokenByHash(
|
|
self: Self,
|
|
alloc: std.mem.Allocator,
|
|
hash: []const u8,
|
|
community_id: Uuid,
|
|
) !Token {
|
|
return try tokens.getByHash(self.db, hash, community_id, alloc);
|
|
}
|
|
};
|
|
}
|