Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
4cbcb212
Commit
4cbcb212
authored
2 years ago
by
tmn21
Browse files
Options
Downloads
Patches
Plain Diff
ISSUE
#38
: CREATE streak route
parent
5b1d8010
No related branches found
No related tags found
No related merge requests found
Pipeline
#34088
failed
2 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/user.rb
+23
-0
23 additions, 0 deletions
app/models/user.rb
app/models/view.rb
+1
-0
1 addition, 0 deletions
app/models/view.rb
with
24 additions
and
0 deletions
app/models/user.rb
+
23
−
0
View file @
4cbcb212
...
...
@@ -79,6 +79,8 @@
# level :integer default("1")
# points :integer default("0")
# last_sign_in_day :datetime
# last_action_at :date
# streak :integer default("0")
class
User
<
ApplicationRecord
include
Followable
...
...
@@ -385,6 +387,27 @@ class User < ApplicationRecord
end
end
def
update_streak
()
if
self
.
last_action_at
==
Date
.
today
return
end
# increase streak count
if
self
.
last_action_at
==
Date
.
yesterday
self
.
update
(
last_action_at:
Date
.
today
)
self
.
update
(
streak:
streak
+
1
)
return
end
# restart streak count
if
Date
.
today
-
self
.
last_action_at
>=
2
self
.
update
(
last_action_at:
Date
.
today
)
self
.
update
(
streak:
1
)
end
end
def
complete_action
(
action
,
quantity
=
1
)
return
false
,
{
"error"
:
"action not found"
}
if
action
.
blank?
...
...
This diff is collapsed.
Click to expand it.
app/models/view.rb
+
1
−
0
View file @
4cbcb212
...
...
@@ -62,6 +62,7 @@ class View < ApplicationRecord
if
!
user
.
nil?
if
viewable_type
==
"LearningObject"
user
.
complete_action
(
Action
.
find_by_name
(
"Visualizar um Recurso"
))
user
.
update_streak
()
viewable
.
subjects
.
each
do
|
subject
|
user
.
complete_action
(
Action
.
find_by_name
(
"Visualizar um Recurso de
#{
subject
.
name
}
"
))
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment