Dump changes
This commit is contained in:
parent
e12550a643
commit
aac2ea1b74
25 changed files with 129 additions and 76 deletions
|
|
@ -1,27 +0,0 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/scheduling"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
Overdue Status = iota
|
||||
Upcoming
|
||||
Missed
|
||||
Completed
|
||||
)
|
||||
|
||||
type Appointment struct {
|
||||
ID int64
|
||||
TaskID int64
|
||||
Status Status
|
||||
SchedulingPattern scheduling.Pattern
|
||||
Time time.Time
|
||||
DurationOffset time.Duration
|
||||
CreationTime time.Time
|
||||
}
|
||||
|
||||
type Appointments []*Appointment
|
||||
42
pkg/brainbuffer/domain/appointment/entity.go
Normal file
42
pkg/brainbuffer/domain/appointment/entity.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/domain/scheduling"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CompletionStatus int
|
||||
|
||||
const (
|
||||
None CompletionStatus = iota
|
||||
Missed
|
||||
Completed
|
||||
Skipped
|
||||
)
|
||||
|
||||
type TimeStatus int
|
||||
|
||||
const (
|
||||
Overdue TimeStatus = iota
|
||||
Upcoming
|
||||
)
|
||||
|
||||
type Appointment struct {
|
||||
ID int64
|
||||
TaskID int64
|
||||
CompletionStatus CompletionStatus
|
||||
SchedulingPattern scheduling.Pattern
|
||||
PlannedTime time.Time
|
||||
DurationOffset time.Duration
|
||||
CreationTime time.Time
|
||||
}
|
||||
|
||||
func (a *Appointment) TimeStatus() TimeStatus {
|
||||
if a.PlannedTime.Before(time.Now()) {
|
||||
return Overdue
|
||||
} else {
|
||||
return Upcoming
|
||||
}
|
||||
}
|
||||
|
||||
type Appointments []*Appointment
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ func (repo *inMemoryRepository) GetAllByTasksBefore(taskIds []int64, beforeTime
|
|||
taskAppointments := make(Appointments, 0)
|
||||
|
||||
for _, val := range repo.db {
|
||||
if _, found := findInIntSlice(val.TaskID, taskIds); found && val.Time.Before(beforeTime) {
|
||||
if _, found := findInIntSlice(val.TaskID, taskIds); found && val.PlannedTime.Before(beforeTime) {
|
||||
taskAppointments = append(taskAppointments, val)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
apperrors "brainbuffer/pkg/brainbuffer/errors"
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
apperrors "brainbuffer/pkg/brainbuffer/infrastructure/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ func (service *defaultService) Create(appointment *Appointment) error {
|
|||
}
|
||||
|
||||
func (service *defaultService) CreateNextAppointment(appointment *Appointment) error {
|
||||
nextTime, err := appointment.SchedulingPattern.NextTime(appointment.Time)
|
||||
nextTime, err := appointment.SchedulingPattern.NextTime(appointment.PlannedTime)
|
||||
if err != nil {
|
||||
return apperrors.UnknownError{Err: err}
|
||||
}
|
||||
|
|
@ -45,9 +45,9 @@ func (service *defaultService) CreateNextAppointment(appointment *Appointment) e
|
|||
nextAppointment := Appointment{
|
||||
ID: 0,
|
||||
TaskID: appointment.TaskID,
|
||||
Status: Upcoming,
|
||||
CompletionStatus: None,
|
||||
SchedulingPattern: appointment.SchedulingPattern,
|
||||
Time: *nextTime,
|
||||
PlannedTime: *nextTime,
|
||||
DurationOffset: 0,
|
||||
CreationTime: time.Now(),
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package scheduling
|
||||
|
||||
import (
|
||||
apperrors "brainbuffer/pkg/brainbuffer/errors"
|
||||
apperrors "brainbuffer/pkg/brainbuffer/infrastructure/errors"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/robfig/cron/v3"
|
||||
"time"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package summary
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/appointment"
|
||||
"brainbuffer/pkg/brainbuffer/domain/appointment"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/scheduling"
|
||||
"brainbuffer/pkg/brainbuffer/domain/scheduling"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/scheduling"
|
||||
"brainbuffer/pkg/brainbuffer/domain/scheduling"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package task
|
||||
|
||||
import "brainbuffer/pkg/brainbuffer/repository"
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
)
|
||||
|
||||
type inMemoryRepository struct {
|
||||
db map[int64]*Task
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/appointment"
|
||||
apperrors "brainbuffer/pkg/brainbuffer/errors"
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"brainbuffer/pkg/brainbuffer/scheduling"
|
||||
"brainbuffer/pkg/brainbuffer/domain/appointment"
|
||||
"brainbuffer/pkg/brainbuffer/domain/repository"
|
||||
"brainbuffer/pkg/brainbuffer/domain/scheduling"
|
||||
apperrors "brainbuffer/pkg/brainbuffer/infrastructure/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -50,9 +50,9 @@ func (serv *defaultService) Create(task *Task) error {
|
|||
firstAppointment := appointment.Appointment{
|
||||
ID: 0,
|
||||
TaskID: 0,
|
||||
Status: appointment.Upcoming,
|
||||
CompletionStatus: appointment.None,
|
||||
SchedulingPattern: pattern,
|
||||
Time: *nextTime,
|
||||
PlannedTime: *nextTime,
|
||||
DurationOffset: 0,
|
||||
CreationTime: time.Now(),
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package brainbuffer
|
||||
package infrastructure
|
||||
|
||||
import (
|
||||
"github.com/knadh/koanf"
|
||||
18
pkg/brainbuffer/infrastructure/context.go
Normal file
18
pkg/brainbuffer/infrastructure/context.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package infrastructure
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/knadh/koanf"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
Database *pgxpool.Pool
|
||||
Config *koanf.Koanf
|
||||
}
|
||||
|
||||
func NewContext(db *pgxpool.Pool, config *koanf.Koanf) *Context {
|
||||
return &Context{
|
||||
Database: db,
|
||||
Config: config,
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/knadh/koanf"
|
||||
)
|
||||
|
||||
func Pool(config *koanf.Koanf) *pgxpool.Pool {
|
||||
func NewPool(config *koanf.Koanf) *pgxpool.Pool {
|
||||
connStr, err := getConnectionString(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
apperrors "brainbuffer/pkg/brainbuffer/errors"
|
||||
"brainbuffer/pkg/brainbuffer/task"
|
||||
"brainbuffer/pkg/brainbuffer/domain/task"
|
||||
"brainbuffer/pkg/brainbuffer/infrastructure"
|
||||
apperrors "brainbuffer/pkg/brainbuffer/infrastructure/errors"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/knadh/koanf"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
|
@ -11,13 +12,13 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
func New(conf *koanf.Koanf, pool *pgxpool.Pool) *echo.Echo {
|
||||
func New(context *infrastructure.Context) *echo.Echo {
|
||||
server := echo.New()
|
||||
|
||||
server.HTTPErrorHandler = errorHandler(server)
|
||||
|
||||
registerHandlers(server, pool)
|
||||
registerMiddleware(server, conf)
|
||||
registerHandlers(server, context.Database)
|
||||
registerMiddleware(server, context.Config)
|
||||
|
||||
return server
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue