Just a simple site to publish surveys. Nothing fancy, mostly done because I need it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

89 lines
1.7 KiB

package features_survey
import (
"github.com/gofiber/fiber/v2"
// . "MY/webapp/common"
)
type Question struct {
Id int64
Question string
Answer bool
Result int
}
type Survey struct {
Id int64
Title string
Description string
Date string
Respondents int
State string
Questions []Question
}
func QueryData() Survey {
return Survey{
Title: "Sample Survey",
Description: "The description.",
Date: "01/20/26",
Respondents: 200,
State: "Finished",
Questions: []Question{
{
Id: 1,
Question: "Do you like HTML?",
Answer: true,
// TODO: just for prototyping, needs to be a better model
Result: 20,
},
{
Id: 2,
Question: "Do you like CSS?",
Answer: false,
Result: 11,
},
{
Id: 3,
Question: "Do you like JavaScript?",
Answer: true,
Result: 43,
},
{
Id: 4,
Question: "Are you a programmer?",
Answer: true,
Result: 28,
},
},
}
}
func GetPageIndex(c *fiber.Ctx) error {
return c.Render("survey/index", fiber.Map{
"Survey": QueryData(),
})
}
func GetPageSubmit(c *fiber.Ctx) error {
return c.Render("survey/submit", fiber.Map{
"Survey": QueryData(),
})
}
func GetPageFinalize(c *fiber.Ctx) error {
return c.Render("survey/finalize", fiber.Map{})
}
func GetPageResults(c *fiber.Ctx) error {
return c.Render("survey/results", fiber.Map{
"Survey": QueryData(),
})
}
func SetupViews(app *fiber.App) {
app.Get("/survey/", GetPageIndex)
app.Get("/survey/submit", GetPageSubmit)
app.Get("/survey/finalize", GetPageFinalize)
app.Get("/survey/results", GetPageResults)
}