delete quick entry and some stats

This commit is contained in:
Akhil Gupta
2021-08-13 13:04:00 +05:30
parent 4ee44fb1f1
commit 0e7d105e52
16 changed files with 350 additions and 22 deletions

View File

@@ -19,6 +19,8 @@ func RegisterFilesController(router *gin.RouterGroup) {
router.GET("/me/quickEntries", getMyQuickEntries)
router.GET("/quickEntries/:id", getQuickEntryById)
router.POST("/quickEntries/:id/process", setQuickEntryAsProcessed)
router.DELETE("/quickEntries/:id", deleteQuickEntryById)
router.GET("/attachments/:id/file", getAttachmentFile)
}
@@ -76,6 +78,21 @@ func getQuickEntryById(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func deleteQuickEntryById(c *gin.Context) {
var searchByIdQuery models.SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
err := service.DeleteQuickEntryById(searchByIdQuery.Id)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("deleteQuickEntryById", err))
return
}
c.JSON(http.StatusNoContent, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func setQuickEntryAsProcessed(c *gin.Context) {
var searchByIdQuery models.SearchByIdQuery

View File

@@ -0,0 +1,37 @@
package controllers
import (
"net/http"
"github.com/akhilrex/hammond/common"
"github.com/akhilrex/hammond/models"
"github.com/akhilrex/hammond/service"
"github.com/gin-gonic/gin"
)
func RegisterReportsController(router *gin.RouterGroup) {
router.GET("/vehicles/:id/mileage", getMileageForVehicle)
}
func getMileageForVehicle(c *gin.Context) {
var searchByIdQuery models.SearchByIdQuery
if err := c.ShouldBindUri(&searchByIdQuery); err == nil {
var model models.MileageQueryModel
err := c.BindQuery(&model)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
return
}
fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
return
}
c.JSON(http.StatusOK, fillups)
} else {
c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err))
}
}