2021-11-19 09:54:02 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/beancount-gs/script"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-22 08:47:49 +00:00
|
|
|
type YearMonth struct {
|
|
|
|
|
Year string `bql:"distinct year(date)" json:"year"`
|
|
|
|
|
Month string `bql:"month(date)" json:"month"`
|
|
|
|
|
}
|
2021-11-19 09:54:02 +00:00
|
|
|
|
2021-11-22 08:47:49 +00:00
|
|
|
func MonthsList(c *gin.Context) {
|
2021-11-21 14:37:13 +00:00
|
|
|
ledgerConfig := script.GetLedgerConfigFromContext(c)
|
2021-11-22 08:47:49 +00:00
|
|
|
yearMonthList := make([]YearMonth, 0)
|
|
|
|
|
err := script.BQLQueryList(ledgerConfig, nil, &yearMonthList)
|
2021-11-19 09:54:02 +00:00
|
|
|
if err != nil {
|
2021-11-22 08:47:49 +00:00
|
|
|
InternalError(c, err.Error())
|
2021-11-19 09:54:02 +00:00
|
|
|
return
|
|
|
|
|
}
|
2021-11-22 08:47:49 +00:00
|
|
|
months := make([]string, 0)
|
|
|
|
|
for _, yearMonth := range yearMonthList {
|
|
|
|
|
months = append(months, yearMonth.Year+"-"+yearMonth.Month)
|
2021-11-21 14:37:13 +00:00
|
|
|
}
|
|
|
|
|
OK(c, months)
|
2021-11-19 09:54:02 +00:00
|
|
|
}
|