drawbridge_server/store/
user.rs1use super::{CreateError, Entity, Repository};
5
6use std::ops::Deref;
7
8use drawbridge_type::{Meta, RepositoryConfig, RepositoryName};
9
10use camino::{Utf8Path, Utf8PathBuf};
11use futures::try_join;
12
13#[repr(transparent)]
14#[derive(Copy, Clone, Debug)]
15pub struct User<'a, P = Utf8PathBuf>(Entity<'a, P>);
16
17impl<'a, P> Deref for User<'a, P> {
18 type Target = Entity<'a, P>;
19
20 fn deref(&self) -> &Self::Target {
21 &self.0
22 }
23}
24
25impl<'a, P> From<Entity<'a, P>> for User<'a, P> {
26 fn from(entity: Entity<'a, P>) -> Self {
27 Self(entity)
28 }
29}
30
31impl<'a, P: AsRef<Utf8Path>> User<'a, P> {
32 pub fn repository(&self, name: &RepositoryName) -> Repository<'a, Utf8PathBuf> {
33 self.0.child(format!("repos/{name}")).into()
34 }
35
36 pub async fn create_repository(
37 &self,
38 name: &RepositoryName,
39 meta: Meta,
40 conf: &RepositoryConfig,
41 ) -> Result<Repository<'a, Utf8PathBuf>, CreateError<anyhow::Error>> {
42 let repo = self.repository(name);
43 repo.create_dir("").await?;
44 try_join!(repo.create_json(meta, conf), repo.create_dir("tags"))?;
45 Ok(repo)
46 }
47}