recent_view_controller.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class RecentViewController < ApplicationController
  3. prepend_before_action :authentication_check
  4. =begin
  5. Resource:
  6. GET /api/v1/recent_viewed
  7. Response:
  8. {
  9. ...
  10. }
  11. Test:
  12. curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
  13. =end
  14. def index
  15. recent_viewed = RecentView.list(current_user, 10)
  16. if response_expand?
  17. list = []
  18. recent_viewed.each do |item|
  19. list.push item.attributes_with_association_names
  20. end
  21. render json: list, status: :ok
  22. return
  23. end
  24. if response_full?
  25. assets = {}
  26. item_ids = []
  27. recent_viewed.each do |item|
  28. item_ids.push item.id
  29. assets = item.assets(assets)
  30. end
  31. render json: {
  32. record_ids: item_ids,
  33. assets: assets,
  34. }, status: :ok
  35. return
  36. end
  37. all = []
  38. recent_viewed.each do |item|
  39. all.push item.attributes_with_association_ids
  40. end
  41. render json: all, status: :ok
  42. end
  43. =begin
  44. Resource:
  45. POST /api/v1/recent_viewed
  46. Payload:
  47. {
  48. "object": "Ticket",
  49. "o_id": 123,
  50. }
  51. Response:
  52. {}
  53. Test:
  54. curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}'
  55. =end
  56. def create
  57. RecentView.log(params[:object], params[:o_id], current_user)
  58. # return result
  59. render json: { message: 'ok' }
  60. end
  61. end