pkg

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: GPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound               = errors.New("User not found")
	ErrInvalidCredentials         = errors.New("Login or password are wrong")
	ErrBadRequest                 = errors.New("Bad request")
	ErrPermissionDenied           = errors.New("Permission denied")
	ErrActivityIsRunning          = errors.New("A activity is currently running")
	ErrNoActivityIsRunning        = errors.New("No activity is currently running")
	ErrDuplicateValue             = errors.New("Duplicate value")
	ErrEmptyDescriptionNotAllowed = errors.New("empty description is not allowed")
	ErrStartMustBeBeforeEnd       = errors.New("start time must be before end time")
	ErrReadOnlyAccess             = errors.New("Readonly access")
)
View Source
var ErrInvalidType = errors.New("invalid type")

Functions

This section is empty.

Types

type Activity

type Activity struct {
	ID uint `gorm:"primaryKey"`
	InputActivity
	ActualDurationInMinutes   uint
	EventualDurationInMinutes uint
	UserID                    uint

} // @Name Activity

type ActivityService

type ActivityService interface {
	StartActivity(desc string) (*Activity, error)
	AddActivity(activity Activity) (*Activity, error)
	UpdateActivity(activity Activity) (*Activity, error)
	StopRunningActivity() (*Activity, error)
	GetActivity(id uint) (*Activity, error)
	GetActivities(start time.Time, end time.Time) ([]Activity, error)
	DelActivity(id uint) error
}

type HandleActivity

type HandleActivity = func(a *Activity) error

type Holiday

type Holiday struct {
	ID uint `gorm:"primaryKey"`
	InputHoliday
	UserID uint

} // @Name Holiday

type HolidayService

type HolidayService interface {
	AddHoliday(h Holiday) (*Holiday, error)
	UpdateHoliday(h Holiday) (*Holiday, error)
	GetHoliday(id uint) (*Holiday, error)
	GetHolidays(start time.Time, end time.Time) ([]Holiday, error)
	GetHolidaysByType(start time.Time, end time.Time, hType HolidayType) ([]Holiday, error)
	DelHoliday(id uint) error
}

type HolidayType

type HolidayType string
const (
	HolidayTypeFree            HolidayType = "free"
	HolidayTypeSick            HolidayType = "sick"
	HolidayTypeLegalHoliday    HolidayType = "legal_holiday"
	HolidayTypeLegalUnpaidFree HolidayType = "unpaid_free"
)

func StrToHolidayType

func StrToHolidayType(str string) (HolidayType, error)

type InputActivity

type InputActivity struct {
	Start       *time.Time `format:"date-time" extensions:"x-nullable"`
	End         *time.Time `format:"date-time" extensions:"x-nullable"`
	Description string

} // @Name InputActivity

type InputHoliday

type InputHoliday struct {
	Start       time.Time `format:"date-time"`
	End         time.Time `format:"date-time"`
	Description string
	Type        HolidayType

} // @Name InputHoliday

type InputToken

type InputToken struct {
	Name     string
	Readonly bool

} // @Name InputToken

type InputUser

type InputUser struct {
	Name                     string
	Surname                  string
	Login                    string
	Password                 string
	WorkingDays              string
	WeekWorkingTimeInMinutes uint
	NumWorkingDays           uint
	NumHolidays              uint

} // @Name InputUser

func (*InputUser) ToUser

func (u *InputUser) ToUser() User

type InputWorkDay

type InputWorkDay struct {
	Day        time.Time `gorm:"UNIQUE_INDEX:compositeindex;index;not null" format:"date-time"`
	Overtime   int64
	ActiveTime int64
	UserID     uint `gorm:"UNIQUE_INDEX:compositeindex;index;not null"`

} // @Name InputWorkDay

type MainOvertimeService

type MainOvertimeService interface {
	GetOrCreateInstanceForUser(user *User) OvertimeService
	GetOrCreateReadonlyInstanceForUser(user *User) OvertimeService
	FromToken(token string) (*User, error)
	IsReadonlyToken(token string) bool
	Login(login string, password string) (*User, error)
}

type OvertimeService

type OvertimeService interface {
	CalcOverview(day time.Time) (*Overview, error)

	ActivityService
	HolidayService
	WorkDayService
	UserService
	WebhookService
}

func InitOvertimeClient

func InitOvertimeClient(host string, authHeader string) OvertimeService

type Overview

type Overview struct {
	Date                         time.Time `format:"date-time"`
	WeekNumber                   int
	UsedHolidays                 int
	HolidaysStillAvailable       int
	OvertimeThisDayInMinutes     int64
	ActiveTimeThisDayInMinutes   int64
	OvertimeThisWeekInMinutes    int64
	ActiveTimeThisWeekInMinutes  int64
	OvertimeThisMonthInMinutes   int64
	ActiveTimeThisMonthInMinutes int64
	OvertimeThisYearInMinutes    int64
	ActiveTimeThisYearInMinutes  int64
	ActiveActivity               *Activity `extensions:"x-nullable"`

} // @Name Overtime

type Token

type Token struct {
	ID uint `gorm:"primaryKey"`
	InputToken
	UserID uint
	Token  string

} // @Name Token

type User

type User struct {
	ID                       uint `gorm:"primaryKey"`
	Tokens                   []Token
	Password                 string `json:"-"`
	Name                     string
	Surname                  string
	Login                    string `gorm:"unique"`
	WorkingDays              string
	WeekWorkingTimeInMinutes uint
	NumWorkingDays           uint
	NumHolidays              uint

} // @Name User

func (*User) WorkingDaysAsArray

func (e *User) WorkingDaysAsArray() []string

type UserService

type UserService interface {
	SaveUser(user User, adminToken string) (*User, error)
	DeleteUser(login string, adminToken string) error

	UpdateAccount(fields map[string]interface{}, user User) (*User, error)
	GetAccount() (*User, error)

	CreateToken(token InputToken) (*Token, error)
	DeleteToken(tokenID uint) error
	GetTokens() ([]Token, error)
}

type Webhook

type Webhook struct {
	ID uint `gorm:"primaryKey"`
	WebhookInput
	UserID uint

} // @Name Webhook

type WebhookBody

type WebhookBody struct {
	Event   WebhookEvent
	Payload interface{}
}

type WebhookEvent

type WebhookEvent string
const (
	StartActivityEvent WebhookEvent = "start_activity"
	EndActivityEvent   WebhookEvent = "end_activity"
)

type WebhookHandler

type WebhookHandler interface {

	// HandleStartActivity will be called on start events
	HandleStartActivity(handler HandleActivity)

	// HandleEndActivity will be called on end events
	HandleEndActivity(Handler HandleActivity)

	// ListenAndServe listens on the TCP network address addr and then calls Serve with handler
	// to handle requests on incoming connections.
	ListenAndServe(host string) error
}

func NewWebhookHanlder

func NewWebhookHanlder() WebhookHandler

NewWebhookHandler returns simple http server, on which callbacks for events can be registered and they be automaticly called on their event type.

type WebhookInput

type WebhookInput struct {
	HeaderKey   string
	HeaderValue string
	TargetURL   string
	ReadOnly    bool

} // @Name WebhookInput

type WebhookService

type WebhookService interface {
	CreateWebhook(webhook WebhookInput) (*Webhook, error)
	GetWebhooks() ([]Webhook, error)
}

type WorkDay

type WorkDay struct {
	ID uint `gorm:"primaryKey"`
	InputWorkDay
	IsHoliday bool

} // @Name WorkDay

type WorkDayService

type WorkDayService interface {
	GetWorkDays(start time.Time, end time.Time) ([]WorkDay, error)
	AddWorkDay(w WorkDay) (*WorkDay, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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