<commit_before>(ns metabase.api.card
  (:require [compojure.core :refer [GET DELETE]]
            [korma.core :refer :all]
            [metabase.api.common :refer :all]
            [metabase.db :refer :all]
            (metabase.models [hydrate :refer [hydrate]]
                             [card :refer :all]
                             [card-favorite :refer :all])))

(defendpoint GET "/" [org f] ; TODO - need to do something with the `f` param
  (-> (sel :many Card :organization_id org (order :name :ASC))
      (hydrate :creator)))

(defendpoint GET "/pass/" []
  (check-403 true)
  {:status "OK"})

(defendpoint GET "/:id" [id]
  (->404 (sel :one Card :id id)
         (hydrate :can_read :can_write)))

(defendpoint DELETE "/:id" [id]
  (let-404 [card (sel :one Card :id id)]
    (check-403 @(:can_write card))
    (del Card :id id)))

(defendpoint GET "/fail" []
  (check-403 false)
  {:status "OK"})

(defendpoint GET "/:id/favorite" [id]
  {:favorite (boolean (some->> *current-user-id*
                               (sel :one CardFavorite :card_id id :owner_id)))})

(define-routes)
<commit_msg>remove test functions<commit_after>(ns metabase.api.card
  (:require [compojure.core :refer [GET DELETE]]
            [korma.core :refer :all]
            [metabase.api.common :refer :all]
            [metabase.db :refer :all]
            (metabase.models [hydrate :refer [hydrate]]
                             [card :refer :all]
                             [card-favorite :refer :all])))

(defendpoint GET "/" [org f] ; TODO - need to do something with the `f` param
  (-> (sel :many Card :organization_id org (order :name :ASC))
      (hydrate :creator)))

(defendpoint GET "/:id" [id]
  (->404 (sel :one Card :id id)
         (hydrate :can_read :can_write)))

(defendpoint DELETE "/:id" [id]
  (let-404 [card (sel :one Card :id id)]
    (check-403 @(:can_write card))
    (del Card :id id)))

(defendpoint GET "/:id/favorite" [id]
  {:favorite (boolean (some->> *current-user-id*
                               (sel :one CardFavorite :card_id id :owner_id)))})

(define-routes)

{'fraction_non_alphanumeric': 0.16108986615678778, 'fraction_numerical': 0.011472275334608031, 'mean_word_length': 2.332802547770701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4007242', 'n_tokens_mistral': 735, 'n_tokens_neox': 718, 'n_words': 206}