Documentation ¶
Index ¶
- type MemoryDatabase
- func (m *MemoryDatabase) DeleteOldTrainAlarms(ctx context.Context, threshold time.Time) error
- func (m *MemoryDatabase) DeleteTrainAlarm(ctx context.Context, id string) error
- func (m *MemoryDatabase) GetOrCreateTrainAlarm(ctx context.Context, alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)
- func (m *MemoryDatabase) GetState(ctx context.Context, identifyer string, plattform string) (string, string, error)
- func (m *MemoryDatabase) GetTrainAlarm(ctx context.Context, alarmID string) (*trainalarm.TrainAlarm, error)
- func (m *MemoryDatabase) GetTrainAlarms(ctx context.Context, identifyer string, plattform string) ([]*trainalarm.TrainAlarm, error)
- func (m *MemoryDatabase) GetTrainAlarmsSortByLastNotificationAt(ctx context.Context, limit int) ([]*trainalarm.TrainAlarm, error)
- func (m *MemoryDatabase) UpdateState(ctx context.Context, identifyer string, plattform string, ...) error
- func (m *MemoryDatabase) UpdateTrainAlarm(ctx context.Context, alarmID string, ...) error
- type MemoryStateModel
- type SQLDatabase
- func (s *SQLDatabase) Close()
- func (s *SQLDatabase) DeleteOldTrainAlarms(ctx context.Context, threshold time.Time) error
- func (s *SQLDatabase) DeleteTrainAlarm(ctx context.Context, id string) error
- func (s *SQLDatabase) GetOrCreateTrainAlarm(ctx context.Context, alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)
- func (s *SQLDatabase) GetState(ctx context.Context, identifyer string, plattform string) (string, string, error)
- func (s *SQLDatabase) GetTrainAlarm(ctx context.Context, alarmID string) (*trainalarm.TrainAlarm, error)
- func (s *SQLDatabase) GetTrainAlarms(ctx context.Context, identifyer string, plattform string) ([]*trainalarm.TrainAlarm, error)
- func (s *SQLDatabase) GetTrainAlarmsSortByLastNotificationAt(ctx context.Context, limit int) ([]*trainalarm.TrainAlarm, error)
- func (s *SQLDatabase) UpdateState(ctx context.Context, identifyer string, plattform string, ...) error
- func (s *SQLDatabase) UpdateTrainAlarm(ctx context.Context, alarmID string, ...) error
- type SQLStateModel
- type SQLTrainAlarmModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryDatabase ¶
type MemoryDatabase struct { TrainAlarms map[string]*trainalarm.TrainAlarm CurrentState []*MemoryStateModel Mutex *sync.Mutex }
MemoryDatabase to test without persistence
func (*MemoryDatabase) DeleteOldTrainAlarms ¶
DeleteOldTrainAlarms returns NO error if nothing to do
func (*MemoryDatabase) DeleteTrainAlarm ¶
func (m *MemoryDatabase) DeleteTrainAlarm(ctx context.Context, id string) error
DeleteTrainAlarm returns an error if alarm not found
func (*MemoryDatabase) GetOrCreateTrainAlarm ¶
func (m *MemoryDatabase) GetOrCreateTrainAlarm(ctx context.Context, alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)
GetOrCreateTrainAlarm creates a new alarm if none exists yet
func (*MemoryDatabase) GetState ¶
func (m *MemoryDatabase) GetState(ctx context.Context, identifyer string, plattform string) (string, string, error)
GetState returns an error if no state exists
func (*MemoryDatabase) GetTrainAlarm ¶
func (m *MemoryDatabase) GetTrainAlarm(ctx context.Context, alarmID string) (*trainalarm.TrainAlarm, error)
GetTrainAlarm by id. returns NO error if nothing found
func (*MemoryDatabase) GetTrainAlarms ¶
func (m *MemoryDatabase) GetTrainAlarms(ctx context.Context, identifyer string, plattform string) ([]*trainalarm.TrainAlarm, error)
GetTrainAlarms by identifyer and plattform. returns NO error if nothing found
func (*MemoryDatabase) GetTrainAlarmsSortByLastNotificationAt ¶
func (m *MemoryDatabase) GetTrainAlarmsSortByLastNotificationAt(ctx context.Context, limit int) ([]*trainalarm.TrainAlarm, error)
GetTrainAlarmsSortByLastNotificationAt with a limit. returns NO error if nothing found
func (*MemoryDatabase) UpdateState ¶
func (m *MemoryDatabase) UpdateState(ctx context.Context, identifyer string, plattform string, updateFn func(state string, payload string) (string, string, error)) error
UpdateState create a new if no exists
func (*MemoryDatabase) UpdateTrainAlarm ¶
func (m *MemoryDatabase) UpdateTrainAlarm(ctx context.Context, alarmID string, updateFn func(alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)) error
UpdateTrainAlarm create a transaction, find the model and save it after updateFn. returns a error if model not found or pipe the error from updateFn
type MemoryStateModel ¶
type MemoryStateModel struct { Identifyer string Plattform string State string StatePlayload string }
MemoryStateModel save the current state
type SQLDatabase ¶
type SQLDatabase struct {
// contains filtered or unexported fields
}
SQLDatabase to persistence
func NewSQLDatabase ¶
func NewSQLDatabase(dialect string, path string) *SQLDatabase
NewSQLDatabase by gorm
func (*SQLDatabase) DeleteOldTrainAlarms ¶
DeleteOldTrainAlarms returns NO error if nothing to do
func (*SQLDatabase) DeleteTrainAlarm ¶
func (s *SQLDatabase) DeleteTrainAlarm(ctx context.Context, id string) error
DeleteTrainAlarm returns an error if alarm not found
func (*SQLDatabase) GetOrCreateTrainAlarm ¶
func (s *SQLDatabase) GetOrCreateTrainAlarm(ctx context.Context, alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)
GetOrCreateTrainAlarm creates a new alarm if none exists yet
func (*SQLDatabase) GetState ¶
func (s *SQLDatabase) GetState(ctx context.Context, identifyer string, plattform string) (string, string, error)
GetState returns an error if no state exists
func (*SQLDatabase) GetTrainAlarm ¶
func (s *SQLDatabase) GetTrainAlarm(ctx context.Context, alarmID string) (*trainalarm.TrainAlarm, error)
GetTrainAlarm by id. returns NO error if nothing found
func (*SQLDatabase) GetTrainAlarms ¶
func (s *SQLDatabase) GetTrainAlarms(ctx context.Context, identifyer string, plattform string) ([]*trainalarm.TrainAlarm, error)
GetTrainAlarms by identifyer and plattform. returns NO error if nothing found
func (*SQLDatabase) GetTrainAlarmsSortByLastNotificationAt ¶
func (s *SQLDatabase) GetTrainAlarmsSortByLastNotificationAt(ctx context.Context, limit int) ([]*trainalarm.TrainAlarm, error)
GetTrainAlarmsSortByLastNotificationAt with a limit. returns NO error if nothing found
func (*SQLDatabase) UpdateState ¶
func (s *SQLDatabase) UpdateState(ctx context.Context, identifyer string, plattform string, updateFn func(state string, payload string) (string, string, error)) error
UpdateState create a new if no exists
func (*SQLDatabase) UpdateTrainAlarm ¶
func (s *SQLDatabase) UpdateTrainAlarm(ctx context.Context, alarmID string, updateFn func(alarm *trainalarm.TrainAlarm) (*trainalarm.TrainAlarm, error)) error
UpdateTrainAlarm create a transaction, find the model and save it after updateFn. returns a error if model not found or pipe the error from updateFn
type SQLStateModel ¶
type SQLStateModel struct { Identifyer string `gorm:"primary_key"` Plattform string `gorm:"primary_key"` State string StatePayload string CreatedAt time.Time UpdatedAt time.Time }
SQLStateModel to save conversation state
type SQLTrainAlarmModel ¶
type SQLTrainAlarmModel struct { ID string `gorm:"primary_key"` Identifyer string `gorm:"index:identifyer_plattform"` Plattform string `gorm:"index:identifyer_plattform"` TrainName string StationEVA int StationDate int64 FinalArrivalAt time.Time DelayThresholdMinutes int LastNotificationAt *time.Time LastDelayMinutes int CreatedAt time.Time UpdatedAt time.Time }
SQLTrainAlarmModel to save train alarm
func NewSQLTrainAlarmModel ¶
func NewSQLTrainAlarmModel(alarm *trainalarm.TrainAlarm) *SQLTrainAlarmModel
NewSQLTrainAlarmModel convert domain model to repository model
func (*SQLTrainAlarmModel) TrainAlarm ¶
func (s *SQLTrainAlarmModel) TrainAlarm() *trainalarm.TrainAlarm
TrainAlarm convert to TrainAlarm domain model