Skip to content

Commit

Permalink
broker type enhanced
Browse files Browse the repository at this point in the history
now it supports title, url and logo
  • Loading branch information
guneyin committed Jun 21, 2023
1 parent 6399cc2 commit cd4570a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
7 changes: 5 additions & 2 deletions importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"errors"
"github.com/guneyin/gobist-importer/pkg"
"github.com/guneyin/gobist-importer/pkg/broker"
"github.com/guneyin/gobist-importer/pkg/broker/garanti"
"github.com/guneyin/gobist-importer/pkg/entity"
)

func GetBrokers() []broker.Broker {
return []broker.Broker{broker.Garanti}
func GetBrokers() []pkg.IBroker {
return []pkg.IBroker{
garanti.Garanti{},
}
}

func GetBrokerByName(name string) (*broker.Broker, error) {
Expand Down
6 changes: 4 additions & 2 deletions importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ func TestImporter(t *testing.T) {
brokers := importer.GetBrokers()
assertNotNil(t, brokers)

for _, b := range brokers {
fmt.Printf("Broker Name: %s\n", b.String())
fmt.Println("Supported Brokers:")

for i, b := range brokers {
fmt.Printf(" %d- %s\n", i+1, b.Get().Title)
}

b, err := importer.GetBrokerByName("garanti")
Expand Down
5 changes: 3 additions & 2 deletions pkg/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
)

type IBroker interface {
Get() broker.Broker
Get() broker.Model
Parse(content []byte) (*entity.Transactions, error)
}

Expand All @@ -30,11 +30,12 @@ func NewBrokerAdapter(b broker.Broker) (*BrokerAdapter, error) {
default:
return nil, fmt.Errorf("unspported broker %s", b)
}

return &BrokerAdapter{broker: v}, nil
}

func (va *BrokerAdapter) Parse(content []byte) (*entity.Transactions, error) {
fmt.Println(fmt.Sprintf("reading %v transactions..", va.broker.Get()))
fmt.Println(fmt.Sprintf("reading %v transactions..", va.broker.Get().Name))

return va.broker.Parse(content)
}
7 changes: 7 additions & 0 deletions pkg/broker/broker.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package broker

type Model struct {
Name string
Title string
Url string
Logo string
}

type Broker string

const (
Expand Down
13 changes: 10 additions & 3 deletions pkg/broker/garanti/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ const (
HISSE_SATIS = "Hisse Satış"
)

type Garanti struct{}
type Garanti struct {
broker.Model
}

func (g Garanti) Get() broker.Broker {
return broker.Garanti
func (g Garanti) Get() broker.Model {
return broker.Model{
Name: broker.Garanti.String(),
Title: "Garanti Yatırım Menkul Kıymetler A.Ş.",
Url: "https://www.garantibbvayatirim.com.tr/",
Logo: "https://www.garantibbvayatirim.com.tr/_assets/img/logo.svg",
}
}

func (g Garanti) Parse(content []byte) (*entity.Transactions, error) {
Expand Down

0 comments on commit cd4570a

Please sign in to comment.