feat: QR Codes (#226)

* code gen updates

* qrcode support

* remove opacity on toast

* update item view to use tab-like pages

* adjust view for cards

* fix old API calls for ioutils

* move embed

* extract QR code

* add docs for QR codes

* add QR code
This commit is contained in:
Hayden 2023-01-18 20:44:06 -09:00 committed by GitHub
parent f532b39c46
commit c19fe94c08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 3151 additions and 6454 deletions

View file

@ -30,6 +30,7 @@ type GroupQuery struct {
unique *bool
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Group
withUsers *UserQuery
withLocations *LocationQuery
@ -48,13 +49,13 @@ func (gq *GroupQuery) Where(ps ...predicate.Group) *GroupQuery {
return gq
}
// Limit adds a limit step to the query.
// Limit the number of records to be returned by this query.
func (gq *GroupQuery) Limit(limit int) *GroupQuery {
gq.limit = &limit
return gq
}
// Offset adds an offset step to the query.
// Offset to start from.
func (gq *GroupQuery) Offset(offset int) *GroupQuery {
gq.offset = &offset
return gq
@ -67,7 +68,7 @@ func (gq *GroupQuery) Unique(unique bool) *GroupQuery {
return gq
}
// Order adds an order step to the query.
// Order specifies how the records should be ordered.
func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery {
gq.order = append(gq.order, o...)
return gq
@ -75,7 +76,7 @@ func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery {
// QueryUsers chains the current query on the "users" edge.
func (gq *GroupQuery) QueryUsers() *UserQuery {
query := &UserQuery{config: gq.config}
query := (&UserClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -97,7 +98,7 @@ func (gq *GroupQuery) QueryUsers() *UserQuery {
// QueryLocations chains the current query on the "locations" edge.
func (gq *GroupQuery) QueryLocations() *LocationQuery {
query := &LocationQuery{config: gq.config}
query := (&LocationClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -119,7 +120,7 @@ func (gq *GroupQuery) QueryLocations() *LocationQuery {
// QueryItems chains the current query on the "items" edge.
func (gq *GroupQuery) QueryItems() *ItemQuery {
query := &ItemQuery{config: gq.config}
query := (&ItemClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -141,7 +142,7 @@ func (gq *GroupQuery) QueryItems() *ItemQuery {
// QueryLabels chains the current query on the "labels" edge.
func (gq *GroupQuery) QueryLabels() *LabelQuery {
query := &LabelQuery{config: gq.config}
query := (&LabelClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -163,7 +164,7 @@ func (gq *GroupQuery) QueryLabels() *LabelQuery {
// QueryDocuments chains the current query on the "documents" edge.
func (gq *GroupQuery) QueryDocuments() *DocumentQuery {
query := &DocumentQuery{config: gq.config}
query := (&DocumentClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -185,7 +186,7 @@ func (gq *GroupQuery) QueryDocuments() *DocumentQuery {
// QueryInvitationTokens chains the current query on the "invitation_tokens" edge.
func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery {
query := &GroupInvitationTokenQuery{config: gq.config}
query := (&GroupInvitationTokenClient{config: gq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
@ -208,7 +209,7 @@ func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery {
// First returns the first Group entity from the query.
// Returns a *NotFoundError when no Group was found.
func (gq *GroupQuery) First(ctx context.Context) (*Group, error) {
nodes, err := gq.Limit(1).All(ctx)
nodes, err := gq.Limit(1).All(newQueryContext(ctx, TypeGroup, "First"))
if err != nil {
return nil, err
}
@ -231,7 +232,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group {
// Returns a *NotFoundError when no Group ID was found.
func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gq.Limit(1).IDs(ctx); err != nil {
if ids, err = gq.Limit(1).IDs(newQueryContext(ctx, TypeGroup, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@ -254,7 +255,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Group entity is found.
// Returns a *NotFoundError when no Group entities are found.
func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) {
nodes, err := gq.Limit(2).All(ctx)
nodes, err := gq.Limit(2).All(newQueryContext(ctx, TypeGroup, "Only"))
if err != nil {
return nil, err
}
@ -282,7 +283,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group {
// Returns a *NotFoundError when no entities are found.
func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gq.Limit(2).IDs(ctx); err != nil {
if ids, err = gq.Limit(2).IDs(newQueryContext(ctx, TypeGroup, "OnlyID")); err != nil {
return
}
switch len(ids) {
@ -307,10 +308,12 @@ func (gq *GroupQuery) OnlyIDX(ctx context.Context) uuid.UUID {
// All executes the query and returns a list of Groups.
func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) {
ctx = newQueryContext(ctx, TypeGroup, "All")
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
}
return gq.sqlAll(ctx)
qr := querierAll[[]*Group, *GroupQuery]()
return withInterceptors[[]*Group](ctx, gq, qr, gq.inters)
}
// AllX is like All, but panics if an error occurs.
@ -325,6 +328,7 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group {
// IDs executes the query and returns a list of Group IDs.
func (gq *GroupQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = newQueryContext(ctx, TypeGroup, "IDs")
if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@ -342,10 +346,11 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []uuid.UUID {
// Count returns the count of the given query.
func (gq *GroupQuery) Count(ctx context.Context) (int, error) {
ctx = newQueryContext(ctx, TypeGroup, "Count")
if err := gq.prepareQuery(ctx); err != nil {
return 0, err
}
return gq.sqlCount(ctx)
return withInterceptors[int](ctx, gq, querierCount[*GroupQuery](), gq.inters)
}
// CountX is like Count, but panics if an error occurs.
@ -359,10 +364,15 @@ func (gq *GroupQuery) CountX(ctx context.Context) int {
// Exist returns true if the query has elements in the graph.
func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) {
if err := gq.prepareQuery(ctx); err != nil {
return false, err
ctx = newQueryContext(ctx, TypeGroup, "Exist")
switch _, err := gq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
return gq.sqlExist(ctx)
}
// ExistX is like Exist, but panics if an error occurs.
@ -385,6 +395,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
limit: gq.limit,
offset: gq.offset,
order: append([]OrderFunc{}, gq.order...),
inters: append([]Interceptor{}, gq.inters...),
predicates: append([]predicate.Group{}, gq.predicates...),
withUsers: gq.withUsers.Clone(),
withLocations: gq.withLocations.Clone(),
@ -402,7 +413,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
// WithUsers tells the query-builder to eager-load the nodes that are connected to
// the "users" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery {
query := &UserQuery{config: gq.config}
query := (&UserClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -413,7 +424,7 @@ func (gq *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery {
// WithLocations tells the query-builder to eager-load the nodes that are connected to
// the "locations" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithLocations(opts ...func(*LocationQuery)) *GroupQuery {
query := &LocationQuery{config: gq.config}
query := (&LocationClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -424,7 +435,7 @@ func (gq *GroupQuery) WithLocations(opts ...func(*LocationQuery)) *GroupQuery {
// WithItems tells the query-builder to eager-load the nodes that are connected to
// the "items" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithItems(opts ...func(*ItemQuery)) *GroupQuery {
query := &ItemQuery{config: gq.config}
query := (&ItemClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -435,7 +446,7 @@ func (gq *GroupQuery) WithItems(opts ...func(*ItemQuery)) *GroupQuery {
// WithLabels tells the query-builder to eager-load the nodes that are connected to
// the "labels" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithLabels(opts ...func(*LabelQuery)) *GroupQuery {
query := &LabelQuery{config: gq.config}
query := (&LabelClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -446,7 +457,7 @@ func (gq *GroupQuery) WithLabels(opts ...func(*LabelQuery)) *GroupQuery {
// WithDocuments tells the query-builder to eager-load the nodes that are connected to
// the "documents" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithDocuments(opts ...func(*DocumentQuery)) *GroupQuery {
query := &DocumentQuery{config: gq.config}
query := (&DocumentClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -457,7 +468,7 @@ func (gq *GroupQuery) WithDocuments(opts ...func(*DocumentQuery)) *GroupQuery {
// WithInvitationTokens tells the query-builder to eager-load the nodes that are connected to
// the "invitation_tokens" edge. The optional arguments are used to configure the query builder of the edge.
func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQuery)) *GroupQuery {
query := &GroupInvitationTokenQuery{config: gq.config}
query := (&GroupInvitationTokenClient{config: gq.config}).Query()
for _, opt := range opts {
opt(query)
}
@ -480,16 +491,11 @@ func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQue
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
grbuild := &GroupGroupBy{config: gq.config}
grbuild.fields = append([]string{field}, fields...)
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
if err := gq.prepareQuery(ctx); err != nil {
return nil, err
}
return gq.sqlQuery(ctx), nil
}
gq.fields = append([]string{field}, fields...)
grbuild := &GroupGroupBy{build: gq}
grbuild.flds = &gq.fields
grbuild.label = group.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@ -507,10 +513,10 @@ func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
// Scan(ctx, &v)
func (gq *GroupQuery) Select(fields ...string) *GroupSelect {
gq.fields = append(gq.fields, fields...)
selbuild := &GroupSelect{GroupQuery: gq}
selbuild.label = group.Label
selbuild.flds, selbuild.scan = &gq.fields, selbuild.Scan
return selbuild
sbuild := &GroupSelect{GroupQuery: gq}
sbuild.label = group.Label
sbuild.flds, sbuild.scan = &gq.fields, sbuild.Scan
return sbuild
}
// Aggregate returns a GroupSelect configured with the given aggregations.
@ -519,6 +525,16 @@ func (gq *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect {
}
func (gq *GroupQuery) prepareQuery(ctx context.Context) error {
for _, inter := range gq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, gq); err != nil {
return err
}
}
}
for _, f := range gq.fields {
if !group.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
@ -808,17 +824,6 @@ func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) {
return sqlgraph.CountNodes(ctx, gq.driver, _spec)
}
func (gq *GroupQuery) sqlExist(ctx context.Context) (bool, error) {
switch _, err := gq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec {
_spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
@ -901,13 +906,8 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
// GroupGroupBy is the group-by builder for Group entities.
type GroupGroupBy struct {
config
selector
fields []string
fns []AggregateFunc
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
build *GroupQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
@ -916,58 +916,46 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy {
return ggb
}
// Scan applies the group-by query and scans the result into the given value.
// Scan applies the selector query and scans the result into the given value.
func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error {
query, err := ggb.path(ctx)
if err != nil {
ctx = newQueryContext(ctx, TypeGroup, "GroupBy")
if err := ggb.build.prepareQuery(ctx); err != nil {
return err
}
ggb.sql = query
return ggb.sqlScan(ctx, v)
return scanWithInterceptors[*GroupQuery, *GroupGroupBy](ctx, ggb.build, ggb, ggb.build.inters, v)
}
func (ggb *GroupGroupBy) sqlScan(ctx context.Context, v any) error {
for _, f := range ggb.fields {
if !group.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
}
func (ggb *GroupGroupBy) sqlScan(ctx context.Context, root *GroupQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(ggb.fns))
for _, fn := range ggb.fns {
aggregation = append(aggregation, fn(selector))
}
selector := ggb.sqlQuery()
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*ggb.flds)+len(ggb.fns))
for _, f := range *ggb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*ggb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := ggb.driver.Query(ctx, query, args, rows); err != nil {
if err := ggb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
func (ggb *GroupGroupBy) sqlQuery() *sql.Selector {
selector := ggb.sql.Select()
aggregation := make([]string, 0, len(ggb.fns))
for _, fn := range ggb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(ggb.fields)+len(ggb.fns))
for _, f := range ggb.fields {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
return selector.GroupBy(selector.Columns(ggb.fields...)...)
}
// GroupSelect is the builder for selecting fields of Group entities.
type GroupSelect struct {
*GroupQuery
selector
// intermediate query (i.e. traversal path).
sql *sql.Selector
}
// Aggregate adds the given aggregation functions to the selector query.
@ -978,26 +966,27 @@ func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect {
// Scan applies the selector query and scans the result into the given value.
func (gs *GroupSelect) Scan(ctx context.Context, v any) error {
ctx = newQueryContext(ctx, TypeGroup, "Select")
if err := gs.prepareQuery(ctx); err != nil {
return err
}
gs.sql = gs.GroupQuery.sqlQuery(ctx)
return gs.sqlScan(ctx, v)
return scanWithInterceptors[*GroupQuery, *GroupSelect](ctx, gs.GroupQuery, gs, gs.inters, v)
}
func (gs *GroupSelect) sqlScan(ctx context.Context, v any) error {
func (gs *GroupSelect) sqlScan(ctx context.Context, root *GroupQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(gs.fns))
for _, fn := range gs.fns {
aggregation = append(aggregation, fn(gs.sql))
aggregation = append(aggregation, fn(selector))
}
switch n := len(*gs.selector.flds); {
case n == 0 && len(aggregation) > 0:
gs.sql.Select(aggregation...)
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
gs.sql.AppendSelect(aggregation...)
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := gs.sql.Query()
query, args := selector.Query()
if err := gs.driver.Query(ctx, query, args, rows); err != nil {
return err
}