2019-01-08 00:37:16 +00:00
|
|
|
package influxdb
|
2018-05-14 16:26:38 +00:00
|
|
|
|
2020-01-13 14:22:52 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-03-30 18:10:02 +00:00
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
2020-01-13 14:22:52 +00:00
|
|
|
)
|
2018-05-14 16:26:38 +00:00
|
|
|
|
2018-07-20 10:24:07 +00:00
|
|
|
// Organization is an organization. 🎉
|
2018-05-14 16:26:38 +00:00
|
|
|
type Organization struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
ID platform.ID `json:"id,omitempty"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
2019-05-17 20:25:19 +00:00
|
|
|
CRUDLog
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 21:02:19 +00:00
|
|
|
// errors of org
|
|
|
|
var (
|
|
|
|
// ErrOrgNameisEmpty is error when org name is empty
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrOrgNameisEmpty = &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2019-04-26 21:02:19 +00:00
|
|
|
Msg: "org name is empty",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-12-05 14:57:26 +00:00
|
|
|
// ops for orgs error and orgs op logs.
|
|
|
|
const (
|
|
|
|
OpFindOrganizationByID = "FindOrganizationByID"
|
|
|
|
OpFindOrganization = "FindOrganization"
|
|
|
|
OpFindOrganizations = "FindOrganizations"
|
|
|
|
OpCreateOrganization = "CreateOrganization"
|
2020-01-13 14:22:52 +00:00
|
|
|
OpPutOrganization = "PutOrganization"
|
2018-12-05 14:57:26 +00:00
|
|
|
OpUpdateOrganization = "UpdateOrganization"
|
|
|
|
OpDeleteOrganization = "DeleteOrganization"
|
|
|
|
)
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// OrganizationService represents a service for managing organization data.
|
|
|
|
type OrganizationService interface {
|
|
|
|
// Returns a single organization by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
FindOrganizationByID(ctx context.Context, id platform.ID) (*Organization, error)
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
// Returns the first organization that matches filter.
|
|
|
|
FindOrganization(ctx context.Context, filter OrganizationFilter) (*Organization, error)
|
|
|
|
|
|
|
|
// Returns a list of organizations that match filter and the total count of matching organizations.
|
|
|
|
// Additional options provide pagination & sorting.
|
|
|
|
FindOrganizations(ctx context.Context, filter OrganizationFilter, opt ...FindOptions) ([]*Organization, int, error)
|
|
|
|
|
|
|
|
// Creates a new organization and sets b.ID with the new identifier.
|
|
|
|
CreateOrganization(ctx context.Context, b *Organization) error
|
|
|
|
|
|
|
|
// Updates a single organization with changeset.
|
|
|
|
// Returns the new organization state after update.
|
2021-03-30 18:10:02 +00:00
|
|
|
UpdateOrganization(ctx context.Context, id platform.ID, upd OrganizationUpdate) (*Organization, error)
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
// Removes a organization by ID.
|
2021-03-30 18:10:02 +00:00
|
|
|
DeleteOrganization(ctx context.Context, id platform.ID) error
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OrganizationUpdate represents updates to a organization.
|
|
|
|
// Only fields which are set are updated.
|
|
|
|
type OrganizationUpdate struct {
|
2019-04-25 07:40:00 +00:00
|
|
|
Name *string
|
|
|
|
Description *string `json:"description,omitempty"`
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:22:42 +00:00
|
|
|
// ErrInvalidOrgFilter is the error indicate org filter is empty
|
2021-03-30 18:10:02 +00:00
|
|
|
var ErrInvalidOrgFilter = &errors.Error{
|
|
|
|
Code: errors.EInvalid,
|
2019-04-26 16:22:42 +00:00
|
|
|
Msg: "Please provide either orgID or org",
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// OrganizationFilter represents a set of filter that restrict the returned results.
|
|
|
|
type OrganizationFilter struct {
|
2020-04-16 18:22:21 +00:00
|
|
|
Name *string
|
2021-03-30 18:10:02 +00:00
|
|
|
ID *platform.ID
|
|
|
|
UserID *platform.ID
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
2020-01-13 14:22:52 +00:00
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func ErrInternalOrgServiceError(op string, err error) *errors.Error {
|
|
|
|
return &errors.Error{
|
|
|
|
Code: errors.EInternal,
|
2020-01-13 14:22:52 +00:00
|
|
|
Msg: fmt.Sprintf("unexpected error in organizations; Err: %v", err),
|
|
|
|
Op: op,
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|