You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-06-15 00:15:15 +02:00
Completed enough code gen for project ATM
This commit is contained in:
@ -2,45 +2,42 @@ package project
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project represents a workflow.
|
||||
type Project struct {
|
||||
ID string `json:"id" validate:"required,uuid"`
|
||||
AccountID string `json:"account_id" validate:"required,uuid" truss:"api-create"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Status ProjectStatus `json:"status" validate:"omitempty,oneof=active disabled"`
|
||||
CreatedAt time.Time `json:"created_at" truss:"api-read"`
|
||||
UpdatedAt time.Time `json:"updated_at" truss:"api-read"`
|
||||
ArchivedAt pq.NullTime `json:"archived_at" truss:"api-hide"`
|
||||
ID string `json:"id" validate:"required,uuid"`
|
||||
AccountID string `json:"account_id" validate:"required,uuid" truss:"api-create"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Status ProjectStatus `json:"status" validate:"omitempty,oneof=active disabled"`
|
||||
CreatedAt time.Time `json:"created_at" truss:"api-read"`
|
||||
UpdatedAt time.Time `json:"updated_at" truss:"api-read"`
|
||||
ArchivedAt pq.NullTime `json:"archived_at" truss:"api-hide"`
|
||||
}
|
||||
|
||||
// CreateProjectRequest contains information needed to create a new Project.
|
||||
// ProjectCreateRequest contains information needed to create a new Project.
|
||||
type ProjectCreateRequest struct {
|
||||
AccountID string `json:"account_id" validate:"required,uuid"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Status *ProjectStatus `json:"status" validate:"omitempty,oneof=active disabled"`
|
||||
AccountID string `json:"account_id" validate:"required,uuid"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Status *ProjectStatus `json:"status" validate:"omitempty,oneof=active disabled"`
|
||||
}
|
||||
|
||||
// UpdateProjectRequest defines what information may be provided to modify an existing
|
||||
// ProjectUpdateRequest defines what information may be provided to modify an existing
|
||||
// Project. All fields are optional so clients can send just the fields they want
|
||||
// changed. It uses pointer fields so we can differentiate between a field that
|
||||
// was not provided and a field that was provided as explicitly blank. Normally
|
||||
// we do not want to use pointers to basic types but we make exceptions around
|
||||
// marshalling/unmarshalling.
|
||||
// was not provided and a field that was provided as explicitly blank.
|
||||
type ProjectUpdateRequest struct {
|
||||
ID string `validate:"required,uuid"`
|
||||
Name *string `json:"name" validate:"omitempty"`
|
||||
Status *ProjectStatus `json:"status" validate:"omitempty,oneof=active pending disabled"`
|
||||
ID string `json:"id" validate:"required,uuid"`
|
||||
Name *string `json:"name" validate:"omitempty"`
|
||||
Status *ProjectStatus `json:"status" validate:"omitempty,oneof=active disabled"`
|
||||
}
|
||||
|
||||
// ProjectFindRequest defines the possible options to search for projects. By default
|
||||
// archived projects will be excluded from response.
|
||||
// archived project will be excluded from response.
|
||||
type ProjectFindRequest struct {
|
||||
Where *string
|
||||
Args []interface{}
|
||||
@ -50,20 +47,21 @@ type ProjectFindRequest struct {
|
||||
IncludedArchived bool
|
||||
}
|
||||
|
||||
// ProjectStatus represents the status of an project.
|
||||
// ProjectStatus represents the status of project.
|
||||
type ProjectStatus string
|
||||
|
||||
// ProjectStatus values define the status field of a user project.
|
||||
// ProjectStatus values define the status field of project.
|
||||
const (
|
||||
// ProjectStatus_Active defines the state when a user can access an project.
|
||||
|
||||
// ProjectStatus_Active defines the status of active for project.
|
||||
ProjectStatus_Active ProjectStatus = "active"
|
||||
// ProjectStatus_Disabled defines the state when a user has been disabled from
|
||||
// accessing an project.
|
||||
// ProjectStatus_Disabled defines the status of disabled for project.
|
||||
ProjectStatus_Disabled ProjectStatus = "disabled"
|
||||
)
|
||||
|
||||
// ProjectStatus_Values provides list of valid ProjectStatus values.
|
||||
var ProjectStatus_Values = []ProjectStatus{
|
||||
|
||||
ProjectStatus_Active,
|
||||
ProjectStatus_Disabled,
|
||||
}
|
||||
@ -74,6 +72,7 @@ func (s *ProjectStatus) Scan(value interface{}) error {
|
||||
if !ok {
|
||||
return errors.New("Scan source is not []byte")
|
||||
}
|
||||
|
||||
*s = ProjectStatus(string(asBytes))
|
||||
return nil
|
||||
}
|
||||
@ -81,7 +80,6 @@ func (s *ProjectStatus) Scan(value interface{}) error {
|
||||
// Value converts the ProjectStatus value to be stored in the database.
|
||||
func (s ProjectStatus) Value() (driver.Value, error) {
|
||||
v := validator.New()
|
||||
|
||||
errs := v.Var(s, "required,oneof=active disabled")
|
||||
if errs != nil {
|
||||
return nil, errs
|
||||
|
Reference in New Issue
Block a user