services

package
v0.0.0-...-77c9f96 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaginationParamsDirectionAsc  = "asc"
	PaginationParamsDirectionDesc = "desc"
)
View Source
const OtelName = "github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/services"

Variables

This section is empty.

Functions

func CreateRepos

func CreateRepos() *repos.Repos

CreateRepos creates repositories for service usage.

func CreateTestRepos

func CreateTestRepos(t *testing.T) *repos.Repos

CreateTestRepos creates repositories with convenient wrappers for testing.

func NewMovie

func NewMovie(d models.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, repos *repos.Repos) *Activity

NewActivity returns a new Activity service.

func (*Activity) ByID

ByID gets an activity by ID.

func (*Activity) ByName

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

ByName gets an activity by name.

func (*Activity) ByProjectID

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

ByProjectID gets activities by project ID.

func (*Activity) Create

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

Create creates a new activity.

func (*Activity) Delete

Delete deletes an activity by ID.

func (*Activity) Restore

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

func (*Activity) Update

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, repos *repos.Repos, 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 *models.User) (*models.UserAPIKey, error)

CreateAPIKeyForUser creates a new API key for a user.

func (*Authentication) CreateAccessTokenForUser

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

CreateAccessTokenForUser creates a new token for a user.

func (*Authentication) GetOrRegisterUserFromUserInfo

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

GetOrRegisterUserFromUserInfo returns a user from user info.

func (*Authentication) GetUserFromAPIKey

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

GetUserFromAPIKey returns a user from an api key.

func (*Authentication) GetUserFromAccessToken

func (a *Authentication) GetUserFromAccessToken(ctx context.Context, token string) (*models.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) *Authorization

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 CtxUser

type CtxUser struct {
	// db user object with no joins
	*models.User
	Role     Role
	Teams    []models.Team
	Projects []models.Project
	APIKey   *models.UserAPIKey
}

func NewCtxUser

func NewCtxUser(user *models.User) *CtxUser

NewCtxUser returns a new CtxUser. Required joins: Teams, Projects.

type DemoTwoWorkItem

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

func NewDemoTwoWorkItem

func NewDemoTwoWorkItem(logger *zap.SugaredLogger, repos *repos.Repos) *DemoTwoWorkItem

NewDemoTwoWorkItem returns a new DemoTwoWorkItem service.

func (*DemoTwoWorkItem) ByID

ByID gets a work item by ID.

func (*DemoTwoWorkItem) Create

Create creates a new work item.

func (*DemoTwoWorkItem) List

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

func (*DemoTwoWorkItem) ListDeleted

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

func (*DemoTwoWorkItem) Update

Update updates an existing work item.

type DemoTwoWorkItemCreateParams

type DemoTwoWorkItemCreateParams struct {
	repos.DemoTwoWorkItemCreateParams
	WorkItemCreateParams
}

type DemoWorkItem

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

func NewDemoWorkItem

func NewDemoWorkItem(logger *zap.SugaredLogger, repos *repos.Repos) *DemoWorkItem

NewDemoWorkItem returns a new DemoWorkItem service.

func (*DemoWorkItem) ByID

ByID gets a work item by ID.

func (*DemoWorkItem) Create

Create creates a new work item.

func (*DemoWorkItem) List

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

func (*DemoWorkItem) ListDeleted

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

func (*DemoWorkItem) Update

Update updates an existing work item.

type DemoWorkItemCreateParams

type DemoWorkItemCreateParams struct {
	repos.DemoWorkItemCreateParams
	WorkItemCreateParams
}

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

ByID gets a KanbanStep by ID.

func (*KanbanStep) ByProject

func (ks *KanbanStep) ByProject(ctx context.Context, d models.DBTX, projectID models.ProjectID) ([]models.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 models.UserID       `json:"userID" required:"true"`
}

type Notification

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

func NewNotification

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

NewNotification returns a new Notification service.

func (*Notification) CreateNotification

func (n *Notification) CreateNotification(ctx context.Context, d models.DBTX, params *NotificationCreateParams) (*models.UserNotification, error)

Create creates a new notification. In case of global notifications returns a single one from the fan out.

func (*Notification) LatestNotifications

LatestNotifications gets user notifications ordered by creation date.

func (*Notification) PaginatedUserNotifications

func (n *Notification) PaginatedUserNotifications(ctx context.Context, d models.DBTX, userID models.UserID, params models.GetPaginatedNotificationsParams) ([]models.UserNotification, error)

PaginatedUserNotifications gets user notifications by cursor.

type NotificationCreateParams

type NotificationCreateParams struct {
	models.NotificationCreateParams
	ReceiverRole *models.Role `json:"receiverRole"`
}

type PaginationParams

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

type PaginationParamsDirection

type PaginationParamsDirection string

type Project

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

func NewProject

func NewProject(logger *zap.SugaredLogger, repos *repos.Repos) *Project

NewProject returns a new Project service.

func (*Project) ByID

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

func (*Project) ByName

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

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 Services

type Services struct {
	Activity        *Activity
	WorkItemComment *WorkItemComment
	User            *User
	Project         *Project
	Team            *Team
	DemoWorkItem    *DemoWorkItem
	DemoTwoWorkItem *DemoTwoWorkItem
	WorkItemTag     *WorkItemTag
	Authorization   *Authorization
	Authentication  *Authentication
	Notification    *Notification
	TimeEntry       *TimeEntry
	WorkItemType    *WorkItemType
	WorkItem        *WorkItem
}

func New

func New(logger *zap.SugaredLogger, repos *repos.Repos, pool *pgxpool.Pool) *Services

type Team

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

func NewTeam

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

NewTeam returns a new Team service.

func (*Team) ByID

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

ByID gets a team by ID.

func (*Team) ByName

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

ByName gets a team by name.

func (*Team) Create

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

Create creates a new team.

func (*Team) Delete

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

Delete deletes an existing team.

func (*Team) Update

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

Update updates an existing team.

type TimeEntry

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

func NewTimeEntry

func NewTimeEntry(logger *zap.SugaredLogger, repos *repos.Repos) *TimeEntry

NewTimeEntry returns a new TimeEntry service.

func (*TimeEntry) ByID

ByID gets a time entry by ID.

func (*TimeEntry) Create

func (te *TimeEntry) Create(ctx context.Context, d models.DBTX, caller CtxUser, params *models.TimeEntryCreateParams) (*models.TimeEntry, error)

Create creates a new time entry.

func (*TimeEntry) Delete

Delete deletes a time entry by ID.

func (*TimeEntry) Update

Update updates an existing time entry.

type TimeEntryUpdateParams

type TimeEntryUpdateParams struct {
	models.TimeEntryUpdateParams
	// no need for getters for new field, validate in dedicated validateUpdateParams only.
	// if it conflicts with base validation, just skip based on validatemode
	NewField string `json:"newField"`
}

*

  • TODO:
  • xo : new property annotations: no-update, no-create, no-update-json, no-create-json to remove json fields or struct fields from either create or update or both,
  • instead of current `private` annotations.

example: extra fields required in services for update (same applies for create)

type User

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

func NewUser

func NewUser(logger *zap.SugaredLogger, repos *repos.Repos) *User

NewUser returns a new User service.

func (*User) AssignTeam

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

func (*User) ByAPIKey

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

ByAPIKey gets a user by apiKey.

func (*User) ByEmail

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

ByEmail gets a user by email.

func (*User) ByExternalID

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

ByExternalID gets a user by ExternalID.

func (*User) ByID

func (*User) ByUsername

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

ByUsername gets a user by username.

func (*User) CreateAPIKey

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

func (*User) Delete

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

Delete marks a user as deleted.

func (*User) LatestGlobalNotifications

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

TODO.

func (*User) LatestPersonalNotifications

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

TODO.

func (*User) Paginated

func (u *User) Paginated(ctx context.Context, d models.DBTX, params models.GetPaginatedUsersParams) ([]models.User, error)

func (*User) Register

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

Register registers a user. IMPORTANT: for internal use only.

func (*User) Update

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

Update updates a user. In this case request params are defined in the spec and converted to db params for demo purposes. The same can be achieved excluding fields from db update params via SQL column comments.

func (*User) UpdateUserAuthorization

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

type UserRegisterParams

type UserRegisterParams struct {
	Username   string         `json:"username"`
	Email      string         `json:"email"`
	FirstName  *string        `json:"firstName"`
	LastName   *string        `json:"lastName"`
	ExternalID string         `json:"externalID"`
	Scopes     []models.Scope `json:"scopes"`
	Role       models.Role    `json:"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, repos *repos.Repos) *WorkItem

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

func (*WorkItem) AssignTags

func (w *WorkItem) AssignTags(ctx context.Context, d models.DBTX, workItemID models.WorkItemID, tagIDs []models.WorkItemTagID) error

func (*WorkItem) AssignUsers

func (w *WorkItem) AssignUsers(ctx context.Context, d models.DBTX, workItemID models.WorkItemID, members []Member) error

func (*WorkItem) Delete

Delete deletes a work item by ID.

func (*WorkItem) RemoveAssignedUsers

func (w *WorkItem) RemoveAssignedUsers(ctx context.Context, d models.DBTX, workItemID models.WorkItemID, members []models.UserID) error

func (*WorkItem) RemoveTags

func (w *WorkItem) RemoveTags(ctx context.Context, d models.DBTX, workItemID models.WorkItemID, tagIDs []models.WorkItemTagID) error

func (*WorkItem) Restore

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

Restore restores a work item marked as deleted by ID.

type WorkItemComment

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

func NewWorkItemComment

func NewWorkItemComment(logger *zap.SugaredLogger, repos *repos.Repos) *WorkItemComment

NewWorkItemComment returns a new work item comment service.

func (*WorkItemComment) ByID

ByID gets a work item comment by ID.

func (*WorkItemComment) Create

Create creates a new work item comment.

func (*WorkItemComment) Delete

Delete deletes an existing work item comment.

func (*WorkItemComment) Update

Update updates an existing work item comment.

type WorkItemCreateParams

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

type WorkItemTag

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

func NewWorkItemTag

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

NewWorkItemTag returns a new WorkItemTag service.

func (*WorkItemTag) ByID

ByID gets a work item tag by ID.

func (*WorkItemTag) ByName

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

ByName gets a work item tag by name.

func (*WorkItemTag) Create

Create creates a new work item tag.

func (*WorkItemTag) Delete

Delete deletes a work item tag by ID.

func (*WorkItemTag) Update

Update updates an existing work item tag.

type WorkItemType

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

func NewWorkItemType

func NewWorkItemType(logger *zap.SugaredLogger, repos *repos.Repos) *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