Skip to content

Commit

Permalink
Fixing up the handlers to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ESteanes committed Jul 27, 2024
1 parent 6816ef9 commit ba28e01
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions datafetcher/handlers/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package handlers

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"

"github.com/esteanes/expense-manager/datafetcher/upclient"
)
Expand All @@ -14,8 +14,8 @@ type TransactionsHandler struct {
*BaseHandler
}

func NewTransactionHandler(log *log.Logger, upclient *upclient.APIClient, auth context.Context) *AccountHandler {
handler := &AccountHandler{}
func NewTransactionHandler(log *log.Logger, upclient *upclient.APIClient, auth context.Context) *TransactionsHandler {
handler := &TransactionsHandler{}
handler.BaseHandler = &BaseHandler{
Uri: "/transactions",
Log: log,
Expand All @@ -31,9 +31,17 @@ func (h *TransactionsHandler) Get(w http.ResponseWriter, r *http.Request) {
pageSize := int32(30) // int32 | The number of records to return in each page. (optional)
resp2, r2, err := h.UpClient.TransactionsAPI.TransactionsGet(h.UpAuth).PageSize(pageSize).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `TransactionsAPI.TransactionsGet``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r2.Body)
fmt.Fprintf(w, "Error when calling `TransactionsAPI.TransactionsGet``: %v\n", err)
fmt.Fprintf(w, "Full HTTP response: %v\n", r2.Body)
h.Log.Println(r2.Body)
}
// response from `TransactionsGet`: ListTransactionsResponse
fmt.Fprintf(os.Stdout, "Response from `TransactionsAPI.TransactionsGet`: %v\n", resp2)
fmt.Fprintf(w, "Response from `TransactionsAPI.TransactionsGet`: %v\n", resp2)
jsonString := `{"account":{"data":{"type":"accounts","id":"a90b55ad-1bcb-4e75-b407-0e0e1e5c8a6d"},"links":{"related":"https://api.up.com.au/api/v1/accounts/a90b55ad-1bcb-4e75-b407-0e0e1e5c8a6d"}},"transferAccount":{"data":null},"category":{"data":{"type":"categories","id":"public-transport"},"links":{"self":"https://api.up.com.au/api/v1/transactions/e33e57c4-efa9-496d-83bd-e1f8c0b9651c/relationships/category","related":"https://api.up.com.au/api/v1/categories/public-transport"}},"parentCategory":{"data":{"type":"categories","id":"transport"},"links":{"related":"https://api.up.com.au/api/v1/categories/transport"}},"tags":{"data":[],"links":{"self":"https://api.up.com.au/api/v1/transactions/e33e57c4-efa9-496d-83bd-e1f8c0b9651c/relationships/tags"}},"attachment":{"data":null}}`
var manualResponse upclient.TransactionResourceRelationships
err = json.Unmarshal([]byte(jsonString), &manualResponse)
fmt.Fprintf(w, "Manual json unmarshalling: %v\n", manualResponse)
if err != nil {
fmt.Fprintf(w, "error unmarshalling: %s\n", err)
}
}

0 comments on commit ba28e01

Please sign in to comment.