2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-13 08:27:42 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package console
|
2018-11-13 08:27:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2018-11-13 08:27:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Projects exposes methods to manage Project table in database.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2018-11-13 08:27:42 +00:00
|
|
|
type Projects interface {
|
|
|
|
// GetAll is a method for querying all projects from the database.
|
|
|
|
GetAll(ctx context.Context) ([]Project, error)
|
2019-11-15 14:27:44 +00:00
|
|
|
// GetCreatedBefore retrieves all projects created before provided date.
|
2019-06-06 17:07:14 +01:00
|
|
|
GetCreatedBefore(ctx context.Context, before time.Time) ([]Project, error)
|
2020-06-03 18:01:54 +01:00
|
|
|
// GetByUserID returns a list of projects where user is a project member.
|
2018-12-06 15:19:47 +00:00
|
|
|
GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
|
2020-06-03 18:01:54 +01:00
|
|
|
// GetOwn returns a list of projects where user is an owner.
|
2020-01-29 00:57:15 +00:00
|
|
|
GetOwn(ctx context.Context, userID uuid.UUID) ([]Project, error)
|
2018-11-13 08:27:42 +00:00
|
|
|
// 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)
|
2018-11-13 08:27:42 +00:00
|
|
|
// 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
|
2019-11-05 13:16:02 +00:00
|
|
|
// List returns paginated projects, created before provided timestamp.
|
|
|
|
List(ctx context.Context, offset int64, limit int, before time.Time) (ProjectsPage, error)
|
2020-02-07 17:24:58 +00:00
|
|
|
|
|
|
|
// UpdateRateLimit is a method for updating projects rate limit.
|
|
|
|
UpdateRateLimit(ctx context.Context, id uuid.UUID, newLimit int) error
|
2020-06-30 22:49:29 +01:00
|
|
|
|
|
|
|
// GetMaxBuckets is a method to get the maximum number of buckets allowed for the project
|
|
|
|
GetMaxBuckets(ctx context.Context, id uuid.UUID) (int, error)
|
2020-07-15 15:14:56 +01:00
|
|
|
// UpdateBucketLimit is a method for updating projects bucket limit.
|
|
|
|
UpdateBucketLimit(ctx context.Context, id uuid.UUID, newLimit int) error
|
2018-11-13 08:27:42 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Project is a database object that describes Project entity.
|
2018-11-13 08:27:42 +00:00
|
|
|
type Project struct {
|
2018-11-26 10:47:23 +00:00
|
|
|
ID uuid.UUID `json:"id"`
|
2018-11-13 08:27:42 +00:00
|
|
|
|
2019-07-12 18:59:19 +01:00
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
PartnerID uuid.UUID `json:"partnerId"`
|
2019-08-07 13:28:13 +01:00
|
|
|
OwnerID uuid.UUID `json:"ownerId"`
|
2020-01-17 15:01:36 +00:00
|
|
|
RateLimit *int `json:"rateLimit"`
|
2020-06-30 22:49:29 +01:00
|
|
|
MaxBuckets int `json:"maxBuckets"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
2018-11-26 10:47:23 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ProjectInfo holds data needed to create/update Project.
|
2018-11-26 10:47:23 +00:00
|
|
|
type ProjectInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
2018-11-28 16:20:23 +00:00
|
|
|
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
2018-11-13 08:27:42 +00:00
|
|
|
}
|
2019-11-05 13:16:02 +00:00
|
|
|
|
|
|
|
// ProjectsPage returns paginated projects,
|
|
|
|
// providing next offset if there are more projects
|
|
|
|
// to retrieve.
|
|
|
|
type ProjectsPage struct {
|
|
|
|
Projects []Project
|
|
|
|
Next bool
|
|
|
|
NextOffset int64
|
|
|
|
}
|