Added uploading receipt photo to API
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"FamilyHub/src/api/services"
|
||||
"FamilyHub/src/config"
|
||||
"FamilyHub/src/database"
|
||||
"FamilyHub/src/integrations/ocr"
|
||||
"FamilyHub/src/integrations/receiptService"
|
||||
"FamilyHub/src/repositories"
|
||||
"context"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
ocr ocr.OCR
|
||||
}
|
||||
|
||||
func NewServer(cfg config.Config) *Server {
|
||||
@@ -89,9 +91,14 @@ func NewServer(cfg config.Config) *Server {
|
||||
|
||||
transactionRepo := repositories.NewTransactionsSQLRepository(dbConn)
|
||||
|
||||
ocrSvc, err := ocr.NewGoogleOCR(context.Background())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
receiptRepo := repositories.NewReceiptsSQLRepository(dbConn)
|
||||
receiptService_ := receiptService.NewReceiptService(receiptRepo, transactionRepo)
|
||||
receiptRouter := routers.NewReceiptRouter(receiptService_)
|
||||
receiptRouter := routers.NewReceiptRouter(receiptService_, ocrSvc)
|
||||
receiptRouter.RegisterRoutes(apiV1)
|
||||
|
||||
transactionService := services.NewTransactionService(transactionRepo)
|
||||
@@ -118,6 +125,7 @@ func NewServer(cfg config.Config) *Server {
|
||||
Addr: cfg.APIHost + ":" + cfg.APIPort,
|
||||
Handler: router,
|
||||
},
|
||||
ocr: ocrSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,5 +134,8 @@ func (s *Server) Start() error {
|
||||
}
|
||||
|
||||
func (s *Server) Shutdown(ctx context.Context) error {
|
||||
if s.ocr != nil {
|
||||
_ = s.ocr.Close()
|
||||
}
|
||||
return s.httpServer.Shutdown(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user