-
Notifications
You must be signed in to change notification settings - Fork 1
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
915e489
commit 80dc61f
Showing
14 changed files
with
188 additions
and
387 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module V2 | ||
class OrderProductsController < ResourcesController | ||
end | ||
end |
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class Order | ||
module StateMachine | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include AASM | ||
|
||
# enum :status, { pending: 0, delivered: 1, cancelled: 2 } | ||
aasm column: :state, timestamps: true do | ||
state :pending, initial: true | ||
state :ordered | ||
state :delivered | ||
state :withdrawn | ||
state :cancelled | ||
|
||
event :order do | ||
transitions from: :pending, to: :ordered | ||
end | ||
|
||
event :deliver do | ||
transitions from: :ordered, to: :delivered | ||
end | ||
|
||
event :withdraw do | ||
transitions from: :delivered, to: :withdrawn | ||
end | ||
|
||
event :cancel do | ||
transitions from: %i[ordered delivered], to: :cancelled | ||
end | ||
end | ||
end | ||
end | ||
end |
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrderProductPolicy < Presets::UserEditablePolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.where(order: OrderPolicy::Scope.new(user, Order).resolve) | ||
end | ||
end | ||
end |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrderProductSerializer < ActiveModel::Serializer | ||
attributes :id, :quantity | ||
|
||
belongs_to :product | ||
end |
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrderSerializer < ActiveModel::Serializer | ||
attributes :id, :status, :created_at | ||
attributes :id, | ||
:state, | ||
:created_at, | ||
:updated_at, | ||
:ordered_at, | ||
:delivered_at, | ||
:withdrawn_at, | ||
:cancelled_at | ||
belongs_to :customer | ||
end |
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeOrderStatusToState < ActiveRecord::Migration[8.0] | ||
def change | ||
change_table :orders, bulk: true do |t| | ||
t.remove :status, type: :integer, default: 0 | ||
t.string :state | ||
t.datetime :ordered_at | ||
t.datetime :delivered_at | ||
t.datetime :withdrawn_at | ||
t.datetime :cancelled_at | ||
end | ||
end | ||
end |
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
Oops, something went wrong.