Example #1
0
func eventClose(c *gin.Context) {
	user := GetUser(c)
	event_id := c.Param("id")
	var event = types.StrategyEvent{}
	var process Process

	if err := c.BindJSON(&process); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "message": err.Error()})
		return
	}

	if len(event_id) == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "message": "event_id should be applied"})
		return
	}

	if err := mydb.Table("strategy_event").Where("id = ?", event_id).First(&event).Error; err != nil {
		c.JSON(http.StatusNotFound, gin.H{"code": http.StatusNotFound, "message": err.Error()})
		return
	}

	if event.Status == types.EVENT_AWARED {
		event.Status = types.EVENT_CLOSED
		event.ProcessUser = user.Username
		event.ProcessComments = process.ProcessComments
		event.ProcessTime = time.Now()
		mydb.Save(&event)
	}

	c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "status": event.Status})
}
Example #2
0
func eventInform(c *gin.Context) {
	user := GetUser(c)
	event_id := c.Param("id")
	var event = types.StrategyEvent{}
	if len(event_id) == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "message": "event_id should be applied"})
		return
	}

	if err := mydb.Where("id = ?", event_id).First(&event).Error; err != nil {
		c.JSON(http.StatusNotFound, gin.H{"code": http.StatusNotFound, "message": err.Error()})
		return
	}

	if event.Status == types.EVENT_NEW {
		event.Status = types.EVENT_AWARED
		event.ProcessUser = user.Username
		mydb.Save(&event)
	}

	c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "status": event.Status})
}