mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 15:22:47 +01:00
@@ -2,42 +2,31 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/bus"
|
||||
"github.com/SecurityBrewery/catalyst/database"
|
||||
"github.com/SecurityBrewery/catalyst/database/busdb"
|
||||
"github.com/SecurityBrewery/catalyst/generated/models"
|
||||
"github.com/SecurityBrewery/catalyst/generated/restapi/api"
|
||||
"github.com/SecurityBrewery/catalyst/generated/model"
|
||||
"github.com/SecurityBrewery/catalyst/storage"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
bus *bus.Bus
|
||||
database *database.Database
|
||||
settings *models.Settings
|
||||
settings *model.Settings
|
||||
storage *storage.Storage
|
||||
}
|
||||
|
||||
func New(bus *bus.Bus, database *database.Database, storage *storage.Storage, settings *models.Settings) (*Service, error) {
|
||||
func New(bus *bus.Bus, database *database.Database, storage *storage.Storage, settings *model.Settings) (*Service, error) {
|
||||
return &Service{database: database, bus: bus, settings: settings, storage: storage}, nil
|
||||
}
|
||||
|
||||
func (s *Service) Healthy() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Service) response(ctx context.Context, function string, ids []driver.DocumentID, v interface{}, err error) *api.Response {
|
||||
func (s *Service) publishRequest(ctx context.Context, err error, function string, ids []driver.DocumentID) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &api.Response{Code: httpStatus(err), Body: gin.H{"error": err.Error()}}
|
||||
return
|
||||
}
|
||||
|
||||
if ids != nil {
|
||||
userID := "unknown"
|
||||
user, ok := busdb.UserFromContext(ctx)
|
||||
@@ -47,18 +36,4 @@ func (s *Service) response(ctx context.Context, function string, ids []driver.Do
|
||||
|
||||
go s.bus.PublishRequest(userID, function, ids)
|
||||
}
|
||||
|
||||
if v == nil {
|
||||
return &api.Response{Code: http.StatusNoContent, Body: v}
|
||||
}
|
||||
return &api.Response{Code: http.StatusOK, Body: v}
|
||||
}
|
||||
|
||||
func httpStatus(err error) int {
|
||||
ae := driver.ArangoError{}
|
||||
if errors.As(err, &ae) {
|
||||
return ae.Code
|
||||
}
|
||||
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user