Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 line
3.5KB

  1. #|
  2. src/web/cards.lisp
  3. Card Browser
  4. TODO Link To Inventory Item
  5. TODO This needs to be rewritten using YGOProDeck 2 still.
  6. |#
  7. (in-package #:cl-deck-builder2.web)
  8. (defroute ("/cards" :method :GET) (&key _parsed)
  9. "Card Browser Main Route. We use RENDER-RESULTS from `/inventory` URL.
  10. TODO Cards should probably have their own RENDER-RESULTS. RENDER-CARD?"
  11. (v:info :cards "GET /cards => ~a" _parsed)
  12. (with-logged-in-user
  13. (render-results :active "/cards"
  14. :class 'ygo-info
  15. :params _parsed
  16. :tpl #P"cards/index.html")))
  17. (defroute ("/cards/search" :method :POST) (&key _parsed)
  18. "Card Browser Search POST Route. We also user RENDER-RESULTS here."
  19. (v:info :cards "POST /cards/search => ~a" _parsed)
  20. (with-logged-in-user
  21. (render-results :active "/cards"
  22. :class 'ygo-info
  23. :params _parsed
  24. :tpl #P"cards/search-results.html")))
  25. (defroute ("/cards/:id/view" :method :GET) (&key id)
  26. "View Route for Card ID. We use YGO-SELECT-INFO-BY-ID to get the PASSCODE to get the YGO-SET-BY-PASSCODE."
  27. (v:info :cards "GET /cards/~d/view" id)
  28. (with-logged-in-user
  29. (handler-case
  30. (ratify:with-parsed-forms
  31. ((:integer id))
  32. (with-connection (db)
  33. (with-transaction
  34. (let* ((variants (select-variant-condition))
  35. (ygo-info (ygo-select-info-by-id id))
  36. (passcode (ygo-passcode-of ygo-info))
  37. (found (ygo-card-sets passcode)))
  38. (if found
  39. (render-with-env #P"cards/view.html"
  40. `(:ygo-card-sets ,found
  41. :variants ,variants)))))))
  42. (ratify:combined-error (e)
  43. (flash-error (format nil "/cards/~d/view.error => ~a~%" id e))))))
  44. (defroute ("/cards/by-passcode/:id" :method :GET) (&key id)
  45. "View YGO-INFO by PASSCODE ID."
  46. (alexandria:if-let ((info (find-dao 'ygo-info :passcode id)))
  47. (redirect (format nil "/cards/~d/view" (mito:object-id info)))
  48. (redirect "/cards")))
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. ;; This is bad, but could be better for other things
  51. (defroute ("/cards/:id/image" :method :GET) (&key id)
  52. "Get the card image for card ID.
  53. TODO Rewrite with templates
  54. TODO This is bad, the way that it's written right now it will take one ID, ideally, this should wrap a list of IDs to save on database bandwidth. Each request triggers a FIND-DAO."
  55. (v:debug :cards "GET /cards/~d/image" id)
  56. (with-logged-in-user
  57. (handler-case
  58. (ratify:with-parsed-forms
  59. ((:integer id))
  60. (let ((found (find-dao 'ygo-info :id id)))
  61. (if found
  62. (format nil
  63. "<img class=\"w3-image w3-card-4 zoom\" src=\"/public/ygoprodeck/~a.jpg\" alt=\"Card Image for Yu-Gi-Oh! ~a - ~a\">"
  64. (ygo-passcode-of found)
  65. (ygo-passcode-of found)
  66. (name-of found))))))))
  67. (defroute ("/cards/by-passcode/:id/price" :method :GET) (&key id)
  68. "Get the YGO-PRICE info for this PASSCODE ID. The pricing info comes from YGOProDeck."
  69. (with-logged-in-user
  70. (handler-case
  71. (ratify:with-parsed-forms
  72. ((:integer id))
  73. (let ((found (find-dao 'ygo-price :passcode-id id)))
  74. (render-with-env #P"cards/ygo-price.html"
  75. (list :price found)))))))