Move getDate to util file
This commit is contained in:
parent
fd6b77f154
commit
ecb801b2f2
@ -3,7 +3,6 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||||
@ -41,27 +40,6 @@ func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDate(c *gin.Context) (time.Time, error) {
|
|
||||||
var year, month int
|
|
||||||
yearString := c.Param("year")
|
|
||||||
monthString := c.Param("month")
|
|
||||||
if yearString == "" && monthString == "" {
|
|
||||||
return getFirstOfMonthTime(time.Now()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
year, err := strconv.Atoi(yearString)
|
|
||||||
if err != nil {
|
|
||||||
return time.Time{}, fmt.Errorf("parse year: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
month, err = strconv.Atoi(monthString)
|
|
||||||
if err != nil {
|
|
||||||
return time.Time{}, fmt.Errorf("parse month: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return getFirstOfMonth(year, month, time.Now().Location()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) budgetingForMonth(c *gin.Context) {
|
func (h *Handler) budgetingForMonth(c *gin.Context) {
|
||||||
budgetID := c.Param("budgetid")
|
budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
|
30
server/util.go
Normal file
30
server/util.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getDate(c *gin.Context) (time.Time, error) {
|
||||||
|
var year, month int
|
||||||
|
yearString := c.Param("year")
|
||||||
|
monthString := c.Param("month")
|
||||||
|
if yearString == "" && monthString == "" {
|
||||||
|
return getFirstOfMonthTime(time.Now()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
year, err := strconv.Atoi(yearString)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, fmt.Errorf("parse year: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
month, err = strconv.Atoi(monthString)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, fmt.Errorf("parse month: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFirstOfMonth(year, month, time.Now().Location()), nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user