Skip to content

Commit

Permalink
Update ESModels and Inventory end-pts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskaranbir committed Nov 8, 2018
1 parent 48245d4 commit 115e915
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ KAFKA_BROKERS=kafka:9092
KAFKA_PRODUCER_EVENT_TOPIC=event.rns_eventstore.events

KAFKA_CONSUMER_TOPIC_USERAUTH=agg.userauth.response
KAFKA_CONSUMER_TOPIC_INVENTORY=aggregate.inventory.response
KAFKA_CONSUMER_TOPIC_INVENTORY=agg.inventory.response

REDIS_HOST=localhost:6379
REDIS_DB=0
28 changes: 10 additions & 18 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@

[[constraint]]
name = "github.com/TerrexTech/go-eventstore-models"
version = "3.0.0"
version = "4.0.0"

[[constraint]]
name = "github.com/TerrexTech/go-kafkautils"
version = "3.0.0"
version = "3.1.0"

[[constraint]]
name = "github.com/TerrexTech/uuuid"
Expand All @@ -66,7 +66,7 @@

[[constraint]]
name = "github.com/mongodb/mongo-go-driver"
version = "0.0.16"
version = "=0.0.14"

[[constraint]]
name = "github.com/pkg/errors"
Expand Down
14 changes: 7 additions & 7 deletions gql/entity/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
```graphql
mutation{
authRegister(
userName:"testUserName",
password:"testPassword",
firstName:"testFirstName",
lastName:"testLastName",
email:"testEmail",
userName:"danpie3",
password:"danpie",
firstName:"obnoxious",
lastName:"potato",
email:"explosion",
role:"employee"
){
accessToken,
Expand All @@ -24,8 +24,8 @@
```graphql
{
authLogin(
userName:"testUserName",
password:"testPassword"
userName: "danpie",
password:"danpie"
){
accessToken,
refreshToken
Expand Down
17 changes: 8 additions & 9 deletions gql/entity/auth/resolver/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ var Login = func(params graphql.ResolveParams) (interface{}, error) {
// CorrelationID
cid, err := uuuid.NewV4()
if err != nil {
err = errors.Wrap(err, "AuthRegisterResolver: Error generating UUID for cid")
err = errors.Wrap(err, "AuthLoginResolver: Error generating UUID for cid")
return nil, err
}
timeUUID, err := uuuid.NewV1()
uuid, err := uuuid.NewV4()
if err != nil {
err = errors.Wrap(err, "AuthRegisterResolver: Error generating UUID for Register-Event")
err = errors.Wrap(err, "AuthLoginResolver: Error generating UUID for Login-Event")
return nil, err
}

// Publish Auth-Request on Kafka Topic
kf.EventProducer() <- &esmodel.Event{
Action: "query",
EventAction: "query",
CorrelationID: cid,
AggregateID: 1,
Data: credentialsJSON,
Timestamp: time.Now(),
TimeUUID: timeUUID,
NanoTime: time.Now().UnixNano(),
UUID: uuid,
YearBucket: 2018,
}

cio, err := kf.EnsureConsumerIO(consTopic, consTopic, false, timeUUID)
cio, err := kf.EnsureConsumerIO(consTopic, consTopic, false, uuid)
if err != nil {
err = errors.Wrap(err, "AuthLoginResolver: Error creating ConsumerIO")
return nil, err
Expand All @@ -72,7 +72,7 @@ authResponseLoop:
case <-ctx.Done():
break authResponseLoop
case msg := <-cio:
authRes := handleLoginResponse(msg, ts, cid)
authRes := handleLoginResponse(msg, ts)
if authRes != nil {
if authRes.Err == nil {
return authRes.Result, nil
Expand All @@ -88,7 +88,6 @@ authResponseLoop:
func handleLoginResponse(
kr esmodel.KafkaResponse,
ts auth.TokenStoreI,
cid uuuid.UUID,
) *response.ResolverResponse {
if kr.Error != "" {
err := errors.New(kr.Error)
Expand Down
10 changes: 5 additions & 5 deletions gql/entity/auth/resolver/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ var Register = func(params graphql.ResolveParams) (interface{}, error) {
err = errors.Wrap(err, "AuthRegisterResolver: Error generating UUID for cid")
return nil, err
}
timeUUID, err := uuuid.NewV1()
uuid, err := uuuid.NewV4()
if err != nil {
err = errors.Wrap(err, "AuthRegisterResolver: Error generating UUID for Register-Event")
return nil, err
}

// Publish Auth-Request on Kafka Topic
kf.EventProducer() <- &esmodel.Event{
Action: "insert",
EventAction: "insert",
CorrelationID: cid,
AggregateID: 1,
Data: credentialsJSON,
Timestamp: time.Now(),
TimeUUID: timeUUID,
NanoTime: time.Now().UnixNano(),
UUID: uuid,
YearBucket: 2018,
}

// Timeout Context
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

krChan, err := kf.EnsureConsumerIO(consTopic, consTopic, false, timeUUID)
krChan, err := kf.EnsureConsumerIO(consTopic, consTopic, false, uuid)
if err != nil {
err = errors.Wrap(err, "AuthRegisterResolver: Error creating ConsumerIO")
return nil, err
Expand Down
61 changes: 59 additions & 2 deletions gql/entity/inventory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
mutation{
InventoryInsert(
itemID: "c2167f7a-1eeb-4c6e-8605-6456dbccc2a7",
barcode: "test-barcode",
dateArrived: 1539222685400,
dateSold: 1539222685400,
deviceID: "5d79d6f6-3181-4fec-a474-0a5b0020c6cb",
Expand All @@ -17,7 +18,6 @@
name: "test_item",
origin: "test_origin",
price: 23.65,
quantity: 3
rsCustomerID: "a571181c-06c3-4436-a79d-21580cef1086",
salePrice: 23.45,
sku: "test-sku"
Expand All @@ -30,6 +30,64 @@
{
_id,
itemID,
barcode,
dateArrived,
dateSold,
deviceID,
donateWeight,
expiryDate,
lot,
name,
origin,
price,
rsCustomerID,
salePrice,
sku,
soldWeight,
timestamp,
totalWeight,
upc,
wasteWeight
}
}
```

* #### InventoryDelete
```graphql
mutation{
InventoryDelete(
itemID: "c2167f7a-1eeb-4c6e-8605-6456dbccc2a7",
){
deletedCount
}
}
```

* #### InventoryUpdate
```graphql
mutation{
InventoryUpdate(
filter: {
itemID: "c2167f7a-1eeb-4c6e-8605-6456dbccc2a7"
},
update: {
origin: "new-origin"
},
){
matchedCount, modifiedCount
}
}
```

* #### InventoryQuery
```graphql
{
InventoryQuery(
itemID: "642fcd6f-bca0-467a-aa9a-2581288a8f00",
){
_id,
itemID,
barcode,
dateArrived,
dateSold,
deviceID,
Expand All @@ -39,7 +97,6 @@
name,
origin,
price,
quantity,
rsCustomerID,
salePrice,
sku,
Expand Down
6 changes: 3 additions & 3 deletions gql/entity/inventory/mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var Mutations = map[string]*graphql.Field{
"itemID": &graphql.ArgumentConfig{
Type: graphql.String,
},
"barcode": &graphql.ArgumentConfig{
Type: graphql.String,
},
"dateArrived": &graphql.ArgumentConfig{
Type: graphql.Int,
},
Expand Down Expand Up @@ -41,9 +44,6 @@ var Mutations = map[string]*graphql.Field{
"price": &graphql.ArgumentConfig{
Type: graphql.Float,
},
"quantity": &graphql.ArgumentConfig{
Type: graphql.Int,
},
"rsCustomerID": &graphql.ArgumentConfig{
Type: graphql.String,
},
Expand Down
Loading

0 comments on commit 115e915

Please sign in to comment.