2023-03-07 18:52:37 +07:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
db "git.nochill.in/nochill/naice_pos/db/sqlc"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
2023-03-12 11:01:43 +07:00
|
|
|
store db.Store
|
2023-03-07 18:52:37 +07:00
|
|
|
router *gin.Engine
|
|
|
|
}
|
|
|
|
|
2023-03-12 11:01:43 +07:00
|
|
|
func NewServer(store db.Store) *Server {
|
2023-03-07 18:52:37 +07:00
|
|
|
server := &Server{store: store}
|
|
|
|
router := gin.Default()
|
|
|
|
|
2023-03-13 09:24:59 +07:00
|
|
|
router.POST("/merchants", server.createUser)
|
2023-03-07 18:52:37 +07:00
|
|
|
router.POST("/products", server.createProduct)
|
2023-03-12 11:01:43 +07:00
|
|
|
router.PATCH("/products", server.updateProduct)
|
|
|
|
router.GET("/product/:id", server.getProduct)
|
2023-03-07 18:52:37 +07:00
|
|
|
router.POST("/suppliers", server.createSupplier)
|
2023-03-08 15:22:57 +07:00
|
|
|
router.POST("/purchase-products", server.createPurchase)
|
2023-03-07 18:52:37 +07:00
|
|
|
|
|
|
|
server.router = router
|
|
|
|
return server
|
|
|
|
}
|
|
|
|
|
|
|
|
func (server *Server) Start(address string) error {
|
|
|
|
return server.router.Run(address)
|
|
|
|
}
|