recent_view_controller.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = recent_viewed.map(&:attributes_with_association_names)
  18. render json: list, status: :ok
  19. return
  20. end
  21. if response_full?
  22. assets = {}
  23. item_ids = []
  24. recent_viewed.each do |item|
  25. item_ids.push item.id
  26. assets = item.assets(assets)
  27. end
  28. render json: {
  29. record_ids: item_ids,
  30. assets: assets,
  31. }, status: :ok
  32. return
  33. end
  34. all = recent_viewed.map(&:attributes_with_association_ids)
  35. render json: all, status: :ok
  36. end
  37. =begin
  38. Resource:
  39. POST /api/v1/recent_viewed
  40. Payload:
  41. {
  42. "object": "Ticket",
  43. "o_id": 123,
  44. }
  45. Response:
  46. {}
  47. Test:
  48. curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"object": "Ticket","o_id": 123}'
  49. =end
  50. def create
  51. RecentView.log(params[:object], params[:o_id], current_user)
  52. # return result
  53. render json: { message: 'ok' }
  54. end
  55. end