Skip to content

Commit

Permalink
refactor: removed unused functions from the model package and gave ap…
Browse files Browse the repository at this point in the history
…propriate names to the structures
  • Loading branch information
vvatanabe committed Sep 17, 2023
1 parent 5857a01 commit 10132d8
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 481 deletions.
12 changes: 6 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *CLI) Run(ctx context.Context, command string, params []string) {
return
}
c.Shipment.ResetSystemInfo()
c.Shipment.SystemInfo.Status = model.StatusEnumReadyToShip
c.Shipment.SystemInfo.Status = model.StatusReadyToShip
err := c.Client.Put(ctx, c.Shipment)
if err != nil {
printError(err)
Expand All @@ -180,7 +180,7 @@ func (c *CLI) Run(ctx context.Context, command string, params []string) {
printError("'done' command can be only used in the CLI's App mode. Call first `id <record-id>`")
return
}
rr, err := c.Client.UpdateStatus(ctx, c.Shipment.ID, model.StatusEnumCompleted)
rr, err := c.Client.UpdateStatus(ctx, c.Shipment.ID, model.StatusCompleted)
if err != nil {
printError(err)
return
Expand Down Expand Up @@ -312,9 +312,9 @@ func (c *CLI) Run(ctx context.Context, command string, params []string) {
return
}
// convert under_construction to ready to ship
if shipment.SystemInfo.Status == model.StatusEnumUnderConstruction {
if shipment.SystemInfo.Status == model.StatusUnderConstruction {
shipment.ResetSystemInfo()
shipment.SystemInfo.Status = model.StatusEnumReadyToShip
shipment.SystemInfo.Status = model.StatusReadyToShip
err = c.Client.Put(ctx, shipment)
if err != nil {
printError(err)
Expand Down Expand Up @@ -380,9 +380,9 @@ func (c *CLI) Run(ctx context.Context, command string, params []string) {
return
}
statusStr := strings.TrimSpace(strings.ToUpper(params[0]))
if statusStr == string(model.StatusEnumReadyToShip) {
if statusStr == string(model.StatusReadyToShip) {
c.Shipment.MarkAsReadyForShipment()
rr, err := c.Client.UpdateStatus(ctx, c.Shipment.ID, model.StatusEnumReadyToShip)
rr, err := c.Client.UpdateStatus(ctx, c.Shipment.ID, model.StatusReadyToShip)
if err != nil {
printError(err)
return
Expand Down
50 changes: 0 additions & 50 deletions model/dequeueresult.go

This file was deleted.

37 changes: 0 additions & 37 deletions model/dlqresult.go

This file was deleted.

21 changes: 0 additions & 21 deletions model/enqueueresult.go

This file was deleted.

37 changes: 0 additions & 37 deletions model/peekresult.go

This file was deleted.

59 changes: 0 additions & 59 deletions model/queuestats.go

This file was deleted.

130 changes: 130 additions & 0 deletions model/result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package model

type Result struct {
ID string `json:"id"`
ReturnValue ReturnStatus `json:"return_value"`
Status Status `json:"status"`
LastUpdatedTimestamp string `json:"last_updated_timestamp"`
Version int `json:"version"`
}

func NewReturnResultWithID(id string) *Result {
return &Result{
ID: id,
ReturnValue: ReturnStatusNone,
Status: StatusNone,
}
}

func (rr *Result) IsSuccessful() bool {
return rr.ReturnValue == ReturnStatusSUCCESS
}

func (rr *Result) GetErrorMessage() string {
return rr.ReturnValue.GetErrorMessage()
}

// ReturnStatus defines the statuses for queue operations.
type ReturnStatus int

const (
ReturnStatusNone ReturnStatus = iota
ReturnStatusSUCCESS
ReturnStatusFailedIDNotProvided
ReturnStatusFailedIDNotFound
ReturnStatusFailedRecordNotConstructed
ReturnStatusFailedOnCondition
ReturnStatusFailedEmptyQueue
ReturnStatusFailedIllegalState
ReturnStatusFailedDynamoError
)

// String maps ReturnStatus values to their string representations.
func (e ReturnStatus) String() string {
switch e {
case ReturnStatusNone:
return "NONE"
case ReturnStatusSUCCESS:
return "SUCCESS"
case ReturnStatusFailedIDNotProvided:
return "FAILED_ID_NOT_PROVIDED"
case ReturnStatusFailedIDNotFound:
return "FAILED_ID_NOT_FOUND"
case ReturnStatusFailedRecordNotConstructed:
return "FAILED_RECORD_NOT_CONSTRUCTED"
case ReturnStatusFailedOnCondition:
return "FAILED_ON_CONDITION"
case ReturnStatusFailedEmptyQueue:
return "FAILED_EMPTY_QUEUE"
case ReturnStatusFailedIllegalState:
return "FAILED_ILLEGAL_STATE"
case ReturnStatusFailedDynamoError:
return "FAILED_DYNAMO_ERROR"
default:
return "UNKNOWN"
}
}

// GetErrorMessage returns the associated error message for the ReturnStatus value.
func (e ReturnStatus) GetErrorMessage() string {
switch e {
case ReturnStatusNone:
return "No error"
case ReturnStatusFailedIDNotProvided:
return "ID was not provided!"
case ReturnStatusFailedIDNotFound:
return "Provided Shipment ID was not found in the Dynamo DB!"
case ReturnStatusFailedRecordNotConstructed:
return "Shipment record not yet fully constructed .. cannot execute API!"
case ReturnStatusFailedOnCondition:
return "Condition on the 'version' attribute has failed!"
case ReturnStatusFailedEmptyQueue:
return "Cannot proceed, queue is empty!"
case ReturnStatusFailedIllegalState:
return "Illegal state, cannot proceed!"
case ReturnStatusFailedDynamoError:
return "Unspecified DynamoDB error is encountered!"
default:
return "API was not called!"
}
}

type DequeueResult struct {
*Result
DequeuedShipmentObject *Shipment `json:"-"`
}

func NewDequeueResultFromReturnResult(result *Result) *DequeueResult {
return &DequeueResult{
Result: result,
}
}

// EnqueueResult represents the result for the enqueue() API call.
type EnqueueResult struct {
*Result // Embedded type for inheritance-like behavior in Go
Shipment *Shipment `json:"-"`
}

// NewEnqueueResultWithID constructs a new EnqueueResult with the provided ID.
func NewEnqueueResultWithID(id string) *EnqueueResult {
return &EnqueueResult{
Result: &Result{
ID: id,
},
}
}

// PeekResult represents the result for the peek() API call.
type PeekResult struct {
*Result // Embedded type for inheritance-like behavior in Go
TimestampMillisUTC int64 `json:"timestamp_milliseconds_utc"`
PeekedShipmentObject *Shipment `json:"-"`
}

// NewPeekResult constructs a new PeekResult with the default values.
func NewPeekResult() *PeekResult {
return &PeekResult{
Result: &Result{},
}
}
Loading

0 comments on commit 10132d8

Please sign in to comment.