expire rout added
parent
4694b12e1b
commit
5f9a2309c1
|
@ -0,0 +1,65 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"netina/database"
|
||||
license_repository "netina/repositories/license"
|
||||
store_repository "netina/repositories/store"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func ExpireDate(c echo.Context) error {
|
||||
|
||||
db := database.Db()
|
||||
|
||||
storeQuery := store_repository.StoreQueryRepository{DB: &db}
|
||||
licenseQuery := license_repository.LicenseQueryRepository{DB: &db}
|
||||
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid store ID"})
|
||||
}
|
||||
|
||||
store , err := storeQuery.GetStore(uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
license , err := licenseQuery.GetLicense(store.License_id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
|
||||
if time.Now().After(license.ExpireDate) {
|
||||
return c.JSON(http.StatusOK , map[string]string{"error": "license expired"})
|
||||
} else {
|
||||
remainingTime := time.Until(license.ExpireDate)
|
||||
secondsRemaining := remainingTime.Seconds()
|
||||
minutesRemaining := remainingTime.Minutes()
|
||||
hoursRemaining := remainingTime.Hours()
|
||||
daysRemaining := hoursRemaining/24
|
||||
|
||||
secondsRemainingStr := strconv.FormatFloat(secondsRemaining, 'f', -1, 64)
|
||||
minutesRemainingStr := strconv.FormatFloat(minutesRemaining, 'f', -1, 64)
|
||||
hoursRemainingStr := strconv.FormatFloat(hoursRemaining, 'f', -1, 64)
|
||||
daysRemainingStr := strconv.FormatFloat(daysRemaining, 'f', -1, 64)
|
||||
|
||||
timeMap := map[string]string{
|
||||
"secondsRemaining": secondsRemainingStr,
|
||||
"minutesRemaining": minutesRemainingStr,
|
||||
"hoursRemaining": hoursRemainingStr,
|
||||
"daysRemaining": daysRemainingStr,
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK , timeMap )
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue