Daniel Ponte
dea092d448
Closes #14 Reviewed-on: #102 Co-authored-by: Daniel Ponte <amigan@gmail.com> Co-committed-by: Daniel Ponte <amigan@gmail.com>
34 lines
730 B
Go
34 lines
730 B
Go
package sinks
|
|
|
|
import (
|
|
"context"
|
|
|
|
"dynatron.me/x/stillbox/pkg/calls"
|
|
"dynatron.me/x/stillbox/pkg/calls/callstore"
|
|
"dynatron.me/x/stillbox/pkg/database"
|
|
"dynatron.me/x/stillbox/pkg/talkgroups/tgstore"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type DatabaseSink struct {
|
|
db database.Store
|
|
tgs tgstore.Store
|
|
}
|
|
|
|
func NewDatabaseSink(store database.Store, tgs tgstore.Store) *DatabaseSink {
|
|
return &DatabaseSink{store, tgs}
|
|
}
|
|
|
|
func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error {
|
|
if !call.ShouldStore() {
|
|
log.Debug().Str("call", call.String()).Msg("received dontStore call")
|
|
return nil
|
|
}
|
|
|
|
return callstore.FromCtx(ctx).AddCall(ctx, call)
|
|
}
|
|
|
|
func (s *DatabaseSink) SinkType() string {
|
|
return "database"
|
|
}
|