inklabs/rangedb

View on GitHub
examples/chat/user_aggregate_gen.go

Summary

Maintainability
A
30 mins
Test Coverage
// Code generated by go generate; DO NOT EDIT.
// This file was generated at
// 2021-11-19 15:31:41.120391 -0800 PST m=+0.004059159
package chat
 
import (
"github.com/inklabs/rangedb"
"github.com/inklabs/rangedb/pkg/cqrs"
)
 
Similar blocks of code found in 2 locations. Consider refactoring.
func (a *user) Load(recordIterator rangedb.RecordIterator) {
for recordIterator.Next() {
if recordIterator.Err() == nil {
if event, ok := recordIterator.Record().Data.(rangedb.Event); ok {
a.apply(event)
}
}
}
}
 
func (a *user) apply(event rangedb.Event) {
switch e := event.(type) {
 
case UserWasOnBoarded:
a.userWasOnBoarded(e)
 
case *UserWasOnBoarded:
a.userWasOnBoarded(*e)
 
case UserWasWarned:
a.userWasWarned(e)
 
case *UserWasWarned:
a.userWasWarned(*e)
 
}
}
 
func (a *user) Handle(command cqrs.Command) []rangedb.Event {
switch c := command.(type) {
 
case OnBoardUser:
a.onBoardUser(c)
 
case *OnBoardUser:
a.onBoardUser(*c)
 
case WarnUser:
a.warnUser(c)
 
case *WarnUser:
a.warnUser(*c)
 
}
 
defer a.resetPendingEvents()
return a.pendingEvents
}
 
func (a *user) resetPendingEvents() {
a.pendingEvents = nil
}
 
func (a *user) CommandTypes() []string {
return []string{
OnBoardUser{}.CommandType(),
WarnUser{}.CommandType(),
}
}
 
func (a *user) raise(events ...rangedb.Event) {
a.pendingEvents = append(a.pendingEvents, events...)
}