-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
117bf3c
commit d83a5f2
Showing
18 changed files
with
263 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,12 @@ http: | |
host: '0.0.0.0' | ||
port: 5002 | ||
|
||
postgres: | ||
pool_max: 2 | ||
url: postgres://postgres:P@[email protected]:5432/postgres?sslmode=disable | ||
|
||
rabbit_mq: | ||
url: amqp://guest:[email protected].255.101:5672/ | ||
url: amqp://guest:[email protected].240.102:5672/ | ||
|
||
logger: | ||
log_level: 'debug' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ http: | |
|
||
postgres: | ||
pool_max: 2 | ||
url: postgres://postgres:P@[email protected].255.101:5432/postgres?sslmode=disable | ||
url: postgres://postgres:P@[email protected].240.102:5432/postgres?sslmode=disable | ||
|
||
rabbit_mq: | ||
url: amqp://guest:[email protected].255.101:5672/ | ||
url: amqp://guest:[email protected].240.102:5672/ | ||
|
||
product_client: | ||
url: 0.0.0.0:5001 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,12 @@ http: | |
host: '0.0.0.0' | ||
port: 5004 | ||
|
||
postgres: | ||
pool_max: 2 | ||
url: postgres://postgres:P@[email protected]:5432/postgres?sslmode=disable | ||
|
||
rabbit_mq: | ||
url: amqp://guest:[email protected].255.101:5672/ | ||
url: amqp://guest:[email protected].240.102:5672/ | ||
|
||
logger: | ||
log_level: 'debug' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package domain | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ( | ||
OrderRepo interface { | ||
Create(context.Context, *BaristaOrder) error | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package domain | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/thangchung/go-coffeeshop/proto/gen" | ||
) | ||
|
||
type BaristaOrder struct { | ||
ID uuid.UUID `json:"id" db:"id"` | ||
ItemName string `json:"itemName" db:"item_name"` | ||
ItemType gen.ItemType `json:"itemType" db:"item_type"` | ||
TimeUp time.Time `json:"timeUp" db:"time_up"` | ||
Created time.Time `json:"created" db:"created"` | ||
Updated time.Time `json:"updated" db:"updated"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package repo | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/thangchung/go-coffeeshop/internal/barista/domain" | ||
"github.com/thangchung/go-coffeeshop/pkg/postgres" | ||
) | ||
|
||
var _ domain.OrderRepo = (*orderRepo)(nil) | ||
|
||
type orderRepo struct { | ||
pg *postgres.Postgres | ||
} | ||
|
||
func NewOrderRepo(pg *postgres.Postgres) domain.OrderRepo { | ||
return &orderRepo{pg: pg} | ||
} | ||
|
||
func (d *orderRepo) Create(ctx context.Context, baristaOrder *domain.BaristaOrder) error { | ||
tx, err := d.pg.Pool.Begin(ctx) | ||
if err != nil { | ||
return errors.Wrapf(err, "orderRepo-Create-d.pg.Pool.Begin(ctx)") | ||
} | ||
|
||
// insert order | ||
sql, args, err := d.pg.Builder. | ||
Insert(`"barista".barista_orders`). | ||
Columns("id", "item_type", "item_name", "time_up", "created", "updated"). | ||
Values( | ||
baristaOrder.ID, | ||
baristaOrder.ItemType, | ||
baristaOrder.ItemName, | ||
baristaOrder.TimeUp, | ||
baristaOrder.Created, | ||
baristaOrder.Updated, | ||
). | ||
ToSql() | ||
if err != nil { | ||
return tx.Rollback(ctx) | ||
} | ||
|
||
_, err = d.pg.Pool.Exec(ctx, sql, args...) | ||
if err != nil { | ||
return tx.Rollback(ctx) | ||
} | ||
|
||
return tx.Commit(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package domain | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ( | ||
OrderRepo interface { | ||
Create(context.Context, *KitchenOrder) error | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package domain | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/thangchung/go-coffeeshop/proto/gen" | ||
) | ||
|
||
type KitchenOrder struct { | ||
ID uuid.UUID `json:"id" db:"id"` | ||
OrderID uuid.UUID `json:"orderId" db:"order_id"` | ||
ItemName string `json:"itemName" db:"item_name"` | ||
ItemType gen.ItemType `json:"itemType" db:"item_type"` | ||
TimeUp time.Time `json:"timeUp" db:"time_up"` | ||
Created time.Time `json:"created" db:"created"` | ||
Updated time.Time `json:"updated" db:"updated"` | ||
} |
Oops, something went wrong.