package web import ( "context" "database/sql" "encoding/json" "fmt" "net/http" "time" "github.com/go-chi/chi/v5" "github.com/rs/zerolog/log" "nickiel.net/recount_server/types" ) const DEFAULT_RESULT_COUNT = 20; func getTransactionsRows(w http.ResponseWriter, req *http.Request) { transactions := make([]types.HumanLegibleTransaction, 10) // Populate the slice with dummy data (you can replace this with your actual data) for i := 10; i > 0; i-- { transaction := types.HumanLegibleTransaction{ Id: i, Amount: fmt.Sprintf("%d.00", (i+1)*100), Description: sql.NullString{String: fmt.Sprintf("Transaction %d", i+1), Valid: true}, AccountName: sql.NullString{String: "Savings", Valid: true}, Account: 123, Bucket: sql.NullInt64{Int64: int64(i + 100), Valid: true}, BucketName: sql.NullString{String: fmt.Sprintf("Bucket %d", i+1), Valid: true}, Date: time.Now(), } transactions[10 - i] = transaction } component := transaction_rows(&transactions); component.Render(context.Background(), w); } func getTransactionQuickAccessEntries(w http.ResponseWriter, req *http.Request) { transactions := make([]types.HumanLegibleTransaction, 20) // Populate the slice with dummy data (you can replace this with your actual data) for i := 20; i > 0; i-- { transaction := types.HumanLegibleTransaction{ Id: i, Amount: fmt.Sprintf("%d.00", (i+1)*100), Description: sql.NullString{String: fmt.Sprintf("Transaction %d", i+1), Valid: true}, AccountName: sql.NullString{String: "Savings", Valid: true}, Account: 123, Bucket: sql.NullInt64{Int64: int64(i + 100), Valid: true}, BucketName: sql.NullString{String: fmt.Sprintf("Bucket %d", i+1), Valid: true}, Date: time.Now(), } transactions[20 - i] = transaction } component := transaction_quick_access_entries(&transactions); component.Render(context.Background(), w); } func getRightPanelQuickAccess(w http.ResponseWriter, req *http.Request) { component := right_panel_quick_access(); component.Render(context.Background(), w); } func getExpenditureChart(w http.ResponseWriter, req *http.Request) { data_package := struct{ Labels []string `json:"labels"` IncomeDataset []int `json:"income_data"` ExpensesDataset []int `json:"expenses_data"` } { Labels: []string{"Income", "Expenses"}, IncomeDataset: []int {300, 250}, ExpensesDataset: []int {200, 100}, }; json_data, err := json.Marshal(data_package); if err != nil { log.Fatal().Err(err).Msg("Could not jsonify data_package"); } w.Write(json_data); } func getAccountSummaries(w http.ResponseWriter, req *http.Request) { accounts := make([]types.TwoIntsItem, 20) for i := 0; i < 20; i++ { accounts[i] = types.TwoIntsItem {Item1: i*100, Item2: i+5} } component := account_summary_rows(&accounts) component.Render(context.Background(), w) } func getAccountSummaryChart(w http.ResponseWriter, req *http.Request) { accountID := chi.URLParam(req, "accountID") data_package := types.ChartjsData { Labels: []string {accountID, "1/10", "1/17", "1/24"}, Data: []int {100, 0, -50, 25}, } json_data, err := json.Marshal(data_package); if err != nil { log.Fatal().Err(err).Msg("Could not jsonify data_package"); } w.Write(json_data); }