Skip to content

Commit

Permalink
added pos service
Browse files Browse the repository at this point in the history
  • Loading branch information
gipsh committed Nov 14, 2023
1 parent 0740cd4 commit 1f94622
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 76 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof

.env
20 changes: 20 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package mpsdkgo

import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/http/httputil"
Expand All @@ -10,6 +12,7 @@ import (
type ApiClient struct {
cfg *Config
Store *StoreService
Pos *PosService
BaseURL string
}

Expand All @@ -24,6 +27,7 @@ func NewApiClient(cfg *Config) *ApiClient {
}

client.Store = NewStoreService(client)
client.Pos = NewPosService(client)

return client

Expand Down Expand Up @@ -56,3 +60,19 @@ func (c *ApiClient) callAPI(request *http.Request) (*http.Response, error) {
}
return resp, err
}

func (c *ApiClient) DeserializeBody(body io.Reader, obj any) error {

b, err := io.ReadAll(body)
if err != nil {
return err
}

err = json.Unmarshal(b, obj)
if err != nil {
return err
}

return nil

}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/vudu-people/mp-sdk-go

go 1.20

require github.com/joho/godotenv v1.5.1
42 changes: 42 additions & 0 deletions model/pos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package model

type QR struct {
Image string `json:"image"`
TemplateDocument string `json:"template_document"`
TemplateImage string `json:"template_image"`
}

type Pos struct {
ID int `json:"id"`
QR QR `json:"qr"`
Status string `json:"status"`
DateCreated string `json:"date_created"`
DateLastUpdated string `json:"date_last_updated"`
UUID string `json:"uuid"`
UserID int `json:"user_id"`
Name string `json:"name"`
FixedAmount bool `json:"fixed_amount"`
Category int `json:"category"`
StoreID string `json:"store_id"`
ExternalID string `json:"external_id"`
Site string `json:"site"`
QrCode string `json:"qr_code"`
}

type CreatePosRequest struct {
StoreID int `json:"store_id"`
Name string `json:"name"`
FixedAmount bool `json:"fixed_amount"`
Category int `json:"category"`
ExternalStoreID string `json:"external_store_id,omitempty"`
ExternalID string `json:"external_id,omitempty"`
}

type GetAllPosResponse struct {
Paging struct {
Total int `json:"total"`
Offset int `json:"offset"`
Limit int `json:"limit"`
} `json:"paging"`
Results []Pos `json:"results"`
}
76 changes: 31 additions & 45 deletions model/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,38 @@ package model

import "time"

type BusinessHourPair struct {
Open string `json:"open"`
Close string `json:"close"`
}

type BusinessHours struct {
Monday []BusinessHourPair `json:"monday,omitempty"`
Tuesday []BusinessHourPair `json:"tuesday,omitempty"`
Wednesday []BusinessHourPair `json:"wednesday,omitempty"`
Thursday []BusinessHourPair `json:"thursday,omitempty"`
Friday []BusinessHourPair `json:"friday,omitempty"`
Saturday []BusinessHourPair `json:"saturday,omitempty"`
Sunday []BusinessHourPair `json:"sunday,omitempty"`
}

type CreateStoreRequest struct {
Name string `json:"name"`
BusinessHours struct {
Monday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"monday,omitempty"`
Tuesday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"tuesday,omitempty"`
Wednesday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"wednesday,omitempty"`
Thursday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"thursday,omitempty"`
Friday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"friday,omitempty"`
Saturday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"saturday,omitempty"`
Sunday []struct {
Open string `json:"open"`
Close string `json:"close"`
} `json:"sunday,omitempty"`
} `json:"business_hours"`
Location struct {
StreetNumber string `json:"street_number"`
StreetName string `json:"street_name"`
CityName string `json:"city_name"`
StateName string `json:"state_name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Reference string `json:"reference"`
} `json:"location"`
ExternalID string `json:"external_id"`
Name string `json:"name,omitempty"`
BusinessHours BusinessHours `json:"business_hours"`
Location struct {
StreetNumber string `json:"street_number,omitempty"`
StreetName string `json:"street_name,omitempty"`
CityName string `json:"city_name,omitempty"`
StateName string `json:"state_name,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Reference string `json:"reference,omitempty"`
} `json:"location,omitempty"`
ExternalID string `json:"external_id,omitempty"`
}

type CreateStoreResponse struct {
ID int `json:"id"`
type Store struct {
ID string `json:"id"`
Name string `json:"name"`
DateCreated time.Time `json:"date_created"`
BusinessHours struct {
Expand All @@ -70,7 +56,7 @@ type CreateStoreResponse struct {
}

type GetStoreResponse struct {
CreateStoreResponse
Store
}

type UpdateStoreRequest struct {
Expand All @@ -83,5 +69,5 @@ type GetStoresResponse struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
} `json:"paging"`
Results []CreateStoreResponse `json:"results"`
Results []Store `json:"results"`
}
Loading

0 comments on commit 1f94622

Please sign in to comment.