Skip to content

Commit 3ae08c8

Browse files
authored
move events under models (#51)
1 parent 2af92ee commit 3ae08c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+200
-105
lines changed

app/domains/accountify/contact.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Accountify
22
module Contact
33
extend self
44

5-
class CreatedEvent < Event; end
6-
75
def create(user_id:, tenant_id:,
86
organisation_id:, first_name:, last_name:, email:)
97
contact = nil
@@ -18,7 +16,7 @@ def create(user_id:, tenant_id:,
1816
last_name: last_name,
1917
email: email)
2018

21-
event = CreatedEvent
19+
event = Models::Contact::CreatedEvent
2220
.create!(
2321
user_id: user_id,
2422
tenant_id: tenant_id,
@@ -58,8 +56,6 @@ def find_by_id(user_id:, tenant_id:, id:)
5856
}
5957
end
6058

61-
class UpdatedEvent < Event; end
62-
6359
def update(user_id:, tenant_id:, id:,
6460
first_name:, last_name:, email:)
6561
contact = nil
@@ -74,7 +70,7 @@ def update(user_id:, tenant_id:, id:,
7470
last_name: last_name,
7571
email: email)
7672

77-
event = UpdatedEvent
73+
event = Models::Contact::UpdatedEvent
7874
.create!(
7975
user_id: user_id,
8076
tenant_id: tenant_id,
@@ -90,8 +86,6 @@ def update(user_id:, tenant_id:, id:,
9086
{ id: contact.id, events: [{ id: event.id, type: event.type }] }
9187
end
9288

93-
class DeletedEvent < Event; end
94-
9589
def delete(user_id:, tenant_id:, id:, time: ::Time)
9690
contact = nil
9791
event = nil
@@ -102,7 +96,7 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)
10296

10397
contact.update!(deleted_at: time.now.utc)
10498

105-
event = DeletedEvent
99+
event = Models::Contact::DeletedEvent
106100
.create!(
107101
user_id: user_id,
108102
tenant_id: tenant_id,

app/domains/accountify/invoice.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ module Status
99
VOIDED = 'voided'
1010
end
1111

12-
class DraftedEvent < Event; end
13-
1412
def draft(user_id:, tenant_id:,
1513
organisation_id:, contact_id:,
1614
currency_code:, due_date:, line_items:,
@@ -51,7 +49,7 @@ def draft(user_id:, tenant_id:,
5149
quantity: line_item[:quantity])
5250
end
5351

54-
event = DraftedEvent.create!(
52+
event = Models::Invoice::DraftedEvent.create!(
5553
user_id: user_id,
5654
tenant_id: tenant_id,
5755
created_at: current_utc_time,
@@ -118,8 +116,6 @@ def find_by_id(user_id:, tenant_id:, id:)
118116
}
119117
end
120118

121-
class UpdatedEvent < Event; end
122-
123119
def update(user_id:, tenant_id:, id:,
124120
organisation_id:, contact_id:,
125121
due_date:, line_items:,
@@ -162,7 +158,7 @@ def update(user_id:, tenant_id:, id:,
162158
quantity: line_item[:quantity])
163159
end
164160

165-
event = UpdatedEvent.create!(
161+
event = Models::Invoice::UpdatedEvent.create!(
166162
user_id: user_id,
167163
tenant_id: tenant_id,
168164
created_at: current_utc_time,
@@ -191,8 +187,6 @@ def update(user_id:, tenant_id:, id:,
191187
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
192188
end
193189

194-
class DeletedEvent < Event; end
195-
196190
def delete(user_id:, tenant_id:, id:, time: ::Time)
197191
invoice = nil
198192
event = nil
@@ -204,7 +198,7 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)
204198

205199
invoice.update!(updated_at: current_utc_time, deleted_at: current_utc_time)
206200

207-
event = DeletedEvent.create!(
201+
event = Models::Invoice::DeletedEvent.create!(
208202
user_id: user_id,
209203
tenant_id: tenant_id,
210204
created_at: current_utc_time,
@@ -219,8 +213,6 @@ def delete(user_id:, tenant_id:, id:, time: ::Time)
219213
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
220214
end
221215

222-
class IssuedEvent < Event; end
223-
224216
def issue(user_id:, tenant_id:, id:, time: ::Time)
225217
invoice = nil
226218
event = nil
@@ -235,7 +227,7 @@ def issue(user_id:, tenant_id:, id:, time: ::Time)
235227
issued_at: current_utc_time,
236228
updated_at: current_utc_time)
237229

238-
event = IssuedEvent.create!(
230+
event = Models::Invoice::IssuedEvent.create!(
239231
user_id: user_id,
240232
tenant_id: tenant_id,
241233
created_at: current_utc_time,
@@ -251,8 +243,6 @@ def issue(user_id:, tenant_id:, id:, time: ::Time)
251243
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
252244
end
253245

254-
class PaidEvent < Event; end
255-
256246
def paid(user_id:, tenant_id:, id:, time: ::Time)
257247
invoice = nil
258248
event = nil
@@ -268,7 +258,7 @@ def paid(user_id:, tenant_id:, id:, time: ::Time)
268258

269259
invoice.update!(status: Invoice::Status::PAID, paid_at: Time.current)
270260

271-
event = PaidEvent.create!(
261+
event = Models::Invoice::PaidEvent.create!(
272262
user_id: user_id,
273263
tenant_id: tenant_id,
274264
eventable: invoice,
@@ -284,8 +274,6 @@ def paid(user_id:, tenant_id:, id:, time: ::Time)
284274
{ id: invoice.id, events: [{ id: event.id, type: event.type }] }
285275
end
286276

287-
class VoidedEvent < Event; end
288-
289277
def void(user_id:, tenant_id:, id:, time: ::Time)
290278
invoice = nil
291279
event = nil
@@ -295,7 +283,7 @@ def void(user_id:, tenant_id:, id:, time: ::Time)
295283

296284
invoice.update!(status: Invoice::Status::VOIDED)
297285

298-
event = VoidedEvent.create!(
286+
event = Models::Invoice::VoidedEvent.create!(
299287
user_id: user_id,
300288
tenant_id: tenant_id,
301289
eventable: invoice,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Contact
4+
class CreatedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Contact
4+
class DeletedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Contact
4+
class UpdatedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Accountify
2+
module Models
3+
class Event < ::Models::Event
4+
5+
end
6+
end
7+
end

app/domains/accountify/models/invoice.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class Invoice < ActiveRecord::Base
77

88
has_many :line_items, -> { order(id: :asc) }
99

10-
has_many :events, -> { order(created_at: :asc) },
11-
as: :eventable
10+
has_many :events, -> { order(created_at: :asc) }, as: :eventable
1211

1312
has_one :invoice_status_summary
1413

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Invoice
4+
class DeletedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Invoice
4+
class DraftedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Accountify
2+
module Models
3+
class Invoice
4+
class IssuedEvent < Models::Event
5+
6+
end
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)