services

package
v0.0.0-...-5905bd6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const OtelName = "github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/services"

Variables

This section is empty.

Functions

func NewMovie

func NewMovie(d db.DBTX, logger *zap.SugaredLogger, moviec tfidf.MovieGenreClient) *movie

NewMovie returns a new movie service. This is a sample service to showcase grpc + opentelemetry.

Types

type Activity

type Activity struct {
	// contains filtered or unexported fields
}

func NewActivity

func NewActivity(logger *zap.SugaredLogger, aRepo repos.Activity) *Activity

NewActivity returns a new Activity service.

func (*Activity) ByID

func (a *Activity) ByID(ctx context.Context, d db.DBTX, id db.ActivityID) (*db.Activity, error)

ByID gets an activity by ID.

func (*Activity) ByName

func (a *Activity) ByName(ctx context.Context, d db.DBTX, name string, projectID db.ProjectID) (*db.Activity, error)

ByName gets an activity by name.

func (*Activity) ByProjectID

func (a *Activity) ByProjectID(ctx context.Context, d db.DBTX, projectID db.ProjectID) ([]db.Activity, error)

ByProjectID gets activities by project ID.

func (*Activity) Create

func (a *Activity) Create(ctx context.Context, d db.DBTX, params *db.ActivityCreateParams) (*db.Activity, error)

Create creates a new activity.

func (*Activity) Delete

func (a *Activity) Delete(ctx context.Context, d db.DBTX, id db.ActivityID) (*db.Activity, error)

Delete deletes an activity by ID.

func (*Activity) Update

func (a *Activity) Update(ctx context.Context, d db.DBTX, id db.ActivityID, params *db.ActivityUpdateParams) (*db.Activity, error)

Update updates an existing activity.

type Admin

type Admin struct{}

func NewAdmin

func NewAdmin() *Admin

NewAdmin returns a new Admin service.

type AppClaims

type AppClaims struct {
	Email    string `json:"email"`
	Username string `json:"username"`
	jwt.RegisteredClaims
}

type Authentication

type Authentication struct {
	// contains filtered or unexported fields
}

func NewAuthentication

func NewAuthentication(logger *zap.SugaredLogger, usvc *User, pool *pgxpool.Pool) *Authentication

NewAuthentication returns a new authentication service. TODO should we use tx instead of providing pool only.

func (*Authentication) CreateAPIKeyForUser

func (a *Authentication) CreateAPIKeyForUser(ctx context.Context, user *db.User) (*db.UserAPIKey, error)

CreateAPIKeyForUser creates a new API key for a user.

func (*Authentication) CreateAccessTokenForUser

func (a *Authentication) CreateAccessTokenForUser(ctx context.Context, user *db.User) (string, error)

CreateAccessTokenForUser creates a new token for a user.

func (*Authentication) GetOrRegisterUserFromUserInfo

func (a *Authentication) GetOrRegisterUserFromUserInfo(ctx context.Context, userinfo oidc.UserInfo) (*db.User, error)

GetOrRegisterUserFromUserInfo returns a user from user info.

func (*Authentication) GetUserFromAPIKey

func (a *Authentication) GetUserFromAPIKey(ctx context.Context, apiKey string) (*db.User, error)

GetUserFromAPIKey returns a user from an api key.

func (*Authentication) GetUserFromAccessToken

func (a *Authentication) GetUserFromAccessToken(ctx context.Context, token string) (*db.User, error)

GetUserFromAccessToken returns a user from a token.

func (*Authentication) ParseToken

func (a *Authentication) ParseToken(ctx context.Context, token string) (*AppClaims, error)

ParseToken returns a token string claims.

type Authorization

type Authorization struct {
	// contains filtered or unexported fields
}

Authorization represents a service for authorization.

func NewAuthorization

func NewAuthorization(logger *zap.SugaredLogger, scopePolicy string, rolePolicy string) (*Authorization, error)

NewAuthorization returns a new Authorization service. Existing roles and scopes will be loaded from the given policy JSON file paths.

func (*Authorization) DefaultScopes

func (a *Authorization) DefaultScopes(role models.Role) models.Scopes

DefaultScopes returns the default scopes for a role. Scopes are assigned/revoked upon role change (reset completely).

func (*Authorization) HasRequiredRole

func (a *Authorization) HasRequiredRole(role Role, requiredRole models.Role) error

func (*Authorization) HasRequiredScopes

func (a *Authorization) HasRequiredScopes(scopes models.Scopes, requiredScopes models.Scopes) error

func (*Authorization) RoleByName

func (a *Authorization) RoleByName(role models.Role) Role

func (*Authorization) RoleByRank

func (a *Authorization) RoleByRank(rank int) (Role, bool)

func (*Authorization) ScopeByName

func (a *Authorization) ScopeByName(scope string) (Scope, error)

type Board

type Board struct {
	// contains filtered or unexported fields
}

func NewBoard

func NewBoard(logger *zap.SugaredLogger, projectRepo repos.Project,
	teamRepo repos.Team,
	workItemTagRepo repos.WorkItemTag,
	workItemTypeRepo repos.WorkItemType,
	authzsvc *Authorization,
) *Board

NewBoard returns a new Board service.

type DemoTwoWorkItem

type DemoTwoWorkItem struct {
	// contains filtered or unexported fields
}

func NewDemoTwoWorkItem

func NewDemoTwoWorkItem(logger *zap.SugaredLogger, demowiRepo repos.DemoTwoWorkItem, wiRepo repos.WorkItem, userRepo repos.User, wiSvc *WorkItem) *DemoTwoWorkItem

NewDemoTwoWorkItem returns a new DemoTwoWorkItem service.

func (*DemoTwoWorkItem) AssignTag

TODO: same as assign/remove members.

func (*DemoTwoWorkItem) ByID

func (w *DemoTwoWorkItem) ByID(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

ByID gets a work item by ID.

func (*DemoTwoWorkItem) Create

Create creates a new work item.

func (*DemoTwoWorkItem) Delete

func (w *DemoTwoWorkItem) Delete(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

Delete deletes a work item by ID.

func (*DemoTwoWorkItem) List

func (w *DemoTwoWorkItem) List(ctx context.Context, d db.DBTX, teamID db.TeamID) ([]db.WorkItem, error)

func (*DemoTwoWorkItem) ListDeleted

func (w *DemoTwoWorkItem) ListDeleted(ctx context.Context, d db.DBTX, teamID db.TeamID) ([]db.WorkItem, error)

func (*DemoTwoWorkItem) RemoveTag

func (w *DemoTwoWorkItem) RemoveTag(ctx context.Context, d db.DBTX, tagID db.WorkItemTagID, workItemID db.WorkItemID) error

TODO: same as assign/remove members.

func (*DemoTwoWorkItem) Restore

func (w *DemoTwoWorkItem) Restore(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

func (*DemoTwoWorkItem) Update

Update updates an existing work item.

type DemoTwoWorkItemCreateParams

type DemoTwoWorkItemCreateParams struct {
	repos.DemoTwoWorkItemCreateParams
	TagIDs  []db.WorkItemTagID `json:"tagIDs"  nullable:"false" required:"true"`
	Members []Member           `json:"members" nullable:"false" required:"true"`
}

type DemoWorkItem

type DemoWorkItem struct {
	// contains filtered or unexported fields
}

func NewDemoWorkItem

func NewDemoWorkItem(logger *zap.SugaredLogger, demowiRepo repos.DemoWorkItem, wiRepo repos.WorkItem, userRepo repos.User, wiSvc *WorkItem) *DemoWorkItem

NewDemoWorkItem returns a new DemoWorkItem service.

func (*DemoWorkItem) AssignTag

TODO: same as assign/remove members.

func (*DemoWorkItem) ByID

func (w *DemoWorkItem) ByID(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

ByID gets a work item by ID.

func (*DemoWorkItem) Create

Create creates a new work item.

func (*DemoWorkItem) Delete

func (w *DemoWorkItem) Delete(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

Delete deletes a work item by ID.

func (*DemoWorkItem) List

func (w *DemoWorkItem) List(ctx context.Context, d db.DBTX, teamID int) ([]db.WorkItem, error)

func (*DemoWorkItem) ListDeleted

func (w *DemoWorkItem) ListDeleted(ctx context.Context, d db.DBTX, teamID db.TeamID) ([]db.WorkItem, error)

func (*DemoWorkItem) RemoveTag

func (w *DemoWorkItem) RemoveTag(ctx context.Context, d db.DBTX, tagID db.WorkItemTagID, workItemID db.WorkItemID) error

TODO: same as assign/remove members.

func (*DemoWorkItem) Restore

func (w *DemoWorkItem) Restore(ctx context.Context, d db.DBTX, id db.WorkItemID) (*db.WorkItem, error)

func (*DemoWorkItem) Update

Update updates an existing work item.

type DemoWorkItemCreateParams

type DemoWorkItemCreateParams struct {
	repos.DemoWorkItemCreateParams
	TagIDs  []db.WorkItemTagID `json:"tagIDs"  nullable:"false" required:"true"`
	Members []Member           `json:"members" nullable:"false" required:"true"`
}

type KanbanStep

type KanbanStep struct {
	// contains filtered or unexported fields
}

func NewKanbanStep

func NewKanbanStep(logger *zap.SugaredLogger, ksrepo repos.KanbanStep) *KanbanStep

NewKanbanStep returns a new KanbanStep service.

func (*KanbanStep) ByID

func (ks *KanbanStep) ByID(ctx context.Context, d db.DBTX, id db.KanbanStepID) (*db.KanbanStep, error)

ByID gets a KanbanStep by ID.

func (*KanbanStep) ByProject

func (ks *KanbanStep) ByProject(ctx context.Context, d db.DBTX, projectID db.ProjectID) ([]db.KanbanStep, error)

ByProject gets all KanbanSteps for a project.

type Member

type Member struct {
	Role   models.WorkItemRole `json:"role"   ref:"#/components/schemas/WorkItemRole" required:"true"`
	UserID db.UserID           `json:"userID" required:"true"`
}

type Notification

type Notification struct {
	// contains filtered or unexported fields
}

func NewNotification

func NewNotification(logger *zap.SugaredLogger, nrepo repos.Notification) *Notification

NewNotification returns a new Notification service.

func (*Notification) Create

Create creates a new notification.

func (*Notification) LatestUserNotifications

func (n *Notification) LatestUserNotifications(ctx context.Context, d db.DBTX, params *db.GetUserNotificationsParams) ([]db.GetUserNotificationsRow, error)

LatestUserNotifications gets user notifications ordered by creation date.

type Project

type Project struct {
	// contains filtered or unexported fields
}

func NewProject

func NewProject(logger *zap.SugaredLogger, projectRepo repos.Project,
	teamRepo repos.Team,
) *Project

NewProject returns a new Project service.

func (*Project) ByID

func (p *Project) ByID(ctx context.Context, d db.DBTX, projectID db.ProjectID) (*db.Project, error)

func (*Project) ByName

func (p *Project) ByName(ctx context.Context, d db.DBTX, name models.Project) (*db.Project, error)

func (*Project) MergeConfigFields

func (p *Project) MergeConfigFields(ctx context.Context, d db.DBTX, projectName models.Project, update map[string]any) (*models.ProjectConfig, error)

obj1 : required existing database config update : config update object (we dont know any of those, just projectID) TODO call this for every project at app startup, therefore config is always up to date in the db. `update` will be empty in this first update. when a user updates the config in UI we use this same function but with empty [] of paths. merging logic is the same for both scenarios. we are not typing the update to save ourselves from manually adding a migration to change projects.board_config when _any_ field changes. we generate a new config the way it must be and merge with whatever was in db's board_config there at app startup. the endpoint to update it will be validated by openapi libs as usual.

type Role

type Role struct {
	Description string      `json:"description"`
	Rank        int         `json:"rank"`
	Name        models.Role `json:"name"`
}

Role represents a predefined role that may be required for specific actions regardless of scopes assigned to a user.

type Scope

type Scope struct {
	Description string `json:"description"`
}

type Team

type Team struct {
	// contains filtered or unexported fields
}

func NewTeam

func NewTeam(logger *zap.SugaredLogger, trepo repos.Team) *Team

NewTeam returns a new Team service.

func (*Team) ByID

func (t *Team) ByID(ctx context.Context, d db.DBTX, id db.TeamID) (*db.Team, error)

ByID gets a team by ID.

func (*Team) ByName

func (t *Team) ByName(ctx context.Context, d db.DBTX, name string, projectID db.ProjectID) (*db.Team, error)

ByName gets a team by name.

func (*Team) Create

func (t *Team) Create(ctx context.Context, d db.DBTX, params *db.TeamCreateParams) (*db.Team, error)

Create creates a new team.

func (*Team) Delete

func (t *Team) Delete(ctx context.Context, d db.DBTX, id db.TeamID) (*db.Team, error)

Delete deletes an existing team.

func (*Team) Update

func (t *Team) Update(ctx context.Context, d db.DBTX, id db.TeamID, params *db.TeamUpdateParams) (*db.Team, error)

Update updates an existing team.

type TimeEntry

type TimeEntry struct {
	// contains filtered or unexported fields
}

func NewTimeEntry

func NewTimeEntry(logger *zap.SugaredLogger, teRepo repos.TimeEntry, wiRepo repos.WorkItem) *TimeEntry

NewTimeEntry returns a new TimeEntry service.

func (*TimeEntry) ByID

func (a *TimeEntry) ByID(ctx context.Context, d db.DBTX, id db.TimeEntryID) (*db.TimeEntry, error)

ByID gets a time entry by ID.

func (*TimeEntry) Create

func (a *TimeEntry) Create(ctx context.Context, d db.DBTX, caller *db.User, params *db.TimeEntryCreateParams) (*db.TimeEntry, error)

Create creates a new time entry.

func (*TimeEntry) Delete

func (a *TimeEntry) Delete(ctx context.Context, d db.DBTX, id db.TimeEntryID) (*db.TimeEntry, error)

Delete deletes a time entry by ID.

func (*TimeEntry) Update

func (a *TimeEntry) Update(ctx context.Context, d db.DBTX, id db.TimeEntryID, params *db.TimeEntryUpdateParams) (*db.TimeEntry, error)

Update updates an existing time entry.

type User

type User struct {
	// contains filtered or unexported fields
}

func NewUser

func NewUser(logger *zap.SugaredLogger, urepo repos.User, notificationrepo repos.Notification, authzsvc *Authorization) *User

NewUser returns a new User service.

func (*User) AssignTeam

func (u *User) AssignTeam(ctx context.Context, d db.DBTX, userID db.UserID, teamID db.TeamID) error

func (*User) ByAPIKey

func (u *User) ByAPIKey(ctx context.Context, d db.DBTX, apiKey string) (*db.User, error)

ByAPIKey gets a user by apiKey.

func (*User) ByEmail

func (u *User) ByEmail(ctx context.Context, d db.DBTX, email string) (*db.User, error)

ByEmail gets a user by email.

func (*User) ByExternalID

func (u *User) ByExternalID(ctx context.Context, d db.DBTX, id string) (*db.User, error)

ByExternalID gets a user by ExternalID.

func (*User) ByUsername

func (u *User) ByUsername(ctx context.Context, d db.DBTX, username string) (*db.User, error)

ByUsername gets a user by username.

func (*User) CreateAPIKey

func (u *User) CreateAPIKey(ctx context.Context, d db.DBTX, user *db.User) (*db.UserAPIKey, error)

func (*User) Delete

func (u *User) Delete(ctx context.Context, d db.DBTX, id db.UserID) (*db.User, error)

Delete marks a user as deleted.

func (*User) LatestGlobalNotifications

func (u *User) LatestGlobalNotifications(ctx context.Context, d db.DBTX, userID db.UserID) ([]db.GetUserNotificationsRow, error)

TODO.

func (*User) LatestPersonalNotifications

func (u *User) LatestPersonalNotifications(ctx context.Context, d db.DBTX, userID db.UserID) ([]db.UserNotification, error)

TODO.

func (*User) Register

func (u *User) Register(ctx context.Context, d db.DBTX, params UserRegisterParams) (*db.User, error)

Register registers a user.

func (*User) Update

func (u *User) Update(ctx context.Context, d db.DBTX, id db.UserID, caller *db.User, params *models.UpdateUserRequest) (*db.User, error)

Update updates a user.

func (*User) UpdateUserAuthorization

func (u *User) UpdateUserAuthorization(ctx context.Context, d db.DBTX, id db.UserID, caller *db.User, params *models.UpdateUserAuthRequest) (*db.User, error)

type UserRegisterParams

type UserRegisterParams struct {
	Username   string
	Email      string
	FirstName  *string
	LastName   *string
	ExternalID string
	Scopes     []models.Scope
	Role       models.Role
}

NOTE: the most important distinction about repositories is that they represent collections of entities. They do not represent database storage or caching or any number of technical concerns. Repositories represent collections. How you hold those collections is simply an implementation detail. Repo should not be aware of models Role and Scope, its conversion or its default values. That's all for upper layers convenience. e.g roles: entity uses rank internally. Repo should not care about mappings to user-friendly names.

type WorkItem

type WorkItem struct {
	// contains filtered or unexported fields
}

func NewWorkItem

func NewWorkItem(logger *zap.SugaredLogger, wiTagRepo repos.WorkItemTag, wiRepo repos.WorkItem, userRepo repos.User, projectRepo repos.Project) *WorkItem

NewWorkItem returns a new WorkItem service with common logic for all project workitems.

func (*WorkItem) AssignTags

func (w *WorkItem) AssignTags(ctx context.Context, d db.DBTX, projectName models.Project, workItem *db.WorkItem, tagIDs []db.WorkItemTagID) error

func (*WorkItem) AssignUsers

func (w *WorkItem) AssignUsers(ctx context.Context, d db.DBTX, workItem *db.WorkItem, members []Member) error

func (*WorkItem) RemoveAssignedUsers

func (w *WorkItem) RemoveAssignedUsers(ctx context.Context, d db.DBTX, workItem *db.WorkItem, members []db.UserID) error

func (*WorkItem) RemoveTags

func (w *WorkItem) RemoveTags(ctx context.Context, d db.DBTX, workItem *db.WorkItem, tagIDs []db.WorkItemTagID) error

type WorkItemTag

type WorkItemTag struct {
	// contains filtered or unexported fields
}

func NewWorkItemTag

func NewWorkItemTag(logger *zap.SugaredLogger, witRepo repos.WorkItemTag) *WorkItemTag

NewWorkItemTag returns a new WorkItemTag service.

func (*WorkItemTag) ByID

func (wit *WorkItemTag) ByID(ctx context.Context, d db.DBTX, id db.WorkItemTagID) (*db.WorkItemTag, error)

ByID gets a work item tag by ID.

func (*WorkItemTag) ByName

func (wit *WorkItemTag) ByName(ctx context.Context, d db.DBTX, name string, projectID db.ProjectID) (*db.WorkItemTag, error)

ByName gets a work item tag by name.

func (*WorkItemTag) Create

func (wit *WorkItemTag) Create(ctx context.Context, d db.DBTX, caller *db.User, params *db.WorkItemTagCreateParams) (*db.WorkItemTag, error)

Create creates a new work item tag.

func (*WorkItemTag) Delete

func (wit *WorkItemTag) Delete(ctx context.Context, d db.DBTX, caller *db.User, id db.WorkItemTagID) (*db.WorkItemTag, error)

Delete deletes a work item tag by ID.

func (*WorkItemTag) Update

func (wit *WorkItemTag) Update(ctx context.Context, d db.DBTX, caller *db.User, id db.WorkItemTagID, params *db.WorkItemTagUpdateParams) (*db.WorkItemTag, error)

Update updates an existing work item tag.

type WorkItemType

type WorkItemType struct {
	// contains filtered or unexported fields
}

func NewWorkItemType

func NewWorkItemType(logger *zap.SugaredLogger, witRepo repos.WorkItemType) *WorkItemType

NewWorkItemType returns a new WorkItemType service.

func (*WorkItemType) ByID

ByID gets a work item type by ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL