Implement confirmation service
This commit is contained in:
parent
0815b7015e
commit
da895c78e3
@ -6,16 +6,53 @@ import (
|
|||||||
"github.com/kcotugno/tacitus"
|
"github.com/kcotugno/tacitus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
conf_columns = `product, last_trade_id`
|
||||||
|
conf_insert = `INSERT INTO confirmations (` + conf_columns +
|
||||||
|
`) VALUES ($1, $2) RETURNING id, ` + conf_columns + `;`
|
||||||
|
conf_find_product = `SELECT id, ` + conf_columns + ` FROM confirmations` +
|
||||||
|
`WHERE product = $1`
|
||||||
|
conf_update = `UPDATE confirmation SET last_trade_id = $1 WHERE product = $2`
|
||||||
|
)
|
||||||
|
|
||||||
type ConfirmationService struct {
|
type ConfirmationService struct {
|
||||||
logger tacitus.Logger
|
logger tacitus.Logger
|
||||||
client *client
|
client *client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfirmationService) Confirmation(product·string)·(*Confirmation,·error) {
|
func (s *ConfirmationService) Confirmation(product string) (Confirmation, error) {
|
||||||
|
var conf Confirmation
|
||||||
|
|
||||||
|
res, err := s.client.QueryRow(conf_find_product, product)
|
||||||
|
if err != nil {
|
||||||
|
return conf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = row.Scan(&conf.Id, &conf.Product, &conf.LastTradeId)
|
||||||
|
if err != nil {
|
||||||
|
return conf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfirmationService) CreateConfirmation(c·*Confirmation)·error {
|
func (s *ConfirmationService) CreateConfirmation(c Confirmation) (Confirmation, error) {
|
||||||
|
var conf Confirmation
|
||||||
|
|
||||||
|
res, err := s.client.QueryRow(conf_insert, c.Product, c.LastTradeId)
|
||||||
|
if err != nil {
|
||||||
|
return conf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = row.Scan(&conf.Id, &conf.Product, &conf.LastTradeId)
|
||||||
|
if err != nil {
|
||||||
|
return conf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfirmationService) UpdateConfirmation(c·*Confirmation)·error {
|
func (s *ConfirmationService) UpdateConfirmation(c Confirmation) (Confirmation, error) {
|
||||||
|
res, err := s.client.Exec(conf_update, c.LastTradeId, c.Product)
|
||||||
|
return c, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user