124 lines
2.7 KiB
Go
124 lines
2.7 KiB
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"github.com/jinzhu/gorm/dialects/postgres"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
type Project struct {
|
||
|
Base
|
||
|
Title *string `json:"title"`
|
||
|
Tasks []*Task `json:"tasks"`
|
||
|
Params *ProjectParams `gorm:"-" json:"params"`
|
||
|
ParamsJSON postgres.Jsonb `json:"-" gorm:"column:params;"`
|
||
|
TaskCategories []*TaskCategory `json:"taskCategories"`
|
||
|
ACL []*Access `json:"acl"`
|
||
|
}
|
||
|
|
||
|
func (p *Project) BeforeSave() error {
|
||
|
data, err := json.Marshal(p.Params)
|
||
|
if err != nil {
|
||
|
return errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
p.ParamsJSON = postgres.Jsonb{RawMessage: data}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (p *Project) AfterFind() error {
|
||
|
params := &ProjectParams{}
|
||
|
if err := json.Unmarshal(p.ParamsJSON.RawMessage, params); err != nil {
|
||
|
return errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
p.Params = params
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type ProjectParams struct {
|
||
|
TimeUnit *TimeUnit `json:"timeUnit"`
|
||
|
Currency string `json:"currency"`
|
||
|
RoundUpEstimations bool `json:"roundUpEstimations"`
|
||
|
HideFinancialPreviewOnPrint bool `json:"hideFinancialPreviewOnPrint"`
|
||
|
}
|
||
|
|
||
|
func NewDefaultProjectParams() *ProjectParams {
|
||
|
return &ProjectParams{
|
||
|
Currency: "€ H.T.",
|
||
|
TimeUnit: &TimeUnit{
|
||
|
Acronym: "J/H",
|
||
|
Label: "Jour/Homme",
|
||
|
},
|
||
|
RoundUpEstimations: false,
|
||
|
HideFinancialPreviewOnPrint: false,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewDefaultTaskCategories() []*TaskCategory {
|
||
|
return []*TaskCategory{
|
||
|
&TaskCategory{
|
||
|
Label: "Développement",
|
||
|
CostPerTimeUnit: 500,
|
||
|
},
|
||
|
&TaskCategory{
|
||
|
Label: "Conduite de projet",
|
||
|
CostPerTimeUnit: 500,
|
||
|
},
|
||
|
&TaskCategory{
|
||
|
Label: "Recette",
|
||
|
CostPerTimeUnit: 500,
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
LevelOwner = "owner"
|
||
|
LevelReadOnly = "readonly"
|
||
|
LevelContributor = "contributor"
|
||
|
)
|
||
|
|
||
|
type Access struct {
|
||
|
Base
|
||
|
ProjectID int64
|
||
|
Project *Project `json:"-"`
|
||
|
UserID int64
|
||
|
User *User `json:"user"`
|
||
|
Level string `json:"level"`
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
EstimationPessimistic = "pessimistic"
|
||
|
EstimationLikely = "likely"
|
||
|
EstimationOptimistic = "optimistic"
|
||
|
)
|
||
|
|
||
|
type Task struct {
|
||
|
Base
|
||
|
ProjectID int64 `json:"-"`
|
||
|
Project *Project `json:"-"`
|
||
|
Label *string `json:"label"`
|
||
|
CategoryID int64 `json:"-"`
|
||
|
Category *TaskCategory `json:"category"`
|
||
|
Estimations postgres.Hstore `json:"estimations"`
|
||
|
}
|
||
|
|
||
|
type TaskCategory struct {
|
||
|
Base
|
||
|
ProjectID int64 `json:"-"`
|
||
|
Project *Project `json:"-"`
|
||
|
Label string `json:"label"`
|
||
|
CostPerTimeUnit float64 `json:"costPerTimeUnit"`
|
||
|
}
|
||
|
|
||
|
type ProjectsFilter struct {
|
||
|
Ids []*int64 `json:"ids"`
|
||
|
Limit *int `json:"limit"`
|
||
|
Offset *int `json:"offset"`
|
||
|
Search *string `json:"search"`
|
||
|
OwnerIds []int64 `json:"-"`
|
||
|
}
|