3
0
Files
corteza/system/rest/organisation.go
Tit Petric fdf24b3e2c Refactor for new system service
- upd(all): indent spec.json files on all apps
- upd(auth): rename auth app to cmd
- upd(sam): move orgs, teams to system
- upd(system): extend spec.json for check
- upd(codegen): include system/
- upd(codegen): always generate spec files
- upd(sam): references from auth to system
2018-11-05 12:04:04 +01:00

61 lines
1.5 KiB
Go

package rest
import (
"context"
"github.com/pkg/errors"
"github.com/crusttech/crust/system/rest/request"
"github.com/crusttech/crust/system/service"
"github.com/crusttech/crust/system/types"
)
var _ = errors.Wrap
type (
Organisation struct {
svc struct {
org service.OrganisationService
}
}
)
func (Organisation) New() *Organisation {
ctrl := &Organisation{}
ctrl.svc.org = service.DefaultOrganisation
return ctrl
}
func (ctrl *Organisation) Read(ctx context.Context, r *request.OrganisationRead) (interface{}, error) {
return ctrl.svc.org.With(ctx).FindByID(r.ID)
}
func (ctrl *Organisation) List(ctx context.Context, r *request.OrganisationList) (interface{}, error) {
return ctrl.svc.org.With(ctx).Find(&types.OrganisationFilter{Query: r.Query})
}
func (ctrl *Organisation) Create(ctx context.Context, r *request.OrganisationCreate) (interface{}, error) {
org := &types.Organisation{
Name: r.Name,
}
return ctrl.svc.org.With(ctx).Create(org)
}
func (ctrl *Organisation) Edit(ctx context.Context, r *request.OrganisationEdit) (interface{}, error) {
org := &types.Organisation{
ID: r.ID,
Name: r.Name,
}
return ctrl.svc.org.With(ctx).Update(org)
}
func (ctrl *Organisation) Remove(ctx context.Context, r *request.OrganisationRemove) (interface{}, error) {
return nil, ctrl.svc.org.With(ctx).Delete(r.ID)
}
func (ctrl *Organisation) Archive(ctx context.Context, r *request.OrganisationArchive) (interface{}, error) {
return nil, ctrl.svc.org.With(ctx).Archive(r.ID)
}