Skip to content

Commit

Permalink
code refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
guneyin committed Jun 23, 2023
1 parent 1678415 commit 4dd1c3f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
29 changes: 0 additions & 29 deletions broker/ncm/adapter.go

This file was deleted.

18 changes: 9 additions & 9 deletions broker/garanti/garanti.go → brokers/garanti/garanti.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package garanti

import (
"errors"
"github.com/guneyin/gobist-broker/broker"

"github.com/guneyin/gobist-broker/entity"
"github.com/guneyin/gobist-broker/lib"
"github.com/guneyin/gobist-broker/lib/reader"
Expand All @@ -19,21 +19,21 @@ const (
)

type Garanti struct {
info broker.Info
info entity.Info
}

func New() *Garanti {
return &Garanti{
info: broker.Info{
Enum: broker.Garanti,
Name: "Garanti Yatırım",
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",
info: entity.Info{
Name: entity.Garanti.String(),
Title: "Garanti Yatırım",
TitleLong: "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 (b Garanti) Info() broker.Info {
func (b Garanti) Info() entity.Info {
return b.info
}

Expand Down
28 changes: 28 additions & 0 deletions brokers/ncm/ncm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ncm

import (
"github.com/guneyin/gobist-broker/entity"
)

type NCM struct {
info entity.Info
}

func New() *NCM {
return &NCM{
info: entity.Info{
Name: entity.NCM.String(),
Title: "NCM Investment",
TitleLong: "NCM Investment Menkul Değerler A.Ş.",
Url: "https://ncminvest.com.tr/",
Logo: "https://ncminvest.com.tr/Resimler/5/5-logo.webp",
}}
}

func (b NCM) Info() entity.Info {
return b.info
}

func (b NCM) Parse(content []byte) (*entity.Transactions, error) {
return nil, nil
}
12 changes: 6 additions & 6 deletions broker/broker.go → entity/broker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package broker
package entity

type EnumBroker string

Expand All @@ -12,9 +12,9 @@ func (t EnumBroker) String() string {
}

type Info struct {
Enum EnumBroker
Name string
Title string
Url string
Logo string
Name string
Title string
TitleLong string
Url string
Logo string
}
File renamed without changes.
21 changes: 10 additions & 11 deletions module.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package module
package broker

import (
"errors"
"github.com/guneyin/gobist-broker/broker"
"github.com/guneyin/gobist-broker/broker/garanti"
"github.com/guneyin/gobist-broker/broker/ncm"
"github.com/guneyin/gobist-broker/brokers/garanti"
"github.com/guneyin/gobist-broker/brokers/ncm"
"github.com/guneyin/gobist-broker/entity"
"sync"
)
Expand All @@ -15,11 +14,11 @@ var (
)

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

type Brokers map[broker.EnumBroker]Broker
type Brokers map[entity.EnumBroker]Broker

var brokers Brokers

Expand All @@ -28,8 +27,8 @@ func init() {

once.Do(func() {
brokers = Brokers{
broker.Garanti: garanti.New(),
broker.NCM: ncm.New(),
entity.Garanti: garanti.New(),
entity.NCM: ncm.New(),
}
})
}
Expand All @@ -38,16 +37,16 @@ func GetBrokers() Brokers {
return brokers
}

func GetBroker(b broker.EnumBroker) Broker {
func GetBroker(b entity.EnumBroker) Broker {
return brokers[b]
}

func GetBrokerByName(name string) (Broker, error) {
if ok := broker.EnumBroker(name); ok == "" {
if ok := entity.EnumBroker(name); ok == "" {
return nil, errors.New("UNSPPORTED_BROKER")
}

b := broker.EnumBroker(name)
b := entity.EnumBroker(name)

return GetBroker(b), nil
}
12 changes: 6 additions & 6 deletions module_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package module_test
package broker_test

import (
"fmt"
Expand All @@ -10,20 +10,20 @@ import (
)

func TestImporter(t *testing.T) {
brokers := module.GetBrokers()
brokers := broker.GetBrokers()
assertNotNil(t, brokers)

fmt.Println("Supported Brokers:")

i := 0
for _, v := range brokers {
i++
fmt.Printf(" %d- %s\n", i, v.Info().Name)
fmt.Printf(" %d- %s\n", i, v.Info().TitleLong)
}

fmt.Println()

b, err := module.GetBrokerByName("garanti")
b, err := broker.GetBrokerByName("garanti")
assertError(t, err)
assertNotNil(t, b)

Expand All @@ -45,8 +45,8 @@ func TestImporter(t *testing.T) {
}
}

func importFile(b module.Broker, t string) (*entity.Transactions, error) {
fPath := fmt.Sprintf("testdata/%s/%s.csv", b.Info().Enum.String(), t)
func importFile(b broker.Broker, t string) (*entity.Transactions, error) {
fPath := fmt.Sprintf("testdata/%s/%s.csv", b.Info().Name, t)

fileContent, err := os.ReadFile(fPath)
if err != nil {
Expand Down

0 comments on commit 4dd1c3f

Please sign in to comment.