made db module
This commit is contained in:
parent
2dd8cc3d2b
commit
3dacf06005
12 changed files with 82 additions and 99 deletions
22
internal/application/application.go
Normal file
22
internal/application/application.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"vegan-barcode/internal/application/utils"
|
||||
"vegan-barcode/internal/database"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
db database.Database
|
||||
log *logrus.Logger
|
||||
}
|
||||
|
||||
func Start() {
|
||||
application := Application{
|
||||
db: database.InitializeDatabase(),
|
||||
log: utils.InitializeLogger(),
|
||||
}
|
||||
|
||||
application.bindRoutes()
|
||||
}
|
11
internal/application/handlers.go
Normal file
11
internal/application/handlers.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package application
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (application *Application) GetClaimsHandler(c *gin.Context) {
|
||||
system := c.DefaultQuery("system", "upc")
|
||||
barcode := c.Query("barcode")
|
||||
|
||||
application.GetClaims(system, barcode)
|
||||
// TODO: 404 when claims are not found
|
||||
}
|
18
internal/application/routes.go
Normal file
18
internal/application/routes.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// TODO: Service should get moved somewhere else. Not sure on naming.
|
||||
func (application *Application) bindRoutes() {
|
||||
|
||||
router := gin.Default()
|
||||
|
||||
router.Group("/claims")
|
||||
{
|
||||
router.GET("/:barcode", application.GetClaimsHandler)
|
||||
}
|
||||
|
||||
router.Run("localhost:8080")
|
||||
}
|
5
internal/application/services.go
Normal file
5
internal/application/services.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package application
|
||||
|
||||
func (application *Application) GetClaims(system string, barcode string) {
|
||||
application.db.FindClaimsByBarcode(system, barcode)
|
||||
}
|
13
internal/application/utils/logger.go
Normal file
13
internal/application/utils/logger.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
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