1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use boulder::{BuildableWithPersianRug, GeneratableWithPersianRug};
use boulder::{Inc, Pattern, Some as GSome};
use django_query::{
    filtering::FilterableWithPersianRug, row::IntoRowWithPersianRug,
    sorting::SortableWithPersianRug,
};
use persian_rug::{contextual, Context, Proxy};

/// A user in the LAVA API
// FIXME: Deriving sort and IntoRowWithPersianRug needlessly
#[derive(
    Clone,
    Debug,
    FilterableWithPersianRug,
    SortableWithPersianRug,
    IntoRowWithPersianRug,
    BuildableWithPersianRug,
    GeneratableWithPersianRug,
)]
#[django(persian_rug(context=C, access(User<C>, Group<C>)))]
#[boulder(persian_rug(context=C, access(User<C>, Group<C>)))]
#[contextual(C)]
pub struct User<C: Context + 'static> {
    #[boulder(generator=Inc(0))]
    #[django(sort)]
    pub id: i64,
    #[boulder(buildable_with_persian_rug, generatable_with_persian_rug)]
    #[django(traverse, foreign_key = "id")]
    pub group: Option<Proxy<Group<C>>>,
    #[boulder(default="test-username",
              generator=Pattern!("test-user-{}", Inc(1)))]
    #[django(op(in, contains, icontains, startswith, endswith))]
    pub username: String,
    #[boulder(default=Some("test@test.com".to_string()),
              generator=GSome(Pattern!("test-user-{}@example.com", Inc(1))))]
    #[django(op(in, contains, icontains, startswith, endswith))]
    pub email: Option<String>,
}

/// A group in the LAVA API
// FIXME: Deriving sort and IntoRowWithPersianRug needlessly
#[derive(
    Clone,
    Debug,
    FilterableWithPersianRug,
    SortableWithPersianRug,
    IntoRowWithPersianRug,
    BuildableWithPersianRug,
    GeneratableWithPersianRug,
)]
#[django(persian_rug(context=C, access(Group<C>)))]
#[boulder(persian_rug(context=C, access(Group<C>)))]
#[contextual(C)]
pub struct Group<C: Context + 'static> {
    #[django(exclude)]
    _marker: core::marker::PhantomData<C>,
    #[boulder(generator=Inc(0))]
    #[django(sort)]
    pub id: i64,
    #[boulder(default="test-group",
              generator=Pattern!("test-group-{}", Inc(1)))]
    #[django(op(in, contains, icontains, startswith, endswith))]
    pub name: String,
}