-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove legacy api #129
base: master
Are you sure you want to change the base?
Remove legacy api #129
Changes from 7 commits
2e0a936
6bea44f
fd7aeb9
245a340
e0eede3
56aabef
40f0bdc
f92e561
291f683
51d25e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ webapp/.lsp/.cache | |
webapp/out | ||
webapp/.shadow-cljs | ||
webapp/.lein-repl-history | ||
.clj-kondo | ||
.lsp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
(ns lipas.backend.handler | ||
(:require | ||
[clojure.java.io :as io] | ||
[clojure.spec.alpha :as s] | ||
[lipas.backend.core :as core] | ||
[lipas.backend.jwt :as jwt] | ||
[lipas.backend.middleware :as mw] | ||
[lipas.roles :as roles] | ||
[lipas.schema.core] | ||
[lipas.utils :as utils] | ||
[muuntaja.core :as m] | ||
[reitit.coercion.spec] | ||
[reitit.ring :as ring] | ||
[reitit.ring.coercion :as coercion] | ||
[reitit.ring.middleware.exception :as exception] | ||
[reitit.ring.middleware.multipart :as multipart] | ||
[reitit.ring.middleware.muuntaja :as muuntaja] | ||
[reitit.swagger :as swagger] | ||
[reitit.swagger-ui :as swagger-ui] | ||
[ring.middleware.params :as params] | ||
[ring.util.io :as ring-io] | ||
[taoensso.timbre :as log])) | ||
(:require [clojure.java.io :as io] | ||
[clojure.spec.alpha :as s] | ||
[lipas.backend.core :as core] | ||
[lipas.backend.jwt :as jwt] | ||
[lipas.backend.legacy.api :as legacy.api] | ||
[lipas.backend.middleware :as mw] | ||
[lipas.roles :as roles] | ||
[lipas.schema.core] | ||
[lipas.utils :as utils] | ||
[muuntaja.core :as m] | ||
[reitit.coercion.spec] | ||
[reitit.ring :as ring] | ||
[reitit.ring.coercion :as coercion] | ||
[reitit.ring.middleware.exception :as exception] | ||
[reitit.ring.middleware.multipart :as multipart] | ||
[reitit.ring.middleware.muuntaja :as muuntaja] | ||
[reitit.swagger :as swagger] | ||
[reitit.swagger-ui :as swagger-ui] | ||
[ring.middleware.params :as params] | ||
[ring.util.io :as ring-io] | ||
[taoensso.timbre :as log])) | ||
|
||
(defn exception-handler | ||
([status type] | ||
|
@@ -40,7 +40,6 @@ | |
:user-not-found (exception-handler 404 :user-not-found) | ||
:email-not-found (exception-handler 404 :email-not-found) | ||
:reminder-not-found (exception-handler 404 :reminder-not-found) | ||
|
||
:qbits.spandex/response-exception (exception-handler 500 :internal-server-error :print-stack) | ||
|
||
;; Return 500 and print stack trace for exceptions that are not | ||
|
@@ -57,7 +56,6 @@ | |
[{:keys [db emailer search mailchimp aws]}] | ||
(ring/ring-handler | ||
(ring/router | ||
|
||
[["/favicon.ico" | ||
{:get | ||
{:no-doc true | ||
|
@@ -774,7 +772,45 @@ | |
:handler | ||
(fn [{:keys [body-params identity]}] | ||
{:status 200 | ||
:body (core/save-ptv-integration-definitions db search identity body-params)})}}]]] | ||
:body (core/save-ptv-integration-definitions db search identity body-params)})}}]] | ||
|
||
;; legacy routes | ||
["/v1/api" | ||
["/swagger.json" | ||
{:get | ||
{:no-doc true | ||
:swagger {:id ::legacy | ||
:info {:title "Lipas-API (legacy) v1"}} | ||
:handler (swagger/create-swagger-handler)}}] | ||
["/sports-place-types" | ||
{:swagger {:id ::legacy} | ||
:parameters {:query (s/keys :opt-un [:lipas.api/lang])} | ||
:get | ||
{:handler | ||
(fn [req] | ||
(let [locale (or (-> req :parameters :query :lang keyword) :en)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Legacy-api defaults to |
||
{:status 200 | ||
:body (legacy.api/sports-place-types locale)}))}}] | ||
["/sports-place-types/:type-code" | ||
{:swagger {:id ::legacy} | ||
:parameters {:query (s/keys :opt-un [:lipas.api/lang]) | ||
:path {:type-code int?}} | ||
:get | ||
{:handler | ||
(fn [req] | ||
(let [locale (or (-> req :parameters :query :lang keyword) :en) | ||
type-code (-> req :parameters :path :type-code)] | ||
{:status 200 | ||
:body (legacy.api/sports-place-by-type-code locale type-code)}))}}] | ||
["/categories" | ||
{:swagger {:id ::legacy} | ||
:parameters {:query (s/keys :opt-un [:lipas.api/lang])} | ||
:get | ||
{:handler | ||
(fn [req] | ||
(let [locale (or (-> req :parameters :query :lang keyword) :en)] | ||
{:status 200 | ||
:body (legacy.api/categories locale)}))}}]]] | ||
|
||
{:data | ||
{:coercion reitit.coercion.spec/coercion | ||
|
@@ -800,4 +836,5 @@ | |
mw/privilege-middleware]}}) | ||
(ring/routes | ||
(swagger-ui/create-swagger-ui-handler {:path "/api/swagger-ui" :url "/api/swagger.json"}) | ||
(swagger-ui/create-swagger-ui-handler {:path "/v1/api/swagger-ui" :url "/v1/api/swagger.json"}) | ||
(ring/create-default-handler)))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(ns lipas.backend.legacy.api | ||
(:require | ||
[lipas.data.prop-types :as prop-types] | ||
[lipas.data.types :as types] | ||
[lipas.utils :as utils])) | ||
|
||
(def keys-vec [:type-code :name :description :geometry-type :sub-category]) | ||
|
||
(defn fill-properties [m] | ||
(reduce (fn [acc k] (assoc-in acc [:props k] (prop-types/all k))) | ||
m | ||
(-> m :props keys))) | ||
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. or |
||
|
||
|
||
(defn localize-properties [m locale] | ||
(reduce (fn [acc k] | ||
(-> acc | ||
(update-in [:props k :description] locale) | ||
(update-in [:props k :name] locale))) m (-> m :props keys))) | ||
|
||
(defn- localize [m lang] | ||
(-> m | ||
(update :name lang) | ||
(update :description lang))) | ||
|
||
|
||
(defn- ->legacy-api-with-properties [m lang] | ||
(-> m | ||
(fill-properties) | ||
(select-keys (conj keys-vec :props)) | ||
(update :props #(-> % (dissoc :schoolUse? :freeUse?))) | ||
(localize-properties lang) | ||
(localize lang) | ||
utils/->camel-case-keywords)) | ||
|
||
(defn- ->legacy-api [m lang] | ||
(-> m | ||
(select-keys keys-vec) | ||
(localize lang) | ||
utils/->camel-case-keywords)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if it was this simple. ;) However, the differences between lipas and legacy-api are not 1:1 kebab-case -> camelCase... there are a few edge-cases and exceptions that are covered in this mapping: https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/integration/old_lipas/sports_site.clj#L13 ...and it's inverted version https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/integration/old_lipas/sports_site.clj#L203 You can use rename-keys to change "new keys" to "old keys" with the hardcoded map. |
||
|
||
(defn sports-place-types [locale] | ||
(->> (vals types/all) | ||
(map #(->legacy-api % locale)))) | ||
|
||
(defn sports-place-by-type-code [locale type-code] | ||
(-> (types/all type-code) | ||
(->legacy-api-with-properties locale))) | ||
|
||
(defn collect-sport-place-types [sub-category-type-code] | ||
(->> (vals types/all) | ||
(filter #(= (% :sub-category) sub-category-type-code)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor thing, but you can change |
||
(map :type-code))) | ||
|
||
(defn- collect-subcategories [type-code locale] | ||
(->> | ||
(vals types/sub-categories) | ||
(filter #(= (% :main-category) (str type-code))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above :) |
||
(map (fn [x] | ||
{:typeCode (x :type-code) | ||
:name (-> x :name locale) | ||
:sportsPlaceTypes (collect-sport-place-types (x :type-code))})))) | ||
|
||
(defn categories [locale] | ||
(mapv (fn [cat] {:name (-> cat :name locale) | ||
:typeCode (cat :type-code) | ||
:subCategories (collect-subcategories (cat :type-code) locale)}) | ||
(vals types/main-categories))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns lipas.schema.core-legacy | ||
(:require [clojure.spec.alpha :as s] | ||
[lipas.schema.core])) | ||
|
||
(s/def :lipas-legacy.api.parameter/lang :lipas.api/lang) | ||
|
||
(s/def :lipas-legacy.api.response/sports-place-types | ||
(s/keys :req-un [:lipas-legacy.sports-site/typeCode | ||
:lipas.sports-site/name | ||
:lipas.sports-site/description | ||
:lipas-legacy.sports-site/geometryType | ||
:lipas-legacy.sports-site/subCategory])) | ||
|
||
(s/def :lipas-legacy.sports-site/geometryType #{"Point" "LineString"}) | ||
(s/def :lipas-legacy.sports-site/typeCode (s/int-in 1 5000)) | ||
(s/def :lipas-legacy.sports-site/subCategory (s/int-in 1 5000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's currently a top-level endpoint
/rest
that nginx captures and proxies to the legacy-api. I think we could just swap in this thing with the path/rest/api
once it's ready and remove the nginx rule. https://github.com/lipas-liikuntapaikat/lipas/blob/master/nginx/proxy.conf#L141