<commit_before>(ns spacon.components.user
  (:require [com.stuartsierra.component :as component]
            [io.pedestal.interceptor.helpers :refer [defhandler]]
            [spacon.http.intercept :as intercept]
            [spacon.http.response :as response]
            [spacon.models.user :as usermodel]
            [spacon.http.auth :refer [check-auth]]
            [clojure.spec :as s]
            [spacon.spec :as specs]))

(defn http-get-all-users [request]
  response/ok (usermodel/all))

(defn http-create-user
  "Creates a new user"
  [request]
  (let [user (:json-params request)]
    (if (s/valid? :spacon.models.user/spec user)
      (if-let [new-user (usermodel/create user)]
        (response/ok new-user))
      (response/error (str "failed to create user:\n"
                           (s/explain-str :spacon.spec/user-spec user))))))

(defn http-create-user-team [request]
  (if-let [new-user-team (usermodel/add-user-team (:json-params request))]
    (response/ok new-user-team)
    (response/error "Failed to add user to team")))

(defn http-remove-user-team [request]
  (if-let [new-user-team (usermodel/remove-user-team (:json-params request))]
    (response/ok new-user-team)
    (response/error "Failed to remove user from team")))

(defn- routes []
  #{["/api/users" :get  (conj intercept/common-interceptors `http-get-all-users)]
    ["/api/users" :post (conj intercept/common-interceptors `http-create-user)]
    ["/api/user-team" :post (conj intercept/common-interceptors `http-create-user-team)]
    ["/api/user-team" :delete (conj intercept/common-interceptors `http-remove-user-team)]})

(defrecord UserComponent []
  component/Lifecycle
  (start [this]
    (assoc this :routes (routes)))
  (stop [this]
    this))

(defn make-user-component []
  (->UserComponent))
<commit_msg>fixing invalid spec reference (#201)<commit_after>(ns spacon.components.user
  (:require [com.stuartsierra.component :as component]
            [io.pedestal.interceptor.helpers :refer [defhandler]]
            [spacon.http.intercept :as intercept]
            [spacon.http.response :as response]
            [spacon.models.user :as usermodel]
            [spacon.http.auth :refer [check-auth]]
            [clojure.spec :as s]
            [spacon.spec :as specs]))

(defn http-get-all-users [request]
  response/ok (usermodel/all))

(defn http-create-user
  "Creates a new user"
  [request]
  (let [user (:json-params request)]
    (if (s/valid? :spacon.spec/user-spec user)
      (if-let [new-user (usermodel/create user)]
        (response/ok new-user))
      (response/error (str "failed to create user:\n"
                           (s/explain-str :spacon.spec/user-spec user))))))

(defn http-create-user-team [request]
  (if-let [new-user-team (usermodel/add-user-team (:json-params request))]
    (response/ok new-user-team)
    (response/error "Failed to add user to team")))

(defn http-remove-user-team [request]
  (if-let [new-user-team (usermodel/remove-user-team (:json-params request))]
    (response/ok new-user-team)
    (response/error "Failed to remove user from team")))

(defn- routes []
  #{["/api/users" :get  (conj intercept/common-interceptors `http-get-all-users)]
    ["/api/users" :post (conj intercept/common-interceptors `http-create-user)]
    ["/api/user-team" :post (conj intercept/common-interceptors `http-create-user-team)]
    ["/api/user-team" :delete (conj intercept/common-interceptors `http-remove-user-team)]})

(defrecord UserComponent []
  component/Lifecycle
  (start [this]
    (assoc this :routes (routes)))
  (stop [this]
    this))

(defn make-user-component []
  (->UserComponent))

{'fraction_non_alphanumeric': 0.15682504806371875, 'fraction_numerical': 0.0008239494644328481, 'mean_word_length': 3.0875420875420874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7471095', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1238, 'n_words': 270}