move api/server to api/edge/bff
This commit is contained in:
22
api/edge/bff/internal/server/recipientimp/notifications.go
Normal file
22
api/edge/bff/internal/server/recipientimp/notifications.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package recipientimp
|
||||
|
||||
import (
|
||||
messaging "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
notifications "github.com/tech/sendico/pkg/messaging/notifications/object"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
nm "github.com/tech/sendico/pkg/model/notification"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func (a *RecipientAPI) notification(
|
||||
recipient *model.Recipient,
|
||||
actorAccountRef bson.ObjectID,
|
||||
t nm.NotificationAction,
|
||||
) messaging.Envelope {
|
||||
objectRef := bson.NilObjectID
|
||||
if recipient != nil {
|
||||
objectRef = recipient.ID
|
||||
}
|
||||
|
||||
return notifications.Object(a.Name(), actorAccountRef, a.Name(), objectRef, t)
|
||||
}
|
||||
50
api/edge/bff/internal/server/recipientimp/service.go
Normal file
50
api/edge/bff/internal/server/recipientimp/service.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package recipientimp
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/recipient"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
eapi "github.com/tech/sendico/server/interface/api"
|
||||
"github.com/tech/sendico/server/internal/server/papitemplate"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type RecipientAPI struct {
|
||||
papitemplate.ProtectedAPI[model.Recipient]
|
||||
db recipient.DB
|
||||
}
|
||||
|
||||
func (a *RecipientAPI) Name() mservice.Type {
|
||||
return mservice.Recipients
|
||||
}
|
||||
|
||||
func (a *RecipientAPI) Finish(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateAPI(a eapi.API) (*RecipientAPI, error) {
|
||||
dbFactory := func() (papitemplate.ProtectedDB[model.Recipient], error) {
|
||||
return a.DBFactory().NewRecipientsDB()
|
||||
}
|
||||
|
||||
res := &RecipientAPI{}
|
||||
|
||||
p, err := papitemplate.CreateAPI(a, dbFactory, mservice.Organizations, mservice.Recipients)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.ProtectedAPI = *p.
|
||||
WithNotifications(res.notification).
|
||||
WithNoCreateNotification().
|
||||
WithNoUpdateNotification().
|
||||
Build()
|
||||
|
||||
if res.db, err = a.DBFactory().NewRecipientsDB(); err != nil {
|
||||
res.Logger.Warn("Failed to create recipients database", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user