server

package
v0.0.0-...-b2f7acf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2021 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const BcryptCost int = 13
View Source
const RoleAdmin int = 99
View Source
const RoleDeptManager int = 30
View Source
const RoleManager int = 50
View Source
const RoleUser int = 10

Variables

This section is empty.

Functions

func AuthorizeAdmin

func AuthorizeAdmin(context *HandlerContext) (bool, error)

func AuthorizeDeptManager

func AuthorizeDeptManager(context *HandlerContext) (bool, error)

func AuthorizeManager

func AuthorizeManager(context *HandlerContext) (bool, error)

func AuthorizeUser

func AuthorizeUser(context *HandlerContext) (bool, error)

Types

type Activity

type Activity struct {
	ID             int       `db:"id" json:"id"`
	Day            time.Time `db:"day" json:"day"`
	UserID         int       `db:"user_id" json:"userId"`
	ProjectID      int       `db:"project_id" json:"projectId"`
	ActivityTypeID int       `db:"activity_type_id" json:"activityTypeId"`
	Duration       int       `db:"duration" json:"duration"`
	Description    *string   `db:"description" json:"description"`
	Version        int       `db:"version" json:"version"`
}

type ActivityAPI

type ActivityAPI struct {
	// contains filtered or unexported fields
}

func NewActivityAPI

func NewActivityAPI(db *DB) *ActivityAPI

func (*ActivityAPI) DeleteHandler

func (activityAPI *ActivityAPI) DeleteHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ActivityAPI) GetByDayHandler

func (activityAPI *ActivityAPI) GetByDayHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ActivityAPI) SaveHandler

func (activityAPI *ActivityAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

type ActivityType

type ActivityType struct {
	ID      int    `db:"id" json:"id"`
	Title   string `db:"title" json:"title"`
	Version int    `db:"version" json:"version"`
}

type ActivityTypeAPI

type ActivityTypeAPI struct {
	// contains filtered or unexported fields
}

func NewActivityTypeAPI

func NewActivityTypeAPI(db *DB) *ActivityTypeAPI

func (*ActivityTypeAPI) DeleteHandler

func (activityTypeAPI *ActivityTypeAPI) DeleteHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ActivityTypeAPI) GetHandler

func (activityTypeAPI *ActivityTypeAPI) GetHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ActivityTypeAPI) GetListHandler

func (activityTypeAPI *ActivityTypeAPI) GetListHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ActivityTypeAPI) SaveHandler

func (activityTypeAPI *ActivityTypeAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

type ActivityView

type ActivityView struct {
	ID                int       `db:"id" json:"id"`
	Day               time.Time `db:"day" json:"day"`
	UserID            int       `db:"user_id" json:"userId"`
	ProjectID         int       `db:"project_id" json:"projectId"`
	ActivityTypeID    int       `db:"activity_type_id" json:"activityTypeId"`
	Duration          int       `db:"duration" json:"duration"`
	Description       *string   `db:"description" json:"description"`
	Version           int       `db:"version" json:"version"`
	ProjectTitle      string    `db:"project_title" json:"projectTitle"`
	ActivityTypeTitle string    `db:"activity_type_title" json:"activityTypeTitle"`
}

type AnonHandler

type AnonHandler struct {
	HandlerFunc func(context *HandlerContext) (interface{}, *HandlerError)
}

func NewAnonHandler

func NewAnonHandler(handlerFunc func(context *HandlerContext) (interface{}, *HandlerError)) AnonHandler

func (AnonHandler) ServeHTTP

func (anonHandler AnonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth(privateKey string, publicKey string, tokenExpiry int) *Auth

func (*Auth) Authenticate

func (auth *Auth) Authenticate(user *User, pwd string) (string, error)

func (*Auth) AuthenticateUser

func (auth *Auth) AuthenticateUser(context *HandlerContext) (string, error)

func (*Auth) GeneratePasswordHash

func (auth *Auth) GeneratePasswordHash(pwd string) ([]byte, error)

func (*Auth) ValidateToken

func (auth *Auth) ValidateToken(context *HandlerContext) bool

type AuthHandler

type AuthHandler struct {
	HandlerFunc      func(context *HandlerContext) (interface{}, *HandlerError)
	AuthenticateFunc func(context *HandlerContext) (string, error)
	AuthorizeFunc    func(context *HandlerContext) (bool, error)
}

func NewAuthHandler

func NewAuthHandler(
	handlerFunc func(context *HandlerContext) (interface{}, *HandlerError),
	authenticateFunc func(context *HandlerContext) (string, error),
	authorizeFunc func(context *HandlerContext) (bool, error)) AuthHandler

func (AuthHandler) ServeHTTP

func (authHandler AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Chart

type Chart struct {
	Series []string    `json:"series"`
	Labels []string    `json:"labels"`
	Data   [][]float32 `json:"data"`
}

type Config

type Config struct {
	HttpAddr string

	JwtPrivateKey string
	JwtPublicKey  string
	TokenExpiry   int
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(configPath string) *Config

func (*Config) GetDataSourceName

func (config *Config) GetDataSourceName() string

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(dataSourceName string) *DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) DeleteActivity

func (db *DB) DeleteActivity(activity *Activity) error

func (*DB) DeleteActivityType

func (db *DB) DeleteActivityType(activityType *ActivityType) error

func (*DB) DeleteDepartment

func (db *DB) DeleteDepartment(department *Department) error

func (*DB) DeleteProject

func (db *DB) DeleteProject(project *Project) error

func (*DB) DeleteProjectCategory

func (db *DB) DeleteProjectCategory(projectCategory *ProjectCategory) error

func (*DB) Downgrade

func (db *DB) Downgrade(max int) error

func (*DB) ExecCliActions

func (db *DB) ExecCliActions(dbUp int, dbDown int, dbGenerateData bool) (bool, error)

func (*DB) GenerateTestData

func (db *DB) GenerateTestData() error

func (*DB) GetActivitiesByDay

func (db *DB) GetActivitiesByDay(userID int, day time.Time) ([]ActivityView, error)

func (*DB) GetActivity

func (db *DB) GetActivity(id int) (*Activity, error)

func (*DB) GetActivityType

func (db *DB) GetActivityType(id int) (*ActivityType, error)

func (*DB) GetActivityTypes

func (db *DB) GetActivityTypes() ([]ActivityType, error)

func (*DB) GetDepartment

func (db *DB) GetDepartment(id int) (*Department, error)

func (*DB) GetDepartmentIDsDownward

func (db *DB) GetDepartmentIDsDownward(startDeptID int) ([]int, error)

func (*DB) GetDepartmentIDsUpward

func (db *DB) GetDepartmentIDsUpward(startDeptID int) ([]int, error)

func (*DB) GetDepartments

func (db *DB) GetDepartments(parent *Department) ([]Department, error)

func (*DB) GetNumberOfUsers

func (db *DB) GetNumberOfUsers() (int, error)

func (*DB) GetProject

func (db *DB) GetProject(id int) (*Project, error)

func (*DB) GetProjectActivityTypeIDs

func (db *DB) GetProjectActivityTypeIDs(projectID int) ([]int, error)

func (*DB) GetProjectCategories

func (db *DB) GetProjectCategories(parent *ProjectCategory) ([]ProjectCategory, error)

func (*DB) GetProjectCategory

func (db *DB) GetProjectCategory(id int) (*ProjectCategory, error)

func (*DB) GetProjectDepartmentIDs

func (db *DB) GetProjectDepartmentIDs(projectID int) ([]int, error)

func (*DB) GetProjectUserIDs

func (db *DB) GetProjectUserIDs(projectID int) ([]int, error)

func (*DB) GetProjects

func (db *DB) GetProjects(departmentID *int) ([]Project, error)

func (*DB) GetProjectsForSelection

func (db *DB) GetProjectsForSelection(userID int, departmentID int) ([]Project, error)

func (*DB) GetProjectsOfUser

func (db *DB) GetProjectsOfUser(userID int) ([]Project, error)

func (*DB) GetUser

func (db *DB) GetUser(id int) (*User, error)

func (*DB) GetUserByName

func (db *DB) GetUserByName(username string) *User

func (*DB) GetUsers

func (db *DB) GetUsers(departmentID *int) ([]User, error)

func (*DB) IsActivityTypeReferenced

func (db *DB) IsActivityTypeReferenced(activityTypeID int, projectID *int) (bool, error)

func (*DB) IsDepartmentReferenced

func (db *DB) IsDepartmentReferenced(department *Department) (bool, error)

func (*DB) IsProjectCategoryReferenced

func (db *DB) IsProjectCategoryReferenced(projectCategory *ProjectCategory) (bool, error)

func (*DB) IsProjectReferenced

func (db *DB) IsProjectReferenced(id int) (bool, error)

func (*DB) IsUsernameAvailable

func (db *DB) IsUsernameAvailable(username string) (bool, error)

func (*DB) SaveActivity

func (db *DB) SaveActivity(activity *Activity) error

func (*DB) SaveActivityType

func (db *DB) SaveActivityType(activityType *ActivityType) error

func (*DB) SaveDepartment

func (db *DB) SaveDepartment(department *Department) error

func (*DB) SaveProject

func (db *DB) SaveProject(project *Project,
	addedActivityTypes []ProjectActivityType, removedActivityTypes []ProjectActivityType,
	addedDepartments []ProjectDepartment, removedDepartments []ProjectDepartment,
	addedUsers []ProjectUser, removedUsers []ProjectUser) error

func (*DB) SaveProjectCategory

func (db *DB) SaveProjectCategory(projectCategory *ProjectCategory) error

func (*DB) SaveUser

func (db *DB) SaveUser(user *User) error

func (*DB) Update

func (db *DB) Update(trans *gorp.Transaction, model interface{}) error

func (*DB) Upgrade

func (db *DB) Upgrade(max int) error

type DateValue

type DateValue struct {
	Date  time.Time `db:"date" json:"date"`
	Value float32   `db:"value" json:"value"`
}

type Department

type Department struct {
	ID          int          `db:"id" json:"id"`
	ParentID    *int         `db:"parent_id" json:"parentId"`
	Title       string       `db:"title" json:"title"`
	Version     int          `db:"version" json:"version"`
	Path        string       `db:"-" json:"path"`
	Departments []Department `db:"-" json:"departments"`
}

type DepartmentAPI

type DepartmentAPI struct {
	// contains filtered or unexported fields
}

func NewDepartmentAPI

func NewDepartmentAPI(db *DB) *DepartmentAPI

func (*DepartmentAPI) DeleteHandler

func (departmentAPI *DepartmentAPI) DeleteHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*DepartmentAPI) GetListHandler

func (departmentAPI *DepartmentAPI) GetListHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*DepartmentAPI) GetTreeHandler

func (departmentAPI *DepartmentAPI) GetTreeHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*DepartmentAPI) SaveHandler

func (departmentAPI *DepartmentAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

type HandlerContext

type HandlerContext struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	User           *User
	// contains filtered or unexported fields
}

func NewHandlerContext

func NewHandlerContext(w http.ResponseWriter, r *http.Request) *HandlerContext

func (*HandlerContext) GetReqBodyJSON

func (handlerContext *HandlerContext) GetReqBodyJSON(model interface{}) error

func (*HandlerContext) GetRouteVarInt

func (handlerContext *HandlerContext) GetRouteVarInt(name string) (int, error)

func (*HandlerContext) GetRouteVarString

func (handlerContext *HandlerContext) GetRouteVarString(name string) (string, error)

func (*HandlerContext) GetRouteVarTime

func (handlerContext *HandlerContext) GetRouteVarTime(name string, layout string) (time.Time, error)

type HandlerError

type HandlerError struct {
	Error   error
	Message string
	Code    int
}

type MigrationAPI

type MigrationAPI struct {
	// contains filtered or unexported fields
}

func NewMigrationAPI

func NewMigrationAPI(db *DB, userAPI *UserAPI) *MigrationAPI

func (*MigrationAPI) UpgradeHandler

func (migrationAPI *MigrationAPI) UpgradeHandler(context *HandlerContext) (interface{}, *HandlerError)

type Project

type Project struct {
	ID                int            `db:"id" json:"id"`
	ProjectCategoryID int            `db:"project_category_id" json:"projectCategoryId"`
	RefID             string         `db:"ref_id" json:"refId"`
	RefIDComplete     string         `db:"ref_id_complete" json:"refIdComplete"`
	ResponsibleUserID *int           `db:"responsible_user_id" json:"responsibleUserId"`
	ManagerUserID     *int           `db:"manager_user_id" json:"managerUserId"`
	Title             string         `db:"title" json:"title"`
	Description       string         `db:"description" json:"description"`
	Version           int            `db:"version" json:"version"`
	ActivityTypes     []ActivityType `db:"-" json:"activityTypes"`
	Departments       []Department   `db:"-" json:"departments"`
	Users             []User         `db:"-" json:"users"`
}

func (*Project) GetDepartmentIDs

func (project *Project) GetDepartmentIDs() []int

func (*Project) GetUserIDs

func (project *Project) GetUserIDs() []int

type ProjectAPI

type ProjectAPI struct {
	// contains filtered or unexported fields
}

func NewProjectAPI

func NewProjectAPI(db *DB) *ProjectAPI

func (*ProjectAPI) AuthorizeDelete

func (projectAPI *ProjectAPI) AuthorizeDelete(context *HandlerContext) (bool, error)

func (*ProjectAPI) AuthorizeGet

func (projectAPI *ProjectAPI) AuthorizeGet(context *HandlerContext) (bool, error)

func (*ProjectAPI) AuthorizeSave

func (projectAPI *ProjectAPI) AuthorizeSave(context *HandlerContext) (bool, error)

func (*ProjectAPI) DeleteHandler

func (projectAPI *ProjectAPI) DeleteHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectAPI) GetHandler

func (projectAPI *ProjectAPI) GetHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectAPI) GetListHandler

func (projectAPI *ProjectAPI) GetListHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectAPI) GetListSelectHandler

func (projectAPI *ProjectAPI) GetListSelectHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectAPI) GetListUserHandler

func (projectAPI *ProjectAPI) GetListUserHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectAPI) SaveHandler

func (projectAPI *ProjectAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

type ProjectActivityType

type ProjectActivityType struct {
	ProjectID      int `db:"project_id"`
	ActivityTypeID int `db:"activity_type_id"`
}

type ProjectCategory

type ProjectCategory struct {
	ID                int               `db:"id" json:"id"`
	ParentID          *int              `db:"parent_id" json:"parentId"`
	RefID             string            `db:"ref_id" json:"refId"`
	RefIDComplete     string            `db:"ref_id_complete" json:"refIdComplete"`
	Title             string            `db:"title" json:"title"`
	Version           int               `db:"version" json:"version"`
	Path              string            `db:"-" json:"path"`
	ProjectCategories []ProjectCategory `db:"-" json:"projectCategories"`
}

type ProjectCategoryAPI

type ProjectCategoryAPI struct {
	// contains filtered or unexported fields
}

func NewProjectCategoryAPI

func NewProjectCategoryAPI(db *DB) *ProjectCategoryAPI

func (*ProjectCategoryAPI) DeleteHandler

func (projectCategoryAPI *ProjectCategoryAPI) DeleteHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectCategoryAPI) GetListHandler

func (projectCategoryAPI *ProjectCategoryAPI) GetListHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectCategoryAPI) GetTreeHandler

func (projectCategoryAPI *ProjectCategoryAPI) GetTreeHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*ProjectCategoryAPI) SaveHandler

func (projectCategoryAPI *ProjectCategoryAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

type ProjectDepartment

type ProjectDepartment struct {
	ProjectID    int `db:"project_id"`
	DepartmentID int `db:"department_id"`
}

type ProjectUser

type ProjectUser struct {
	ProjectID int `db:"project_id"`
	UserID    int `db:"user_id"`
}

type ReportCriteria

type ReportCriteria struct {
	StartDate *time.Time `json:"startDate"`
	EndDate   *time.Time `json:"endDate"`
	Projects  []Project  `json:"projects"`
}

type ReportOverview

type ReportOverview struct {
	DurationTotal     int   `db:"duration_total" json:"durationTotal"`
	ProjectCount      int   `db:"project_count" json:"projectCount"`
	ActivityTypeCount int   `db:"activity_type_count" json:"activityTypeCount"`
	UserCount         int   `db:"user_count" json:"userCount"`
	DepartmentCount   int   `db:"department_count" json:"departmentCount"`
	Timeline          Chart `db:"-" json:"timeline"`
}

type ReportProjects

type ReportProjects struct {
	Timeline Chart `db:"-" json:"timeline"`
}

type Reporting

type Reporting struct {
	// contains filtered or unexported fields
}

func NewReporting

func NewReporting(db *DB) *Reporting

func (*Reporting) CreateReportOverview

func (reporting *Reporting) CreateReportOverview(context *HandlerContext) (interface{}, *HandlerError)

func (*Reporting) CreateReportProjects

func (reporting *Reporting) CreateReportProjects(context *HandlerContext) (interface{}, *HandlerError)

type SingleValue

type SingleValue struct {
	Value interface{} `json:"value"`
}

type User

type User struct {
	ID                 int    `db:"id" json:"id"`
	Role               *int   `db:"role" json:"role"`
	DepartmentID       *int   `db:"department_id" json:"departmentId"`
	Username           string `db:"username" json:"username"`
	PasswordHash       []byte `db:"password_hash" json:"-"`
	FirstName          string `db:"first_name" json:"firstName"`
	LastName           string `db:"last_name" json:"lastName"`
	Email              string `db:"email" json:"email"`
	Version            int    `db:"version" json:"version"`
	NewPassword        string `db:"-" json:"newPassword"`
	NewPasswordConfirm string `db:"-" json:"newPasswordConfirm"`
}

type UserAPI

type UserAPI struct {
	// contains filtered or unexported fields
}

func NewUserAPI

func NewUserAPI(db *DB, auth *Auth) *UserAPI

func (*UserAPI) AddUser

func (userAPI *UserAPI) AddUser(username string, role int, departmentId int, pwd string, firstName string, lastName string, email string) (*User, error)

func (*UserAPI) AuthorizeGet

func (userAPI *UserAPI) AuthorizeGet(context *HandlerContext) (bool, error)

func (*UserAPI) AuthorizeSave

func (userAPI *UserAPI) AuthorizeSave(context *HandlerContext) (bool, error)

func (*UserAPI) GetHandler

func (userAPI *UserAPI) GetHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*UserAPI) GetListDeptHandler

func (userAPI *UserAPI) GetListDeptHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*UserAPI) GetListHandler

func (userAPI *UserAPI) GetListHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*UserAPI) IsSignedInHandler

func (userAPI *UserAPI) IsSignedInHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*UserAPI) SaveHandler

func (userAPI *UserAPI) SaveHandler(context *HandlerContext) (interface{}, *HandlerError)

func (*UserAPI) SigninHandler

func (userAPI *UserAPI) SigninHandler(context *HandlerContext) (interface{}, *HandlerError)

type UserCredentials

type UserCredentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL