make get and post endpoints work, update enums to be strings, add log file output
This commit is contained in:
parent
79977f1a18
commit
e762fc2abd
12 changed files with 94 additions and 72 deletions
|
@ -3,20 +3,18 @@ package application
|
|||
import (
|
||||
"vegan-barcode/internal/database"
|
||||
"vegan-barcode/internal/utils"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
db database.Database
|
||||
log *logrus.Logger
|
||||
db database.Database
|
||||
// TODO: possibly include logger?
|
||||
}
|
||||
|
||||
func Start() {
|
||||
application := Application{
|
||||
db: database.InitializeDatabase(),
|
||||
log: utils.InitializeLogger(),
|
||||
db: database.InitializeDatabase(),
|
||||
}
|
||||
|
||||
utils.InitializeLogger()
|
||||
application.bindRoutes()
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"vegan-barcode/internal/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (a *Application) TestHandler(c *gin.Context) {
|
||||
|
@ -17,7 +19,7 @@ func (a *Application) GetClaimsHandler(c *gin.Context) {
|
|||
|
||||
productClaims, err := a.GetClaims(system, barcode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, productClaims)
|
||||
|
@ -30,9 +32,10 @@ func (a *Application) PostClaimHandler(c *gin.Context) {
|
|||
var requestBody models.UserClaimForm
|
||||
err := c.BindJSON(&requestBody)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, nil)
|
||||
c.JSON(http.StatusBadRequest, fmt.Errorf("improperly formatted request: %w", err))
|
||||
return
|
||||
}
|
||||
log.Debugf("requestbody: %v", requestBody)
|
||||
|
||||
claim, err := a.CreateClaim(system, barcode, requestBody)
|
||||
if err != nil {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package application
|
|
@ -12,7 +12,7 @@ func (a *Application) GetClaims(system string, barcode string) (*models.ProductC
|
|||
return nil, err
|
||||
}
|
||||
if product == nil {
|
||||
return nil, errors.New("Product not found")
|
||||
return nil, errors.New("product not found")
|
||||
}
|
||||
|
||||
claims, err := a.db.FindClaimsByProductID(product.Id)
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func InitializeLogger() *logrus.Logger {
|
||||
log := logrus.New()
|
||||
log.SetFormatter(&logrus.TextFormatter{
|
||||
FullTimestamp: true, // Include the full timestamp (with date and time)
|
||||
})
|
||||
return log
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue