2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2014-08-27 13:06:09 +00:00
|
|
|
class RecentViewController < ApplicationController
|
2017-02-15 12:29:25 +00:00
|
|
|
prepend_before_action :authentication_check
|
2012-07-19 21:31:57 +00:00
|
|
|
|
2012-09-20 12:08:02 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
Resource:
|
2013-08-06 22:10:28 +00:00
|
|
|
GET /api/v1/recent_viewed
|
2012-09-20 12:08:02 +00:00
|
|
|
|
|
|
|
Response:
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
Test:
|
2014-08-27 13:06:09 +00:00
|
|
|
curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
|
2012-09-20 12:08:02 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2014-08-23 23:56:45 +00:00
|
|
|
def index
|
2018-03-20 12:16:17 +00:00
|
|
|
recent_viewed = RecentView.list(current_user, 10)
|
|
|
|
|
|
|
|
if response_expand?
|
|
|
|
list = []
|
|
|
|
recent_viewed.each do |item|
|
|
|
|
list.push item.attributes_with_association_names
|
|
|
|
end
|
|
|
|
render json: list, status: :ok
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if response_full?
|
|
|
|
assets = {}
|
|
|
|
item_ids = []
|
|
|
|
recent_viewed.each do |item|
|
|
|
|
item_ids.push item.id
|
|
|
|
assets = item.assets(assets)
|
|
|
|
end
|
|
|
|
render json: {
|
|
|
|
record_ids: item_ids,
|
2018-12-19 17:31:51 +00:00
|
|
|
assets: assets,
|
2018-03-20 12:16:17 +00:00
|
|
|
}, status: :ok
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
all = []
|
|
|
|
recent_viewed.each do |item|
|
|
|
|
all.push item.attributes_with_association_ids
|
|
|
|
end
|
|
|
|
render json: all, status: :ok
|
2012-07-19 21:31:57 +00:00
|
|
|
end
|
2012-09-20 12:08:02 +00:00
|
|
|
|
2014-08-23 23:56:45 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
Resource:
|
|
|
|
POST /api/v1/recent_viewed
|
|
|
|
|
|
|
|
Payload:
|
|
|
|
{
|
|
|
|
"object": "Ticket",
|
|
|
|
"o_id": 123,
|
|
|
|
}
|
|
|
|
|
|
|
|
Response:
|
|
|
|
{}
|
|
|
|
|
|
|
|
Test:
|
2014-08-27 13:06:09 +00:00
|
|
|
curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}'
|
2014-08-23 23:56:45 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
2017-06-16 23:02:13 +00:00
|
|
|
RecentView.log(params[:object], params[:o_id], current_user)
|
2014-08-23 23:56:45 +00:00
|
|
|
|
|
|
|
# return result
|
2015-04-27 13:42:53 +00:00
|
|
|
render json: { message: 'ok' }
|
2014-08-23 23:56:45 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|