mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
refactor(v2): init eventstore package (#7806)
* refactor(v2): init database package * refactor(v2): init eventstore package * add mock package * test query constructors * option based push analog to query
This commit is contained in:
36
internal/v2/eventstore/event.go
Normal file
36
internal/v2/eventstore/event.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package eventstore
|
||||
|
||||
import "time"
|
||||
|
||||
type Event[P any] struct {
|
||||
Aggregate Aggregate
|
||||
CreatedAt time.Time
|
||||
Creator string
|
||||
Position GlobalPosition
|
||||
Revision uint16
|
||||
Sequence uint32
|
||||
Type string
|
||||
Payload P
|
||||
}
|
||||
|
||||
type StoragePayload interface {
|
||||
Unmarshal(ptr any) error
|
||||
}
|
||||
|
||||
func EventFromStorage[E Event[P], P any](event *Event[StoragePayload]) (*E, error) {
|
||||
var payload P
|
||||
|
||||
if err := event.Payload.Unmarshal(&payload); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &E{
|
||||
Aggregate: event.Aggregate,
|
||||
CreatedAt: event.CreatedAt,
|
||||
Creator: event.Creator,
|
||||
Position: event.Position,
|
||||
Revision: event.Revision,
|
||||
Sequence: event.Sequence,
|
||||
Type: event.Type,
|
||||
Payload: payload,
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user