Commit fd0a77f7 authored by Will Cory's avatar Will Cory

refactor: Rename DB Dao

parent 6c62f3f6
...@@ -9,18 +9,19 @@ import ( ...@@ -9,18 +9,19 @@ import (
"github.com/go-chi/chi" "github.com/go-chi/chi"
) )
// Database interface for deposits // TODO in this pr most of these types should be coming from the ORM instead
type DepositDB interface {
// DepositsDAO represents the Database Access Object for deposits
type DepositDAO interface {
GetDeposits(limit int, cursor string, sortDirection string) ([]Deposit, string, bool, error) GetDeposits(limit int, cursor string, sortDirection string) ([]Deposit, string, bool, error)
} }
// Database interface for withdrawals // WithdrawalDAO represents the Database Access Object for deposits
type WithdrawalDB interface { type WithdrawalDAO interface {
GetWithdrawals(limit int, cursor string, sortDirection string, sortBy string) ([]Withdrawal, string, bool, error) GetWithdrawals(limit int, cursor string, sortDirection string, sortBy string) ([]Withdrawal, string, bool, error)
} }
// Deposit data structure // Deposit data structure
// TODO this should be coming from the ORM instead
type Deposit struct { type Deposit struct {
Guid string `json:"guid"` Guid string `json:"guid"`
Amount string `json:"amount"` Amount string `json:"amount"`
...@@ -34,7 +35,6 @@ type Deposit struct { ...@@ -34,7 +35,6 @@ type Deposit struct {
} }
// Withdrawal data structure // Withdrawal data structure
// TODO this should be coming from teh ORM instead
type Withdrawal struct { type Withdrawal struct {
Guid string `json:"guid"` Guid string `json:"guid"`
Amount string `json:"amount"` Amount string `json:"amount"`
...@@ -88,7 +88,7 @@ func (a *Api) DepositsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -88,7 +88,7 @@ func (a *Api) DepositsHandler(w http.ResponseWriter, r *http.Request) {
cursor := r.URL.Query().Get("cursor") cursor := r.URL.Query().Get("cursor")
sortDirection := r.URL.Query().Get("sortDirection") sortDirection := r.URL.Query().Get("sortDirection")
deposits, nextCursor, hasNextPage, err := a.DepositDB.GetDeposits(limit, cursor, sortDirection) deposits, nextCursor, hasNextPage, err := a.DepositDAO.GetDeposits(limit, cursor, sortDirection)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
...@@ -109,7 +109,7 @@ func (a *Api) WithdrawalsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -109,7 +109,7 @@ func (a *Api) WithdrawalsHandler(w http.ResponseWriter, r *http.Request) {
sortDirection := r.URL.Query().Get("sortDirection") sortDirection := r.URL.Query().Get("sortDirection")
sortBy := r.URL.Query().Get("sortBy") sortBy := r.URL.Query().Get("sortBy")
withdrawals, nextCursor, hasNextPage, err := a.WithdrawalDB.GetWithdrawals(limit, cursor, sortDirection, sortBy) withdrawals, nextCursor, hasNextPage, err := a.WithdrawalDAO.GetWithdrawals(limit, cursor, sortDirection, sortBy)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
...@@ -144,17 +144,17 @@ func jsonResponse(w http.ResponseWriter, data interface{}, statusCode int) { ...@@ -144,17 +144,17 @@ func jsonResponse(w http.ResponseWriter, data interface{}, statusCode int) {
type Api struct { type Api struct {
Router *chi.Mux Router *chi.Mux
DepositDB DepositDB DepositDAO DepositDAO
WithdrawalDB WithdrawalDB WithdrawalDAO WithdrawalDAO
} }
func NewApi(depositDB DepositDB, withdrawalDB WithdrawalDB) *Api { func NewApi(depositDAO DepositDAO, withdrawalDAO WithdrawalDAO) *Api {
r := chi.NewRouter() r := chi.NewRouter()
api := &Api{ api := &Api{
Router: r, Router: r,
DepositDB: depositDB, DepositDAO: depositDAO,
WithdrawalDB: withdrawalDB, WithdrawalDAO: withdrawalDAO,
} }
r.Get("/api/v0/deposits", api.DepositsHandler) r.Get("/api/v0/deposits", api.DepositsHandler)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment