add: query month calendar api
This commit is contained in:
parent
108dba4ea9
commit
8520e7d75f
|
|
@ -65,18 +65,18 @@ func GetQueryParams(c *gin.Context) QueryParams {
|
|||
return queryParams
|
||||
}
|
||||
|
||||
func BQLQueryOne(ledgerConfig *Config, queryParams *QueryParams, queryResultPtr interface{}) error {
|
||||
assertQueryResultIsPointer(queryResultPtr)
|
||||
output, err := bqlRawQuery(ledgerConfig, "", queryParams, queryResultPtr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = parseResult(output, queryResultPtr, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
//func BQLQueryOne(ledgerConfig *Config, queryParams *QueryParams, queryResultPtr interface{}) error {
|
||||
// assertQueryResultIsPointer(queryResultPtr)
|
||||
// output, err := bqlRawQuery(ledgerConfig, "", queryParams, queryResultPtr)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// err = parseResult(output, queryResultPtr, true)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func BQLQueryList(ledgerConfig *Config, queryParams *QueryParams, queryResultPtr interface{}) error {
|
||||
assertQueryResultIsPointer(queryResultPtr)
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ func RegisterRouter(router *gin.Engine) {
|
|||
authorized.GET("/stats/account/trend", service.StatsAccountTrend)
|
||||
authorized.GET("/stats/account/balance", service.StatsAccountBalance)
|
||||
authorized.GET("/stats/month/total", service.StatsMonthTotal)
|
||||
authorized.GET("/stats/month/calendar", service.StatsMonthCalendar)
|
||||
authorized.GET("/stats/commodity/price", service.StatsCommodityPrice)
|
||||
authorized.GET("/transaction", service.QueryTransactions)
|
||||
authorized.POST("/transaction", service.AddTransactions)
|
||||
|
|
|
|||
|
|
@ -331,12 +331,67 @@ func StatsMonthTotal(c *gin.Context) {
|
|||
OK(c, monthTotalResult)
|
||||
}
|
||||
|
||||
type StatsMonthQuery struct {
|
||||
Year int `form:"year"`
|
||||
Month int `form:"month"`
|
||||
}
|
||||
type StatsCalendarQueryResult struct {
|
||||
Date string
|
||||
Account string
|
||||
Position string
|
||||
}
|
||||
type StatsCalendarResult struct {
|
||||
Date string `json:"date"`
|
||||
Account string `json:"account"`
|
||||
Amount json.Number `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
CurrencySymbol string `json:"currencySymbol"`
|
||||
}
|
||||
|
||||
func StatsMonthCalendar(c *gin.Context) {
|
||||
ledgerConfig := script.GetLedgerConfigFromContext(c)
|
||||
var statsMonthQuery StatsMonthQuery
|
||||
if err := c.ShouldBindQuery(&statsMonthQuery); err != nil {
|
||||
BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
queryParams := script.QueryParams{
|
||||
Year: statsMonthQuery.Year,
|
||||
Month: statsMonthQuery.Month,
|
||||
Where: true,
|
||||
}
|
||||
|
||||
bql := fmt.Sprintf("SELECT '\\', date, '\\', root(account, 1), '\\', sum(convert(value(position), '%s')), '\\'", ledgerConfig.OperatingCurrency)
|
||||
statsCalendarQueryResult := make([]StatsCalendarQueryResult, 0)
|
||||
err := script.BQLQueryListByCustomSelect(ledgerConfig, bql, &queryParams, &statsCalendarQueryResult)
|
||||
if err != nil {
|
||||
InternalError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resultList := make([]StatsCalendarResult, 0)
|
||||
for _, queryRes := range statsCalendarQueryResult {
|
||||
if queryRes.Position != "" {
|
||||
fields := strings.Fields(queryRes.Position)
|
||||
resultList = append(resultList,
|
||||
StatsCalendarResult{
|
||||
Date: queryRes.Date,
|
||||
Account: queryRes.Account,
|
||||
Amount: json.Number(fields[0]),
|
||||
Currency: fields[1],
|
||||
CurrencySymbol: script.GetCommoditySymbol(fields[1]),
|
||||
})
|
||||
}
|
||||
}
|
||||
OK(c, resultList)
|
||||
}
|
||||
|
||||
type StatsPayeeQueryResult struct {
|
||||
Payee string
|
||||
Count int32
|
||||
Position string
|
||||
}
|
||||
|
||||
type StatsPayeeResult struct {
|
||||
Payee string `json:"payee"`
|
||||
Currency string `json:"operatingCurrency"`
|
||||
|
|
|
|||
Loading…
Reference in New Issue