Dump changes
This commit is contained in:
parent
e12550a643
commit
aac2ea1b74
25 changed files with 129 additions and 76 deletions
|
|
@ -1,9 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer"
|
||||
"brainbuffer/pkg/brainbuffer/database"
|
||||
appserver "brainbuffer/pkg/brainbuffer/server"
|
||||
"brainbuffer/pkg/brainbuffer/infrastructure"
|
||||
database2 "brainbuffer/pkg/brainbuffer/infrastructure/database"
|
||||
appserver "brainbuffer/pkg/brainbuffer/infrastructure/server"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
|
|
@ -12,12 +12,13 @@ import (
|
|||
func main() {
|
||||
configureLogger()
|
||||
|
||||
conf := brainbuffer.NewConfig()
|
||||
conf := infrastructure.NewConfig()
|
||||
|
||||
pool := database.Pool(conf)
|
||||
database.Migrate(pool)
|
||||
pool := database2.NewPool(conf)
|
||||
database2.Migrate(pool)
|
||||
|
||||
server := appserver.New(conf, pool)
|
||||
context := infrastructure.NewContext(pool, conf)
|
||||
server := appserver.New(context)
|
||||
|
||||
server.Logger.Fatal(server.Start(":8080"))
|
||||
}
|
||||
|
|
|
|||
40
go.mod
40
go.mod
|
|
@ -1,28 +1,50 @@
|
|||
module brainbuffer
|
||||
|
||||
go 1.16
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/cornelk/hashmap v1.0.1 // indirect
|
||||
github.com/google/uuid v1.2.0 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
|
||||
github.com/jackc/pgx/v4 v4.10.1
|
||||
github.com/jackc/tern v1.12.4
|
||||
github.com/knadh/koanf v0.15.0
|
||||
github.com/labstack/echo/v4 v4.2.1
|
||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||
github.com/mitchellh/copystructure v1.1.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/rs/zerolog v1.20.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver v1.5.0 // indirect
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
||||
github.com/google/uuid v1.2.0 // indirect
|
||||
github.com/huandu/xstrings v1.3.2 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.8.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||
github.com/jackc/pgtype v1.6.2 // indirect
|
||||
github.com/jackc/puddle v1.1.3 // indirect
|
||||
github.com/labstack/gommon v0.3.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||
github.com/mitchellh/copystructure v1.1.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b // indirect
|
||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 // indirect
|
||||
golang.org/x/sys v0.0.0-20210317091845-390168757d9c // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
|
|
|||
6
go.sum
6
go.sum
|
|
@ -26,15 +26,11 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
|
|||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cornelk/hashmap v1.0.1 h1:RXGcy29hEdLLV8T6aK4s+BAd4tq4+3Hq50N2GoG0uIg=
|
||||
github.com/cornelk/hashmap v1.0.1/go.mod h1:8wbysTUDnwJGrPZ1Iwsou3m+An6sldFrJItjRhfegCw=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dchest/siphash v1.1.0 h1:1Rs9eTUlZLPBEvV+2sTaM8O0NWn0ppbgqS7p11aWawI=
|
||||
github.com/dchest/siphash v1.1.0/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
|
|
@ -98,7 +94,6 @@ github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
|
|||
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
|
||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
|
||||
|
|
@ -119,7 +114,6 @@ github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye47
|
|||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
|
||||
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
|
||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
|
||||
|
|
|
|||
|
|
@ -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