| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using InvercargillSql.Orm.Projections;
- using Invercargill.DataStructures;
- using Spry.Authorisation;
- using Invercargill;
- using Invercargill.Expressions;
- namespace Spry.Authentication {
- public class UserProjection : Object, Identity {
- public Element identifier { owned get { return new NativeElement<int64?>(id); } }
- public string username { get { return _username; } }
- public ImmutableLot<string> permissions { owned get { return _permissions.to_immutable_buffer(); } }
- public Invercargill.Properties data { owned get {
- var props = new DataStructures.PropertyDictionary();
- props.set_native<string>("email", email);
- props.set_native<string>("forename", forename);
- props.set_native<string>("surname", surname);
- props.set_native<DateTime>("date_of_birth", date_of_birth);
- props.set_native<DateTime>("created", created);
- props.set_native<DateTime>("modified", modified);
- return props;
- }}
- public int64 id { get; set; }
- public string email { get; set; }
- public string forename { get; set; }
- public string surname { get; set; }
- public string password_hash { get; set; }
- public DateTime date_of_birth { get; set; }
- public DateTime created { get; set; }
- public DateTime modified { get; set; }
- public bool enabled { get; set; }
- private string _username;
- private ImmutableBuffer<string> _permissions;
- public static void projection_mapping(ProjectionBuilder<UserProjection> cfg) throws Error {
- cfg.source<UserEntity>("u")
- .select<int64?>("id", expr("u.id"), (o, v) => o.id = v)
- .select<string>("username", expr("u.username"), (o, v) => o._username = v)
- .select<string>("email", expr("u.email"), (o, v) => o.email = v)
- .select<string>("forename", expr("u.forename"), (o, v) => o.forename = v)
- .select<string>("surname", expr("u.surname"), (o, v) => o.surname = v)
- .select<string>("password_hash", expr("u.password_hash"), (o, v) => o.password_hash = v)
- .select<DateTime>("date_of_birth", expr("u.date_of_birth"), (o, v) => o.date_of_birth = v)
- .select<DateTime>("created", expr("u.created"), (o, v) => o.created = v)
- .select<DateTime>("modified", expr("u.modified"), (o, v) => o.modified = v)
- .select<bool>("enabled", expr("u.enabled"), (o, v) => o.enabled = v)
- .join<UserPermissionEntity>("p", expr("p.user_id == u.id"))
- .select_many<string>("permissions", expr("p.permission"), (o, v) => o._permissions = v.to_immutable_buffer());
- }
- }
- }
|