storj/satellite/console/projects.go

74 lines
2.6 KiB
Go
Raw Normal View History

2019-01-24 16:26:36 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"context"
"time"
"storj.io/common/uuid"
)
// Projects exposes methods to manage Project table in database.
2019-09-10 14:24:16 +01:00
//
// architecture: Database
type Projects interface {
// GetAll is a method for querying all projects from the database.
GetAll(ctx context.Context) ([]Project, error)
// GetCreatedBefore retrieves all projects created before provided date.
GetCreatedBefore(ctx context.Context, before time.Time) ([]Project, error)
// GetByUserID returns a list of projects where user is a project member.
GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
// GetOwn returns a list of projects where user is an owner.
GetOwn(ctx context.Context, userID uuid.UUID) ([]Project, error)
// Get is a method for querying project from the database by id.
Get(ctx context.Context, id uuid.UUID) (*Project, error)
// Insert is a method for inserting project into the database.
2018-11-14 12:45:49 +00:00
Insert(ctx context.Context, project *Project) (*Project, error)
// Delete is a method for deleting project by Id from the database.
Delete(ctx context.Context, id uuid.UUID) error
// Update is a method for updating project entity.
2018-11-14 12:45:49 +00:00
Update(ctx context.Context, project *Project) error
// List returns paginated projects, created before provided timestamp.
List(ctx context.Context, offset int64, limit int, before time.Time) (ProjectsPage, error)
// UpdateRateLimit is a method for updating projects rate limit.
UpdateRateLimit(ctx context.Context, id uuid.UUID, newLimit int) error
// GetMaxBuckets is a method to get the maximum number of buckets allowed for the project
GetMaxBuckets(ctx context.Context, id uuid.UUID) (int, error)
// UpdateBucketLimit is a method for updating projects bucket limit.
UpdateBucketLimit(ctx context.Context, id uuid.UUID, newLimit int) error
}
// Project is a database object that describes Project entity.
type Project struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
PartnerID uuid.UUID `json:"partnerId"`
OwnerID uuid.UUID `json:"ownerId"`
RateLimit *int `json:"rateLimit"`
MaxBuckets int `json:"maxBuckets"`
CreatedAt time.Time `json:"createdAt"`
}
// ProjectInfo holds data needed to create/update Project.
type ProjectInfo struct {
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
}
// ProjectsPage returns paginated projects,
// providing next offset if there are more projects
// to retrieve.
type ProjectsPage struct {
Projects []Project
Next bool
NextOffset int64
}