api_engine_base 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api_engine_base/inbox/message_blast_controller.rb +89 -0
- data/app/controllers/api_engine_base/inbox/message_controller.rb +79 -0
- data/app/models/message.rb +30 -0
- data/app/models/message_blast.rb +27 -0
- data/app/models/user.rb +2 -0
- data/app/services/api_engine_base/inbox_service/blast/delete.rb +23 -0
- data/app/services/api_engine_base/inbox_service/blast/metadata.rb +26 -0
- data/app/services/api_engine_base/inbox_service/blast/new_user_blaster.rb +24 -0
- data/app/services/api_engine_base/inbox_service/blast/retrieve.rb +30 -0
- data/app/services/api_engine_base/inbox_service/blast/upsert.rb +67 -0
- data/app/services/api_engine_base/inbox_service/message/metadata.rb +35 -0
- data/app/services/api_engine_base/inbox_service/message/modify.rb +44 -0
- data/app/services/api_engine_base/inbox_service/message/retrieve.rb +36 -0
- data/app/services/api_engine_base/inbox_service/message/send.rb +33 -0
- data/app/services/api_engine_base/login_strategy/plain_text/create.rb +1 -0
- data/config/routes.rb +21 -0
- data/db/migrate/20250223023306_create_api_engine_base_messages.rb +12 -0
- data/db/migrate/20250223023313_create_api_engine_base_message_blasts.rb +14 -0
- data/lib/api_engine_base/authorization/default.yml +8 -0
- data/lib/api_engine_base/schema/inbox/blast_request.rb +15 -0
- data/lib/api_engine_base/schema/inbox/blast_response.rb +16 -0
- data/lib/api_engine_base/schema/inbox/message_blast_entity.rb +16 -0
- data/lib/api_engine_base/schema/inbox/message_blast_metadata.rb +16 -0
- data/lib/api_engine_base/schema/inbox/message_entity.rb +14 -0
- data/lib/api_engine_base/schema/inbox/metadata.rb +18 -0
- data/lib/api_engine_base/schema/inbox/modified.rb +13 -0
- data/lib/api_engine_base/schema.rb +8 -0
- data/lib/api_engine_base/version.rb +1 -1
- metadata +24 -3
- data/app/controllers/concerns/api_engine_base/schematizable.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d10e7cc64ff7f99aa912731ce7200ebfbff18e90b0cc05b948a8f6034d15e54f
|
4
|
+
data.tar.gz: 07baec4ba6dc487ab145d68e87e489181153550b3e22f1db594d56e1fcc86e3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d925277dac2e33eff40c8f3e4669f4ea162051ca6f9ec0d9d66791ed9e937384262fd983a04d4895c7891d1ec763d41f092a3242c4e685f9237f6b8af463ba
|
7
|
+
data.tar.gz: 7e7bd57ff6c8a991fe251c6afb01d4d3a8900a002973dc8c661313fd94ceac1f81e17f7dc80ec96f175bc110f4c0ec74638c75b9eb32b4a871815dff2c20e21f
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Inbox
|
5
|
+
class MessageBlastController < ::ApiEngineBase::ApplicationController
|
6
|
+
include ApiEngineBase::SchemaHelper
|
7
|
+
|
8
|
+
before_action :authenticate_user!
|
9
|
+
before_action :authorize_user!
|
10
|
+
|
11
|
+
# GET /inbox/blast
|
12
|
+
def metadata
|
13
|
+
result = ApiEngineBase::InboxService::Blast::Metadata.(id: params[:id].to_i)
|
14
|
+
schema_succesful!(status: 200, schema: result.metadata)
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /inbox/blast/:id
|
18
|
+
def blast
|
19
|
+
result = ApiEngineBase::InboxService::Blast::Retrieve.(id: params[:id].to_i)
|
20
|
+
if result.success?
|
21
|
+
schema = result.message_blast
|
22
|
+
status = 200
|
23
|
+
schema_succesful!(status:, schema:)
|
24
|
+
else
|
25
|
+
invalid_arguments!(
|
26
|
+
status: 400,
|
27
|
+
message: result.msg,
|
28
|
+
argument_object: result.invalid_argument_hash,
|
29
|
+
schema: ApiEngineBase::Schema::PlainText::LoginRequest,
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# POST /inbox/blast
|
35
|
+
def create
|
36
|
+
upsert
|
37
|
+
end
|
38
|
+
|
39
|
+
# PATCH /inbox/blast/:id
|
40
|
+
def modify
|
41
|
+
upsert(id: params[:id].to_i)
|
42
|
+
end
|
43
|
+
|
44
|
+
# DELETE /inbox/blast/:id
|
45
|
+
def delete
|
46
|
+
result = ApiEngineBase::InboxService::Blast::Delete.(id: params[:id].to_i)
|
47
|
+
if result.success?
|
48
|
+
schema = result.message
|
49
|
+
status = 200
|
50
|
+
render :json, { id: params[:id], msg: "Message Blast message deleted" }
|
51
|
+
else
|
52
|
+
invalid_arguments!(
|
53
|
+
status: 400,
|
54
|
+
message: result.msg,
|
55
|
+
argument_object: result.invalid_argument_hash,
|
56
|
+
schema: ApiEngineBase::Schema::PlainText::LoginRequest,
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def upsert(id: nil)
|
64
|
+
upsert_params = {
|
65
|
+
user: current_user,
|
66
|
+
existing_users: safe_boolean(value: params[:existing_users]),
|
67
|
+
new_users: safe_boolean(value: params[:new_users]),
|
68
|
+
text: params[:text],
|
69
|
+
title: params[:title],
|
70
|
+
id:,
|
71
|
+
}.compact
|
72
|
+
result = ApiEngineBase::InboxService::Blast::Upsert.(**upsert_params)
|
73
|
+
|
74
|
+
if result.success?
|
75
|
+
schema = result.blast
|
76
|
+
status = 200
|
77
|
+
schema_succesful!(status:, schema:)
|
78
|
+
else
|
79
|
+
invalid_arguments!(
|
80
|
+
status: 400,
|
81
|
+
message: result.msg,
|
82
|
+
argument_object: result.invalid_argument_hash,
|
83
|
+
schema: ApiEngineBase::Schema::Inbox::BlastRequest
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Inbox
|
5
|
+
class MessageController < ::ApiEngineBase::ApplicationController
|
6
|
+
include ApiEngineBase::SchemaHelper
|
7
|
+
|
8
|
+
before_action :authenticate_user!
|
9
|
+
|
10
|
+
# GET: /inbox/messages
|
11
|
+
def metadata
|
12
|
+
result = ApiEngineBase::InboxService::Message::Metadata.(user: current_user)
|
13
|
+
if result.success?
|
14
|
+
schema = result.metadata
|
15
|
+
status = 200
|
16
|
+
schema_succesful!(status:, schema:)
|
17
|
+
else
|
18
|
+
invalid_arguments!(
|
19
|
+
status: 400,
|
20
|
+
message: result.msg,
|
21
|
+
argument_object: result.invalid_argument_hash,
|
22
|
+
schema: ApiEngineBase::Schema::PlainText::LoginRequest
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET: /inbox/messages/:id
|
28
|
+
def message
|
29
|
+
result = ApiEngineBase::InboxService::Message::Retrieve.(user: current_user, id: params[:id].to_i)
|
30
|
+
if result.success?
|
31
|
+
schema = result.message
|
32
|
+
status = 200
|
33
|
+
schema_succesful!(status:, schema:)
|
34
|
+
else
|
35
|
+
invalid_arguments!(
|
36
|
+
status: 400,
|
37
|
+
message: result.msg,
|
38
|
+
argument_object: result.invalid_argument_hash,
|
39
|
+
schema: ApiEngineBase::Schema::PlainText::LoginRequest
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# POST: /inbox/messages/ack
|
45
|
+
# Body { ids: [<list of ids to ack>] }
|
46
|
+
def ack
|
47
|
+
modify(type: ApiEngineBase::InboxService::Message::Modify::VIEWED)
|
48
|
+
end
|
49
|
+
|
50
|
+
# POST: /inbox/messages/delete
|
51
|
+
# Body { ids: [<list of ids to delete>] }
|
52
|
+
def delete
|
53
|
+
modify(type: ApiEngineBase::InboxService::Message::Modify::DELETE)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def modify(type:)
|
59
|
+
result = ApiEngineBase::InboxService::Message::Modify.(
|
60
|
+
user: current_user,
|
61
|
+
ids: params[:ids],
|
62
|
+
type:,
|
63
|
+
)
|
64
|
+
if result.success?
|
65
|
+
schema = result.modified
|
66
|
+
status = 200
|
67
|
+
schema_succesful!(status:, schema:)
|
68
|
+
else
|
69
|
+
invalid_arguments!(
|
70
|
+
status: 400,
|
71
|
+
message: result.msg,
|
72
|
+
argument_object: result.invalid_argument_hash,
|
73
|
+
schema: ApiEngineBase::Schema::PlainText::LoginRequest
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: messages
|
6
|
+
#
|
7
|
+
# id :bigint not null, primary key
|
8
|
+
# pushed :boolean default(FALSE)
|
9
|
+
# text :text(65535)
|
10
|
+
# title :string(255)
|
11
|
+
# viewed :boolean default(FALSE)
|
12
|
+
# created_at :datetime not null
|
13
|
+
# updated_at :datetime not null
|
14
|
+
# message_blast_id :bigint
|
15
|
+
# user_id :bigint not null
|
16
|
+
#
|
17
|
+
# Indexes
|
18
|
+
#
|
19
|
+
# index_messages_on_message_blast_id (message_blast_id)
|
20
|
+
# index_messages_on_user_id (user_id)
|
21
|
+
#
|
22
|
+
# Foreign Keys
|
23
|
+
#
|
24
|
+
# fk_rails_... (message_blast_id => message_blasts.id)
|
25
|
+
# fk_rails_... (user_id => users.id)
|
26
|
+
#
|
27
|
+
class Message < ApplicationRecord
|
28
|
+
belongs_to :user
|
29
|
+
belongs_to :message_blast, optional: true
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: message_blasts
|
6
|
+
#
|
7
|
+
# id :bigint not null, primary key
|
8
|
+
# existing_users :boolean default(FALSE)
|
9
|
+
# new_users :boolean default(FALSE)
|
10
|
+
# text :text(65535)
|
11
|
+
# title :string(255)
|
12
|
+
# created_at :datetime not null
|
13
|
+
# updated_at :datetime not null
|
14
|
+
# user_id :bigint not null
|
15
|
+
#
|
16
|
+
# Indexes
|
17
|
+
#
|
18
|
+
# index_message_blasts_on_user_id (user_id)
|
19
|
+
#
|
20
|
+
# Foreign Keys
|
21
|
+
#
|
22
|
+
# fk_rails_... (user_id => users.id)
|
23
|
+
#
|
24
|
+
class MessageBlast < ApplicationRecord
|
25
|
+
has_many :messages
|
26
|
+
belongs_to :user
|
27
|
+
end
|
data/app/models/user.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Blast
|
6
|
+
class Delete < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :id, is_a: Integer, required: true
|
10
|
+
|
11
|
+
def call
|
12
|
+
message_blast = ::MessageBlast.where(id:).first
|
13
|
+
|
14
|
+
if message_blast.nil?
|
15
|
+
inline_argument_failure!(errors: { id: "MessageBlast ID not found" })
|
16
|
+
end
|
17
|
+
|
18
|
+
message_blast.destroy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Blast
|
6
|
+
class Metadata < ApiEngineBase::ServiceBase
|
7
|
+
def call
|
8
|
+
entities = ::MessageBlast.all.select(:id, :title, :existing_users, :new_users).map do |mb|
|
9
|
+
ApiEngineBase::Schema::Inbox::MessageBlastEntity.new(
|
10
|
+
title: mb.title,
|
11
|
+
id: mb.id,
|
12
|
+
existing_users: mb.existing_users,
|
13
|
+
new_users: mb.new_users,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
context.metadata = ApiEngineBase::Schema::Inbox::MessageBlastMetadata.new(
|
19
|
+
entities: entities,
|
20
|
+
count: entities.length,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Blast
|
6
|
+
class NewUserBlaster < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :user, is_a: User, required: true
|
10
|
+
|
11
|
+
def call
|
12
|
+
::MessageBlast.where(new_users: true).each do |message_blast|
|
13
|
+
InboxService::Message::Send.(
|
14
|
+
user:,
|
15
|
+
text: message_blast.text,
|
16
|
+
title: message_blast.title,
|
17
|
+
message_blast:,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Blast
|
6
|
+
class Retrieve < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :id, is_a: Integer, required: true
|
10
|
+
|
11
|
+
def call
|
12
|
+
message_blast = ::MessageBlast.where(id:).first
|
13
|
+
|
14
|
+
if message_blast.nil?
|
15
|
+
inline_argument_failure!(errors: { id: "MessageBlast ID not found" })
|
16
|
+
end
|
17
|
+
|
18
|
+
context.message_blast = ApiEngineBase::Schema::Inbox::MessageBlastEntity.new(
|
19
|
+
created_by: ApiEngineBase::Schema::User.convert_user_object(user: message_blast.user),
|
20
|
+
title: message_blast.title,
|
21
|
+
text: message_blast.text,
|
22
|
+
id: message_blast.id,
|
23
|
+
existing_users: message_blast.existing_users,
|
24
|
+
new_users: message_blast.new_users,
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Blast
|
6
|
+
class Upsert < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :user, is_a: User, required: true
|
10
|
+
validate :existing_users, is_one: [true, false], required: true
|
11
|
+
validate :new_users, is_one: [true, false], required: true
|
12
|
+
validate :text, is_a: String, required: true
|
13
|
+
validate :title, is_a: String, required: true
|
14
|
+
validate :id, is_a: Integer, required: false
|
15
|
+
|
16
|
+
def call
|
17
|
+
ar = record
|
18
|
+
|
19
|
+
ar.existing_users = existing_users
|
20
|
+
ar.new_users = new_users
|
21
|
+
ar.text = text
|
22
|
+
ar.title = title
|
23
|
+
ar.user = user
|
24
|
+
|
25
|
+
# Probably should wrap this in a transaction block
|
26
|
+
ar.save!
|
27
|
+
blast_messages!(message_blast: ar)
|
28
|
+
|
29
|
+
context.message_blast = ar
|
30
|
+
context.blast = ApiEngineBase::Schema::Inbox::BlastResponse.new(
|
31
|
+
existing_users:,
|
32
|
+
new_users:,
|
33
|
+
text:,
|
34
|
+
title:,
|
35
|
+
id: ar.id,
|
36
|
+
created_by: ApiEngineBase::Schema::User.convert_user_object(user:)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def blast_messages!(message_blast:)
|
41
|
+
# Only blast messages to existing users that are brand new
|
42
|
+
return if @existing_record
|
43
|
+
return unless existing_users
|
44
|
+
|
45
|
+
User.all.each do |u|
|
46
|
+
InboxService::Message::Send.(
|
47
|
+
user: u,
|
48
|
+
text: text,
|
49
|
+
title: title,
|
50
|
+
message_blast: message_blast,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def record
|
56
|
+
return MessageBlast.new if id.nil?
|
57
|
+
|
58
|
+
record = MessageBlast.where(id:).first
|
59
|
+
inline_argument_failure!(errors: { id: "Message Blast ID does not exist" }) if record.nil?
|
60
|
+
|
61
|
+
@existing_record = true
|
62
|
+
record
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Message
|
6
|
+
class Metadata < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :user, is_a: User, required: true
|
10
|
+
|
11
|
+
def call
|
12
|
+
entities = ::Message.where(user:).select(:id, :title, :viewed).map do |message|
|
13
|
+
ApiEngineBase::Schema::Inbox::MessageEntity.new(
|
14
|
+
title: message.title,
|
15
|
+
id: message.id,
|
16
|
+
viewed: message.viewed,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
params = {
|
21
|
+
entities: entities.nil? ? nil : entities,
|
22
|
+
count: entities.length,
|
23
|
+
}
|
24
|
+
|
25
|
+
context.metadata = ApiEngineBase::Schema::Inbox::Metadata.new(**params.compact)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Message
|
6
|
+
class Modify < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
IS_ONE = [
|
10
|
+
VIEWED = :viewed,
|
11
|
+
DELETE = :delete,
|
12
|
+
]
|
13
|
+
validate :user, is_a: User, required: true
|
14
|
+
validate :ids, is_a: Array, required: true
|
15
|
+
validate :type, is_one: IS_ONE, required: true
|
16
|
+
|
17
|
+
def call
|
18
|
+
messages = ::Message.where(user:, id: ids)
|
19
|
+
if messages.empty?
|
20
|
+
inline_argument_failure!(errors: { ids: "No ID's found for user" })
|
21
|
+
end
|
22
|
+
|
23
|
+
case type
|
24
|
+
when VIEWED
|
25
|
+
modified_ids = messages.update(viewed: true).pluck(:id)
|
26
|
+
when DELETE
|
27
|
+
modified_ids = messages.destroy_all.pluck(:id)
|
28
|
+
end
|
29
|
+
|
30
|
+
context.modified = ApiEngineBase::Schema::Inbox::Modified.new(
|
31
|
+
ids: modified_ids,
|
32
|
+
type:,
|
33
|
+
count: modified_ids.length,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Message
|
6
|
+
class Retrieve < ApiEngineBase::ServiceBase
|
7
|
+
on_argument_validation :fail_early
|
8
|
+
|
9
|
+
validate :user, is_a: User, required: true
|
10
|
+
validate :id, is_a: Integer, required: true
|
11
|
+
|
12
|
+
def call
|
13
|
+
message = ::Message.where(user:, id:).first
|
14
|
+
|
15
|
+
if message.nil?
|
16
|
+
inline_argument_failure!(errors: { id: "Message ID not found for user" })
|
17
|
+
end
|
18
|
+
|
19
|
+
message.update!(viewed: true)
|
20
|
+
|
21
|
+
context.message = ApiEngineBase::Schema::Inbox::MessageEntity.new(
|
22
|
+
title: message.title,
|
23
|
+
id: message.id,
|
24
|
+
text: message.text,
|
25
|
+
viewed: message.viewed,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module InboxService
|
5
|
+
module Message
|
6
|
+
class Send < ApiEngineBase::ServiceBase
|
7
|
+
validate :user, is_a: User, required: true
|
8
|
+
validate :text, is_a: String, required: true
|
9
|
+
validate :title, is_a: String, required: true
|
10
|
+
validate :message_blast, is_a: ::MessageBlast, required: false
|
11
|
+
validate :pushed, is_one: [true, false], default: false
|
12
|
+
|
13
|
+
def call
|
14
|
+
message = create_message!
|
15
|
+
context.message = message
|
16
|
+
end
|
17
|
+
|
18
|
+
def push_notification!
|
19
|
+
# TODO: Push notifications
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_message!
|
23
|
+
::Message.create!(
|
24
|
+
user:,
|
25
|
+
text: ,
|
26
|
+
title: ,
|
27
|
+
message_blast:,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/config/routes.rb
CHANGED
@@ -26,6 +26,27 @@ Rails.application.routes.draw do
|
|
26
26
|
post "/modify", to: "api_engine_base/user#modify", as: :"#{append_to_ass}_user_modify_post"
|
27
27
|
end
|
28
28
|
|
29
|
+
scope "inbox" do
|
30
|
+
scope "messages" do
|
31
|
+
get "/", to: "api_engine_base/inbox/message#metadata", as: :"#{append_to_ass}_inbox_metadata"
|
32
|
+
|
33
|
+
get "/:id", to: "api_engine_base/inbox/message#message", as: :"#{append_to_ass}_inbox_message"
|
34
|
+
delete "/:id", to: "api_engine_base/inbox/message#delete", as: :"#{append_to_ass}_inbox_message_del"
|
35
|
+
|
36
|
+
post "/ack", to: "api_engine_base/inbox/message#ack", as: :"#{append_to_ass}_inbox_ack"
|
37
|
+
post "/delete", to: "api_engine_base/inbox/message#delete", as: :"#{append_to_ass}_inbox_delete"
|
38
|
+
end
|
39
|
+
|
40
|
+
scope "blast" do
|
41
|
+
get "/", to: "api_engine_base/inbox/message_blast#metadata", as: :"#{append_to_ass}_blast_metadata"
|
42
|
+
post "/", to: "api_engine_base/inbox/message_blast#create", as: :"#{append_to_ass}_blast_create"
|
43
|
+
|
44
|
+
get "/:id", to: "api_engine_base/inbox/message_blast#blast", as: :"#{append_to_ass}_blast_blast"
|
45
|
+
patch "/:id", to: "api_engine_base/inbox/message_blast#modify", as: :"#{append_to_ass}_blast_modify"
|
46
|
+
delete "/:id", to: "api_engine_base/inbox/message_blast#delete", as: :"#{append_to_ass}_blast_delete"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
29
50
|
scope "admin" do
|
30
51
|
get "/", to: "api_engine_base/admin#show", as: :"#{append_to_ass}_admin_show_get"
|
31
52
|
post "/modify", to: "api_engine_base/admin#modify", as: :"#{append_to_ass}_admin_modify_post"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateApiEngineBaseMessages < ActiveRecord::Migration[7.2]
|
2
|
+
def change
|
3
|
+
create_table :messages do |t|
|
4
|
+
t.timestamps
|
5
|
+
t.references :user, null: false, foreign_key: true # Required
|
6
|
+
t.text :text
|
7
|
+
t.string :title
|
8
|
+
t.boolean :viewed, default: false
|
9
|
+
t.boolean :pushed, default: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateApiEngineBaseMessageBlasts < ActiveRecord::Migration[7.2]
|
2
|
+
def change
|
3
|
+
create_table :message_blasts do |t|
|
4
|
+
t.timestamps
|
5
|
+
t.references :user, null: false, foreign_key: true # Required
|
6
|
+
t.text :text
|
7
|
+
t.string :title
|
8
|
+
t.boolean :existing_users, default: false
|
9
|
+
t.boolean :new_users, default: false
|
10
|
+
end
|
11
|
+
|
12
|
+
add_reference :messages, :message_blast, foreign_key: true, null: true
|
13
|
+
end
|
14
|
+
end
|
@@ -9,18 +9,26 @@ groups:
|
|
9
9
|
the ability to view and update other users states.
|
10
10
|
entities:
|
11
11
|
- admin
|
12
|
+
- message-blast
|
12
13
|
admin-without-impersonation:
|
13
14
|
description: |
|
14
15
|
This group defines permissions for Admin Read and Write operations. Users with this role will have
|
15
16
|
the ability to view and update other users states. However, impersonation is not permitted with this role
|
16
17
|
entities:
|
17
18
|
- admin-without-impersonate
|
19
|
+
- message-blast
|
18
20
|
admin-read-only:
|
19
21
|
description: |
|
20
22
|
This group defines permissions for Admin Read interface only.
|
21
23
|
entities:
|
22
24
|
- read-admin
|
25
|
+
- message-blast-read-only
|
23
26
|
entities:
|
27
|
+
- name: message-blast
|
28
|
+
controller: ApiEngineBase::Inbox::MessageBlastController
|
29
|
+
- name: message-blast-read-only
|
30
|
+
controller: ApiEngineBase::Inbox::MessageBlastController
|
31
|
+
only: metadata
|
24
32
|
- name: read-admin
|
25
33
|
controller: ApiEngineBase::AdminController
|
26
34
|
only: show
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Schema
|
5
|
+
module Inbox
|
6
|
+
class BlastRequest < JsonSchematize::Generator
|
7
|
+
add_field name: :existing_users, type: JsonSchematize::Boolean
|
8
|
+
add_field name: :new_users, type: JsonSchematize::Boolean
|
9
|
+
add_field name: :title, type: String
|
10
|
+
add_field name: :text, type: String
|
11
|
+
add_field name: :id, type: Integer, required: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Schema
|
5
|
+
module Inbox
|
6
|
+
class BlastResponse < JsonSchematize::Generator
|
7
|
+
add_field name: :created_by, type: ApiEngineBase::Schema::User
|
8
|
+
add_field name: :existing_users, type: JsonSchematize::Boolean
|
9
|
+
add_field name: :new_users, type: JsonSchematize::Boolean
|
10
|
+
add_field name: :title, type: String
|
11
|
+
add_field name: :text, type: String
|
12
|
+
add_field name: :id, type: Integer, required: false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Schema
|
5
|
+
module Inbox
|
6
|
+
class MessageBlastEntity < JsonSchematize::Generator
|
7
|
+
add_field name: :created_by, type: ApiEngineBase::Schema::User, required: false # to allow metadata call to be fast
|
8
|
+
add_field name: :text, type: String, required: false # to allow metadata call to be fast
|
9
|
+
add_field name: :title, type: String
|
10
|
+
add_field name: :id, type: Integer
|
11
|
+
add_field name: :existing_users, type: JsonSchematize::Boolean
|
12
|
+
add_field name: :new_users, type: JsonSchematize::Boolean
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "api_engine_base/schema/inbox/message_blast_entity"
|
4
|
+
require "api_engine_base/schema/page"
|
5
|
+
|
6
|
+
module ApiEngineBase
|
7
|
+
module Schema
|
8
|
+
module Inbox
|
9
|
+
class MessageBlastMetadata < JsonSchematize::Generator
|
10
|
+
add_field name: :entities, array_of_types: true, type: ApiEngineBase::Schema::Inbox::MessageBlastEntity, required: false
|
11
|
+
add_field name: :count, type: Integer
|
12
|
+
add_field name: :pagination, type: ApiEngineBase::Schema::Page, required: false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Schema
|
5
|
+
module Inbox
|
6
|
+
class MessageEntity < JsonSchematize::Generator
|
7
|
+
add_field name: :title, type: String
|
8
|
+
add_field name: :id, type: Integer
|
9
|
+
add_field name: :text, type: String, required: false
|
10
|
+
add_field name: :viewed, type: JsonSchematize::Boolean
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "api_engine_base/schema/inbox/message_entity"
|
4
|
+
require "api_engine_base/schema/page"
|
5
|
+
|
6
|
+
module ApiEngineBase
|
7
|
+
module Schema
|
8
|
+
module Inbox
|
9
|
+
class Metadata < JsonSchematize::Generator
|
10
|
+
# schema_default option: :dig_type, value: :string
|
11
|
+
|
12
|
+
add_field name: :entities, array_of_types: true, type: ApiEngineBase::Schema::Inbox::MessageEntity, required: false
|
13
|
+
add_field name: :count, type: Integer
|
14
|
+
add_field name: :pagination, type: ApiEngineBase::Schema::Page, required: false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiEngineBase
|
4
|
+
module Schema
|
5
|
+
module Inbox
|
6
|
+
class Modified < JsonSchematize::Generator
|
7
|
+
add_field name: :type, type: Symbol
|
8
|
+
add_field name: :ids, type: Array
|
9
|
+
add_field name: :count, type: Integer
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -26,5 +26,13 @@ module ApiEngineBase
|
|
26
26
|
|
27
27
|
require "api_engine_base/schema/user"
|
28
28
|
require "api_engine_base/schema/page"
|
29
|
+
|
30
|
+
require "api_engine_base/schema/inbox/metadata"
|
31
|
+
require "api_engine_base/schema/inbox/message_entity"
|
32
|
+
require "api_engine_base/schema/inbox/modified"
|
33
|
+
require "api_engine_base/schema/inbox/blast_response"
|
34
|
+
require "api_engine_base/schema/inbox/blast_request"
|
35
|
+
require "api_engine_base/schema/inbox/message_blast_entity"
|
36
|
+
require "api_engine_base/schema/inbox/message_blast_metadata"
|
29
37
|
end
|
30
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_engine_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matt-taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rotp
|
@@ -122,15 +122,18 @@ files:
|
|
122
122
|
- app/controllers/api_engine_base/admin_controller.rb
|
123
123
|
- app/controllers/api_engine_base/application_controller.rb
|
124
124
|
- app/controllers/api_engine_base/auth/plain_text_controller.rb
|
125
|
+
- app/controllers/api_engine_base/inbox/message_blast_controller.rb
|
126
|
+
- app/controllers/api_engine_base/inbox/message_controller.rb
|
125
127
|
- app/controllers/api_engine_base/user_controller.rb
|
126
128
|
- app/controllers/api_engine_base/username_controller.rb
|
127
|
-
- app/controllers/concerns/api_engine_base/schematizable.rb
|
128
129
|
- app/helpers/api_engine_base/application_helper.rb
|
129
130
|
- app/helpers/api_engine_base/schema_helper.rb
|
130
131
|
- app/jobs/api_engine_base/application_job.rb
|
131
132
|
- app/mailers/api_engine_base/application_mailer.rb
|
132
133
|
- app/mailers/api_engine_base/email_verification_mailer.rb
|
133
134
|
- app/models/api_engine_base/application_record.rb
|
135
|
+
- app/models/message.rb
|
136
|
+
- app/models/message_blast.rb
|
134
137
|
- app/models/user.rb
|
135
138
|
- app/models/user_secret.rb
|
136
139
|
- app/services/api_engine_base/README.md
|
@@ -139,6 +142,15 @@ files:
|
|
139
142
|
- app/services/api_engine_base/argument_validation/class_methods.rb
|
140
143
|
- app/services/api_engine_base/argument_validation/instance_methods.rb
|
141
144
|
- app/services/api_engine_base/authorize/validate.rb
|
145
|
+
- app/services/api_engine_base/inbox_service/blast/delete.rb
|
146
|
+
- app/services/api_engine_base/inbox_service/blast/metadata.rb
|
147
|
+
- app/services/api_engine_base/inbox_service/blast/new_user_blaster.rb
|
148
|
+
- app/services/api_engine_base/inbox_service/blast/retrieve.rb
|
149
|
+
- app/services/api_engine_base/inbox_service/blast/upsert.rb
|
150
|
+
- app/services/api_engine_base/inbox_service/message/metadata.rb
|
151
|
+
- app/services/api_engine_base/inbox_service/message/modify.rb
|
152
|
+
- app/services/api_engine_base/inbox_service/message/retrieve.rb
|
153
|
+
- app/services/api_engine_base/inbox_service/message/send.rb
|
142
154
|
- app/services/api_engine_base/jwt/authenticate_user.rb
|
143
155
|
- app/services/api_engine_base/jwt/decode.rb
|
144
156
|
- app/services/api_engine_base/jwt/encode.rb
|
@@ -163,6 +175,8 @@ files:
|
|
163
175
|
- config/routes.rb
|
164
176
|
- db/migrate/20241117043720_create_api_engine_base_users.rb
|
165
177
|
- db/migrate/20241204065708_create_api_engine_base_user_secrets.rb
|
178
|
+
- db/migrate/20250223023306_create_api_engine_base_messages.rb
|
179
|
+
- db/migrate/20250223023313_create_api_engine_base_message_blasts.rb
|
166
180
|
- lib/api_engine_base.rb
|
167
181
|
- lib/api_engine_base/authorization.rb
|
168
182
|
- lib/api_engine_base/authorization/default.yml
|
@@ -190,6 +204,13 @@ files:
|
|
190
204
|
- lib/api_engine_base/schema/error/base.rb
|
191
205
|
- lib/api_engine_base/schema/error/invalid_argument.rb
|
192
206
|
- lib/api_engine_base/schema/error/invalid_argument_response.rb
|
207
|
+
- lib/api_engine_base/schema/inbox/blast_request.rb
|
208
|
+
- lib/api_engine_base/schema/inbox/blast_response.rb
|
209
|
+
- lib/api_engine_base/schema/inbox/message_blast_entity.rb
|
210
|
+
- lib/api_engine_base/schema/inbox/message_blast_metadata.rb
|
211
|
+
- lib/api_engine_base/schema/inbox/message_entity.rb
|
212
|
+
- lib/api_engine_base/schema/inbox/metadata.rb
|
213
|
+
- lib/api_engine_base/schema/inbox/modified.rb
|
193
214
|
- lib/api_engine_base/schema/page.rb
|
194
215
|
- lib/api_engine_base/schema/plain_text/create_user_request.rb
|
195
216
|
- lib/api_engine_base/schema/plain_text/create_user_response.rb
|