Commit 922e6cf0 authored by James Lopez's avatar James Lopez

refactored code a little based on feedback

parent a05649b1
...@@ -865,7 +865,7 @@ Parameters: ...@@ -865,7 +865,7 @@ Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `from` | string | no | Date time string in the format YEAR-MONTH-DAY, e.g. `2016-03-11`. Defaults to 6 months ago. | | `from` | string | no | Date string in the format YEAR-MONTH-DAY, e.g. `2016-03-11`. Defaults to 6 months ago. |
```bash ```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/user/activities curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/user/activities
......
...@@ -35,7 +35,7 @@ module API ...@@ -35,7 +35,7 @@ module API
optional :assignee_id, type: Integer, desc: 'The ID of a user to assign issue' optional :assignee_id, type: Integer, desc: 'The ID of a user to assign issue'
optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue' optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue'
optional :labels, type: String, desc: 'Comma-separated list of label names' optional :labels, type: String, desc: 'Comma-separated list of label names'
optional :due_date, type: String, desc: 'Date time string in the format YEAR-MONTH-DAY' optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential' optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
optional :state_event, type: String, values: %w[open close], optional :state_event, type: String, values: %w[open close],
desc: 'State of the issue' desc: 'State of the issue'
......
...@@ -459,7 +459,7 @@ module API ...@@ -459,7 +459,7 @@ module API
desc 'Get a list of user activities' desc 'Get a list of user activities'
params do params do
optional :from, type: String, desc: 'Date time string in the format YEAR-MONTH-DAY' optional :from, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
use :pagination use :pagination
end end
get ":activities" do get ":activities" do
......
...@@ -8,8 +8,8 @@ module Gitlab ...@@ -8,8 +8,8 @@ module Gitlab
@options = { default_per_page: DEFAULT_PER_PAGE, @options = { default_per_page: DEFAULT_PER_PAGE,
max_per_page: MAX_PER_PAGE }.merge(options) max_per_page: MAX_PER_PAGE }.merge(options)
@page = sanitize_page(page)
@per_page = sanitize_per_page(per_page) @per_page = sanitize_per_page(per_page)
@page = sanitize_page(page)
end end
def total_count def total_count
...@@ -53,13 +53,13 @@ module Gitlab ...@@ -53,13 +53,13 @@ module Gitlab
def sanitize_per_page(per_page) def sanitize_per_page(per_page)
return @options[:default_per_page] unless per_page && per_page > 0 return @options[:default_per_page] unless per_page && per_page > 0
per_page > @options[:max_per_page] ? @options[:max_per_page] : per_page [@options[:max_per_page], per_page].min
end end
def sanitize_page(page) def sanitize_page(page)
return 1 unless page && page > 1 return 1 unless page && page > 1
page > total_count ? total_count : page [total_pages, page].min
end end
end end
end end
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
end end
def last_activity_at def last_activity_at
@lat_activity_at ||= Time.at(@time).to_s(:db) @last_activity_at ||= Time.at(@time).to_s(:db)
end end
end end
end end
......
...@@ -4,7 +4,6 @@ module Gitlab ...@@ -4,7 +4,6 @@ module Gitlab
include Gitlab::PaginationUtil include Gitlab::PaginationUtil
KEY = 'user/activities' KEY = 'user/activities'
DEFAULT_FROM = 6.months.ago.to_i
def self.record(user) def self.record(user)
Gitlab::Redis.with do |redis| Gitlab::Redis.with do |redis|
...@@ -28,7 +27,7 @@ module Gitlab ...@@ -28,7 +27,7 @@ module Gitlab
def sanitize_date(date) def sanitize_date(date)
Time.strptime(date, "%Y-%m-%d").to_i Time.strptime(date, "%Y-%m-%d").to_i
rescue TypeError, ArgumentError rescue TypeError, ArgumentError
DEFAULT_FROM default_from
end end
def pagination_delegate def pagination_delegate
...@@ -52,6 +51,10 @@ module Gitlab ...@@ -52,6 +51,10 @@ module Gitlab
def limit def limit
[pagination_delegate.offset, pagination_delegate.limit_value] [pagination_delegate.offset, pagination_delegate.limit_value]
end end
def default_from
6.months.ago.to_i
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment