1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package controller
- import (
- "Zythum/dao"
- "encoding/json"
- "github.com/gin-gonic/gin"
- "log"
- "net/http"
- "strconv"
- )
- func writeResponse(ctx *gin.Context, data map[string]interface{}) {
- ctx.JSON(http.StatusOK, data)
- }
- func NewTaskHandler(ctx *gin.Context) {
- newTask, err := dao.GetNewTask()
- if err != nil {
- return
- }
- taskJson, err := json.Marshal(newTask)
- ctx.Header("Content-Type", "application/json")
- _, err = ctx.Writer.Write(taskJson)
- if err != nil {
- log.Println("Failed to write response:", err)
- } else {
- //log.Println("Get /GetNewTask")
- }
- }
- func UpdateTaskHandler(ctx *gin.Context) {
- idString := ctx.Query("id")
- statusString := ctx.Query("status")
- data := map[string]interface{}{
- "update_status": 0,
- }
- id, err := strconv.Atoi(idString)
- if err != nil {
- writeResponse(ctx, data)
- return
- }
- status, err1 := strconv.Atoi(statusString)
- if err1 != nil {
- writeResponse(ctx, data)
- return
- }
- updateResult := dao.UpdateTaskStatus(id, status)
- if updateResult != 0 {
- writeResponse(ctx, data)
- return
- }
- data["update_status"] = 1
- writeResponse(ctx, data)
- }
- func GetTaskStatusHandler(ctx *gin.Context) {
- taskStatus := dao.GetTaskStatus()
- taskStatusJson, err := json.Marshal(taskStatus)
- ctx.Header("Content-Type", "application/json")
- _, err = ctx.Writer.Write(taskStatusJson)
- if err != nil {
- log.Println("Failed to write response:", err)
- } else {
- //log.Println("Get /GetTaskStatus")
- }
- }
|