2022-03-30 12:11:44 -04:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2022-04-19 12:07:18 -04:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/ananthakumaran/paisa/web"
|
2022-03-30 12:11:44 -04:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-04-02 03:31:29 -04:00
|
|
|
"gorm.io/gorm"
|
2022-03-30 12:11:44 -04:00
|
|
|
)
|
|
|
|
|
2022-04-02 03:31:29 -04:00
|
|
|
func Listen(db *gorm.DB) {
|
2022-03-30 12:11:44 -04:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
|
|
|
|
router := gin.Default()
|
|
|
|
router.SetTrustedProxies(nil)
|
2022-04-19 12:07:18 -04:00
|
|
|
router.GET("/static/*filepath", func(c *gin.Context) {
|
|
|
|
c.FileFromFS(c.Request.URL.Path, http.FS(web.Static))
|
|
|
|
})
|
|
|
|
router.GET("/", func(c *gin.Context) {
|
|
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(web.Index))
|
|
|
|
})
|
2022-04-09 03:01:12 -04:00
|
|
|
router.GET("/api/overview", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetOverview(db))
|
|
|
|
})
|
2022-04-02 03:31:29 -04:00
|
|
|
router.GET("/api/investment", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetInvestment(db))
|
|
|
|
})
|
2022-04-23 09:31:28 -04:00
|
|
|
router.GET("/api/gain", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetGain(db))
|
|
|
|
})
|
2022-05-14 10:54:34 -04:00
|
|
|
router.GET("/api/income", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetIncome(db))
|
|
|
|
})
|
2022-04-16 01:08:32 -04:00
|
|
|
router.GET("/api/allocation", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetAllocation(db))
|
|
|
|
})
|
2022-04-09 12:45:05 -04:00
|
|
|
router.GET("/api/ledger", func(c *gin.Context) {
|
|
|
|
c.JSON(200, GetLedger(db))
|
|
|
|
})
|
2022-04-02 03:31:29 -04:00
|
|
|
log.Info("Listening on 7500")
|
2022-04-19 04:02:05 -04:00
|
|
|
err := router.Run(":7500")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2022-03-30 12:11:44 -04:00
|
|
|
}
|