add basic print controller + view
This commit is contained in:
75
controllers/printController.go
Normal file
75
controllers/printController.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"example.com/gin/test/models"
|
||||
"example.com/gin/test/repositories"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PrintController interface {
|
||||
PrintVariantView(*gin.Context)
|
||||
PrintVariantHandler(*gin.Context)
|
||||
}
|
||||
|
||||
type printController struct{}
|
||||
|
||||
func NewPrintController() PrintController {
|
||||
return &printController{}
|
||||
}
|
||||
|
||||
func (rc *printController) PrintVariantView(c *gin.Context) {
|
||||
variant, err := repositories.ShopItems.GetVariantById(c.Param("id"))
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
shopItem, err := repositories.ShopItems.GetById(fmt.Sprintf("%v", variant.ShopItemID))
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "error.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
type ShopItemVariantPair struct {
|
||||
ShopItem models.ShopItem
|
||||
ItemVariant models.ItemVariant
|
||||
}
|
||||
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"itemVariants": []ShopItemVariantPair{
|
||||
{ShopItem: shopItem, ItemVariant: variant},
|
||||
},
|
||||
})
|
||||
|
||||
fmt.Println(data)
|
||||
|
||||
c.HTML(http.StatusOK, "printvariant.html", data)
|
||||
}
|
||||
|
||||
func (rc *printController) PrintVariantHandler(c *gin.Context) {
|
||||
err := repositories.ShopItems.DeleteById(c.Param("id"))
|
||||
|
||||
if err != nil {
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"error": err,
|
||||
"success": "",
|
||||
})
|
||||
|
||||
c.HTML(http.StatusOK, "deleteitem.html", data)
|
||||
}
|
||||
|
||||
shopItems, _ := repositories.ShopItems.GetAll()
|
||||
fmt.Println(len(shopItems))
|
||||
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"title": "shopItem Page",
|
||||
"shopItems": shopItems,
|
||||
})
|
||||
|
||||
fmt.Println(data)
|
||||
|
||||
c.HTML(http.StatusOK, "index.html", data)
|
||||
}
|
||||
Reference in New Issue
Block a user