|
@@ -34,32 +34,29 @@ func Config(c *gin.Context) {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func UpdateUsedDuration(c *gin.Context) {
|
|
|
|
|
|
+func AddUsedDuration(c *gin.Context) {
|
|
deviceId := c.Query("deviceId")
|
|
deviceId := c.Query("deviceId")
|
|
usedDurationStr := c.Query("usedDuration")
|
|
usedDurationStr := c.Query("usedDuration")
|
|
log.Printf("deviceId: %s, usedDuration: %s", deviceId, usedDurationStr)
|
|
log.Printf("deviceId: %s, usedDuration: %s", deviceId, usedDurationStr)
|
|
|
|
+
|
|
usedDuration, err := strconv.ParseUint(usedDurationStr, 10, 64)
|
|
usedDuration, err := strconv.ParseUint(usedDurationStr, 10, 64)
|
|
if err != nil {
|
|
if err != nil {
|
|
dto.Error(c, err)
|
|
dto.Error(c, err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if err := storage.SetUsedDuration(deviceId, usedDuration); err != nil {
|
|
|
|
|
|
+ if existed, err := storage.AddUsedDuration(deviceId, usedDuration); err != nil {
|
|
dto.Error(c, err)
|
|
dto.Error(c, err)
|
|
return
|
|
return
|
|
|
|
+ } else {
|
|
|
|
+ c.JSON(http.StatusOK, dto.ConfigResponse{
|
|
|
|
+ Response: dto.NewOkResponse(),
|
|
|
|
+ Data: dto.ConfigResult{
|
|
|
|
+ FreeTrialDuration: totalFreeDuration - existed,
|
|
|
|
+ Timestamp: time.Now().Unix(),
|
|
|
|
+ Node: convert2DtoNode(healthNodes()[0]),
|
|
|
|
+ },
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- usedDuration, err = storage.GetUsedDuration(deviceId)
|
|
|
|
- if err != nil {
|
|
|
|
- dto.Error(c, err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- c.JSON(http.StatusOK, dto.ConfigResponse{
|
|
|
|
- Response: dto.NewOkResponse(),
|
|
|
|
- Data: dto.ConfigResult{
|
|
|
|
- FreeTrialDuration: totalFreeDuration - usedDuration,
|
|
|
|
- Timestamp: time.Now().Unix(),
|
|
|
|
- Node: convert2DtoNode(healthNodes()[0]),
|
|
|
|
- },
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func Register(c *gin.Context) {
|
|
func Register(c *gin.Context) {
|