2022-08-25 19:26:29 -06:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2023-01-10 20:23:47 -07:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg"
|
2022-08-25 19:26:29 -06:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config"
|
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RepositoryMiddleware(appConfig config.Interface, globalLogger logrus.FieldLogger) gin.HandlerFunc {
|
|
|
|
|
|
|
|
deviceRepo, err := database.NewRepository(appConfig, globalLogger)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: determine where we can call defer deviceRepo.Close()
|
|
|
|
return func(c *gin.Context) {
|
2023-01-10 20:23:47 -07:00
|
|
|
c.Set(pkg.ContextKeyTypeDatabase, deviceRepo)
|
2022-08-25 19:26:29 -06:00
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|