naise_pos/api/server.go

31 lines
704 B
Go
Raw Normal View History

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-14 12:04:03 +07:00
router.POST("/user/merchants", server.createUserMerchant)
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)
}