add basic paper model/view/controller
All checks were successful
Go / build (push) Successful in 12m50s
All checks were successful
Go / build (push) Successful in 12m50s
paper weight is missing
This commit is contained in:
@@ -15,6 +15,12 @@ type ConfigController interface {
|
||||
AddConfigHandler(*gin.Context)
|
||||
ConfigHandler(*gin.Context)
|
||||
ConfigView(*gin.Context)
|
||||
|
||||
GetAllPaper(*gin.Context)
|
||||
PaperView(*gin.Context)
|
||||
PaperHandler(*gin.Context)
|
||||
AddPaperHandler(*gin.Context)
|
||||
|
||||
CreateTag(*gin.Context)
|
||||
GetAllTags(*gin.Context)
|
||||
TagView(*gin.Context)
|
||||
@@ -108,6 +114,99 @@ func (rc *configController) ConfigHandler(ctx *gin.Context) {
|
||||
rc.ConfigView(ctx)
|
||||
}
|
||||
|
||||
func (rc *configController) PaperHandler(ctx *gin.Context) {
|
||||
newPaper, err := models.NewPaper(ctx)
|
||||
action := ctx.PostForm("action")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
ctx.HTML(http.StatusBadRequest, "paperview.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
paper, err := repositories.Papers.GetById(ctx.Param("id"))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
ctx.HTML(http.StatusBadRequest, "paperview.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
if action == "update" {
|
||||
paper.Name = newPaper.Name
|
||||
paper.Brand = newPaper.Brand
|
||||
paper.Size = newPaper.Size
|
||||
paper.Price = newPaper.Price
|
||||
paper, err = repositories.Papers.Update(paper)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
ctx.HTML(http.StatusBadRequest, "paperview.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
repositories.Papers.DeleteById(ctx.Param("id"))
|
||||
}
|
||||
|
||||
rc.PaperView(ctx)
|
||||
}
|
||||
|
||||
func (rc *configController) AddPaperHandler(c *gin.Context) {
|
||||
paper, err := models.NewPaper(c)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "paperview.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
_, err = repositories.Papers.Create(paper)
|
||||
if err != nil {
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"error": err,
|
||||
"success": "",
|
||||
})
|
||||
|
||||
c.HTML(http.StatusOK, "paperview.html", data)
|
||||
return
|
||||
}
|
||||
|
||||
rc.PaperView(c)
|
||||
}
|
||||
|
||||
func (rc *configController) PaperView(c *gin.Context) {
|
||||
papers, err := repositories.Papers.GetAll()
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "paperview.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"paper": papers,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "paperview.html", data)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "paperview.html", data)
|
||||
}
|
||||
|
||||
func (rc *configController) GetAllPaper(c *gin.Context) {
|
||||
papers, err := repositories.Papers.GetAll()
|
||||
|
||||
if err != nil {
|
||||
ReplyError(c, fmt.Errorf("Could not query Papers"))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, papers)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
func (rc *configController) TagHandler(ctx *gin.Context) {
|
||||
name := ctx.PostForm("name")
|
||||
color := ctx.PostForm("color")
|
||||
|
||||
Reference in New Issue
Block a user