cats_core 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/notifications_controller.rb +26 -4
- data/app/controllers/cats/core/roles_controller.rb +18 -0
- data/app/controllers/cats/core/users_controller.rb +23 -0
- data/app/models/cats/core/notification.rb +5 -1
- data/app/models/cats/core/role.rb +1 -0
- data/app/models/cats/core/user.rb +12 -0
- data/config/routes.rb +18 -1
- data/lib/cats/core/version.rb +1 -1
- data/lib/cats_core.rb +1 -0
- data/spec/factories/cats/core/notifications.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45dbf26292f9ebc98fb50e4195e44773184d3f460c0d5aadb3c45afcffffa752
|
4
|
+
data.tar.gz: 7cab2b31272ec765c42d8cd8724f1d8f3daff1481fd82057edf08ed40ce389b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6017835a41ce450bb778aea397234083ac257ec74b1f995a5087811dfae0db693172468ceed14c11ef8433dd26eca298436256ff8fc876a7482e8ce2610d46bb
|
7
|
+
data.tar.gz: 87ff5af9c3533a23b57ede84a3547818b7f54e51cfb629dbd8f3c26c6de73900f974c2ecb0bc38c999b01bdd29a0b7260daf4ec03510407fae8511d85ae372d3
|
@@ -1,14 +1,36 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class NotificationsController < ApplicationController
|
4
|
+
before_action :set_notification, only: %i[mark_as_read mark_as_unread]
|
4
5
|
def index
|
5
|
-
data =
|
6
|
-
render json: data
|
6
|
+
data = Notification.messages(current_user.notifications.newest_first)
|
7
|
+
render json: { success: true, data: data }
|
8
|
+
end
|
9
|
+
|
10
|
+
def read
|
11
|
+
data = Notification.messages(current_user.notifications.read.newest_first)
|
12
|
+
render json: { success: true, data: data }
|
7
13
|
end
|
8
14
|
|
9
15
|
def unread
|
10
|
-
data =
|
11
|
-
render json: data
|
16
|
+
data = Notification.messages(current_user.notifications.unread.newest_first)
|
17
|
+
render json: { success: true, data: data }
|
18
|
+
end
|
19
|
+
|
20
|
+
def mark_as_read
|
21
|
+
@notification.mark_as_read!
|
22
|
+
render json: { success: true, data: @notification.message }
|
23
|
+
end
|
24
|
+
|
25
|
+
def mark_as_unread
|
26
|
+
@notification.mark_as_unread!
|
27
|
+
render json: { success: true, data: @notification.message }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def set_notification
|
33
|
+
@notification = Notification.find(params[:id])
|
12
34
|
end
|
13
35
|
end
|
14
36
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class RolesController < ApplicationController
|
4
|
+
before_action :set_role, only: [:users]
|
5
|
+
|
6
|
+
def users
|
7
|
+
data = ActiveModelSerializers::SerializableResource.new(@role.users)
|
8
|
+
render json: { success: true, data: data }
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def set_role
|
14
|
+
@role = Role.find(params[:id])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class UsersController < ApplicationController
|
4
|
+
before_action :set_user, only: %i[stores warehouses]
|
5
|
+
|
6
|
+
def stores
|
7
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.stores)
|
8
|
+
render json: { success: true, data: data }
|
9
|
+
end
|
10
|
+
|
11
|
+
def warehouses
|
12
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.warehouses)
|
13
|
+
render json: { success: true, data: data }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_user
|
19
|
+
@user = User.find(params[:id])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -6,7 +6,11 @@ module Cats
|
|
6
6
|
belongs_to :recipient, polymorphic: true
|
7
7
|
|
8
8
|
def message
|
9
|
-
to_notification.message
|
9
|
+
{ id: id, read: !read_at.nil? }.merge(to_notification.message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.messages(notifications)
|
13
|
+
notifications.map(&:message)
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -11,6 +11,18 @@ module Cats
|
|
11
11
|
validates :first_name, :last_name, :email, presence: true
|
12
12
|
validates :password, length: { minimum: 6 }
|
13
13
|
validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
14
|
+
|
15
|
+
def warehouses
|
16
|
+
return unless details.key?('warehouses')
|
17
|
+
|
18
|
+
Cats::Core::Location.where(id: details['warehouses'], location_type: Cats::Core::Location::WAREHOUSE)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stores
|
22
|
+
return unless details.key?('stores')
|
23
|
+
|
24
|
+
Cats::Core::Store.where(id: details['stores'])
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
Cats::Core::Engine.routes.draw do
|
2
2
|
get '/notifications/unread', controller: :notifications, action: :unread
|
3
|
+
get '/notifications/read', controller: :notifications, action: :read
|
3
4
|
|
4
|
-
resources :notifications, only: [:index]
|
5
|
+
resources :notifications, only: [:index] do
|
6
|
+
member do
|
7
|
+
post 'mark_as_read', controller: :notifications, action: :mark_as_read
|
8
|
+
post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
|
9
|
+
end
|
10
|
+
end
|
11
|
+
resources :roles do
|
12
|
+
member do
|
13
|
+
get 'users', controller: :roles, action: :users
|
14
|
+
end
|
15
|
+
end
|
16
|
+
resources :users do
|
17
|
+
member do
|
18
|
+
get 'stores', controller: :users, action: :stores
|
19
|
+
get 'warehouses', controller: :users, action: :warehouses
|
20
|
+
end
|
21
|
+
end
|
5
22
|
end
|
data/lib/cats/core/version.rb
CHANGED
data/lib/cats_core.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_model_serializers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: ancestry
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,6 +218,8 @@ files:
|
|
204
218
|
- Rakefile
|
205
219
|
- app/controllers/cats/core/application_controller.rb
|
206
220
|
- app/controllers/cats/core/notifications_controller.rb
|
221
|
+
- app/controllers/cats/core/roles_controller.rb
|
222
|
+
- app/controllers/cats/core/users_controller.rb
|
207
223
|
- app/jobs/cats/core/application_job.rb
|
208
224
|
- app/models/cats/core/application_module.rb
|
209
225
|
- app/models/cats/core/application_record.rb
|