Documentation
¶
Index ¶
- func FormatError(err error) error
- func FormatLimitOffset(limit, offset int) string
- type AuthService
- func (s *AuthService) CreateAuth(ctx context.Context, auth *wtf.Auth) error
- func (s *AuthService) DeleteAuth(ctx context.Context, id int) error
- func (s *AuthService) FindAuthByID(ctx context.Context, id int) (*wtf.Auth, error)
- func (s *AuthService) FindAuths(ctx context.Context, filter wtf.AuthFilter) ([]*wtf.Auth, int, error)
- type DB
- type DialMembershipService
- func (s *DialMembershipService) CreateDialMembership(ctx context.Context, membership *wtf.DialMembership) error
- func (s *DialMembershipService) DeleteDialMembership(ctx context.Context, id int) error
- func (s *DialMembershipService) FindDialMembershipByID(ctx context.Context, id int) (*wtf.DialMembership, error)
- func (s *DialMembershipService) FindDialMemberships(ctx context.Context, filter wtf.DialMembershipFilter) ([]*wtf.DialMembership, int, error)
- func (s *DialMembershipService) UpdateDialMembership(ctx context.Context, id int, upd wtf.DialMembershipUpdate) (*wtf.DialMembership, error)
- type DialService
- func (s *DialService) AverageDialValueReport(ctx context.Context, start, end time.Time, interval time.Duration) (*wtf.DialValueReport, error)
- func (s *DialService) CreateDial(ctx context.Context, dial *wtf.Dial) error
- func (s *DialService) DeleteDial(ctx context.Context, id int) error
- func (s *DialService) DialValues(ctx context.Context, id int) ([]int, error)
- func (s *DialService) FindDialByID(ctx context.Context, id int) (*wtf.Dial, error)
- func (s *DialService) FindDials(ctx context.Context, filter wtf.DialFilter) ([]*wtf.Dial, int, error)
- func (s *DialService) SetDialMembershipValue(ctx context.Context, dialID, value int) error
- func (s *DialService) UpdateDial(ctx context.Context, id int, upd wtf.DialUpdate) (*wtf.Dial, error)
- type NullTime
- type Tx
- type UserService
- func (s *UserService) CreateUser(ctx context.Context, user *wtf.User) error
- func (s *UserService) DeleteUser(ctx context.Context, id int) error
- func (s *UserService) FindUserByID(ctx context.Context, id int) (*wtf.User, error)
- func (s *UserService) FindUsers(ctx context.Context, filter wtf.UserFilter) ([]*wtf.User, int, error)
- func (s *UserService) UpdateUser(ctx context.Context, id int, upd wtf.UserUpdate) (*wtf.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatError ¶
FormatError returns err as a WTF error, if possible. Otherwise returns the original error.
func FormatLimitOffset ¶
FormatLimitOffset returns a SQL string for a given limit & offset. Clauses are only added if limit and/or offset are greater than zero.
Types ¶
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService represents a service for managing OAuth authentication.
func NewAuthService ¶
func NewAuthService(db *DB) *AuthService
NewAuthService returns a new instance of AuthService attached to DB.
func (*AuthService) CreateAuth ¶
CreateAuth Creates a new authentication object If a User is attached to auth, then the auth object is linked to an existing user. Otherwise a new user object is created.
On success, the auth.ID is set to the new authentication ID.
func (*AuthService) DeleteAuth ¶
func (s *AuthService) DeleteAuth(ctx context.Context, id int) error
DeleteAuth permanently deletes an authentication object from the system by ID. The parent user object is not removed.
func (*AuthService) FindAuthByID ¶
FindAuthByID retrieves an authentication object by ID along with the associated user. Returns ENOTFOUND if ID does not exist.
func (*AuthService) FindAuths ¶
func (s *AuthService) FindAuths(ctx context.Context, filter wtf.AuthFilter) ([]*wtf.Auth, int, error)
FindAuths retrieves authentication objects based on a filter.
Also returns the total number of objects that match the filter. This may differ from the returned object count if the Limit field is set.
type DB ¶
type DB struct { // Datasource name. DSN string // Destination for events to be published. EventService wtf.EventService // Returns the current time. Defaults to time.Now(). // Can be mocked for tests. Now func() time.Time // contains filtered or unexported fields }
DB represents the database connection.
type DialMembershipService ¶
type DialMembershipService struct {
// contains filtered or unexported fields
}
DialMembershipService represents a service for managing dial memberships in SQLite.
func NewDialMembershipService ¶
func NewDialMembershipService(db *DB) *DialMembershipService
NewDialMembershipService returns a new instance of DialMembershipService.
func (*DialMembershipService) CreateDialMembership ¶
func (s *DialMembershipService) CreateDialMembership(ctx context.Context, membership *wtf.DialMembership) error
CreateDialMembership creates a new membership on a dial for the current user. Returns EUNAUTHORIZED if there is no current user logged in.
func (*DialMembershipService) DeleteDialMembership ¶
func (s *DialMembershipService) DeleteDialMembership(ctx context.Context, id int) error
DeleteDialMembership permanently deletes a membership by ID. Only the membership owner and the parent dial's owner can delete a membership.
func (*DialMembershipService) FindDialMembershipByID ¶
func (s *DialMembershipService) FindDialMembershipByID(ctx context.Context, id int) (*wtf.DialMembership, error)
FindDialMembershipByID retrieves a membership by ID along with the associated dial & user. Returns ENOTFOUND if membership does exist or user does not have permission to view it.
func (*DialMembershipService) FindDialMemberships ¶
func (s *DialMembershipService) FindDialMemberships(ctx context.Context, filter wtf.DialMembershipFilter) ([]*wtf.DialMembership, int, error)
FindDialMemberships retrieves a list of matching memberships based on filter. Only returns memberships that belong to dials that the current user is a member of.
Also returns a count of total matching memberships which may different if "Limit" is specified on the filter.
func (*DialMembershipService) UpdateDialMembership ¶
func (s *DialMembershipService) UpdateDialMembership(ctx context.Context, id int, upd wtf.DialMembershipUpdate) (*wtf.DialMembership, error)
UpdateDialMembership updates the value of a membership. Only the owner of the membership can update the value. Returns EUNAUTHORIZED if user is not the owner. Returns ENOTFOUND if the membership does not exist.
type DialService ¶
type DialService struct {
// contains filtered or unexported fields
}
DialService represents a service for managing dials.
func NewDialService ¶
func NewDialService(db *DB) *DialService
NewDialService returns a new instance of DialService.
func (*DialService) AverageDialValueReport ¶
func (s *DialService) AverageDialValueReport(ctx context.Context, start, end time.Time, interval time.Duration) (*wtf.DialValueReport, error)
AverageDialValueReport returns a report of the average dial value across all dials that the user is a member of. Average values are computed between start & end time and are slotted into given intervals. The minimum interval size is one minute.
func (*DialService) CreateDial ¶
CreateDial creates a new dial and assigns the current user as the owner. The owner will automatically be added as a member of the new dial.
func (*DialService) DeleteDial ¶
func (s *DialService) DeleteDial(ctx context.Context, id int) error
DeleteDial permanently removes a dial by ID. Only the dial owner may delete a dial. Returns ENOTFOUND if dial does not exist. Returns EUNAUTHORIZED if user is not the dial owner.
func (*DialService) DialValues ¶
DialValues returns a list of all stored historical values for a dial. This is only used for testing.
func (*DialService) FindDialByID ¶
FindDialByID retrieves a single dial by ID along with associated memberships. Only the dial owner & members can see a dial. Returns ENOTFOUND if dial does not exist or user does not have permission to view it.
func (*DialService) FindDials ¶
func (s *DialService) FindDials(ctx context.Context, filter wtf.DialFilter) ([]*wtf.Dial, int, error)
FindDials retrieves a list of dials based on a filter. Only returns dials that the user owns or is a member of.
Also returns a count of total matching dials which may different from the number of returned dials if the "Limit" field is set.
func (*DialService) SetDialMembershipValue ¶ added in v0.1.1
func (s *DialService) SetDialMembershipValue(ctx context.Context, dialID, value int) error
Sets the value of the user's membership in a dial. This works the same as calling UpdateDialMembership() although it doesn't require that the user know their membership ID. Only the dial ID.
Returns ENOTFOUND if the membership does not exist.
func (*DialService) UpdateDial ¶
func (s *DialService) UpdateDial(ctx context.Context, id int, upd wtf.DialUpdate) (*wtf.Dial, error)
UpdateDial updates an existing dial by ID. Only the dial owner can update a dial. Returns the new dial state even if there was an error during update.
Returns ENOTFOUND if dial does not exist. Returns EUNAUTHORIZED if user is not the dial owner.
type NullTime ¶
NullTime represents a helper wrapper for time.Time. It automatically converts time fields to/from RFC 3339 format. Also supports NULL for zero time.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService represents a service for managing users.
func NewUserService ¶
func NewUserService(db *DB) *UserService
NewUserService returns a new instance of UserService.
func (*UserService) CreateUser ¶
CreateUser creates a new user. This is only used for testing since users are typically created during the OAuth creation process in AuthService.CreateAuth().
func (*UserService) DeleteUser ¶
func (s *UserService) DeleteUser(ctx context.Context, id int) error
DeleteUser permanently deletes a user and all owned dials. Returns EUNAUTHORIZED if current user is not the user being deleted. Returns ENOTFOUND if user does not exist.
func (*UserService) FindUserByID ¶
FindUserByID retrieves a user by ID along with their associated auth objects. Returns ENOTFOUND if user does not exist.
func (*UserService) FindUsers ¶
func (s *UserService) FindUsers(ctx context.Context, filter wtf.UserFilter) ([]*wtf.User, int, error)
FindUsers retrieves a list of users by filter. Also returns total count of matching users which may differ from returned results if filter.Limit is specified.
func (*UserService) UpdateUser ¶
func (s *UserService) UpdateUser(ctx context.Context, id int, upd wtf.UserUpdate) (*wtf.User, error)
UpdateUser updates a user object. Returns EUNAUTHORIZED if current user is not the user that is being updated. Returns ENOTFOUND if user does not exist.