|
46 | 46 | (throw (r/ex-bad-method request))) |
47 | 47 |
|
48 | 48 |
|
| 49 | +(defmulti query-collection (fn [collection-id _] collection-id)) |
| 50 | + |
| 51 | +(defn query-collection-default |
| 52 | + [collection-id options] |
| 53 | + (db/query collection-id (assoc options :nuvla/authn auth/internal-identity))) |
| 54 | + |
| 55 | +(defmethod query-collection :default |
| 56 | + [collection-id options] |
| 57 | + (query-collection-default collection-id options)) |
| 58 | + |
49 | 59 | (defn query-as-admin |
50 | 60 | "Calls the database query with the administrator user identity merged |
51 | 61 | into the given options." |
52 | 62 | [collection-id options] |
53 | | - (db/query collection-id (assoc options :nuvla/authn auth/internal-identity) )) |
| 63 | + (query-collection collection-id options)) |
54 | 64 |
|
55 | 65 | (defn query-native |
56 | 66 | "Executes the database query as a native query." |
|
83 | 93 |
|
84 | 94 | (defmulti retrieve-by-id resource-id-dispatch) |
85 | 95 |
|
86 | | - |
87 | | -(defmethod retrieve-by-id :default |
88 | | - [resource-id & [request]] |
| 96 | +(defn retrieve-by-id-default |
| 97 | + [resource-id request] |
89 | 98 | (some-> resource-id |
90 | 99 | db/retrieve |
91 | 100 | (a/throw-cannot-view request))) |
92 | 101 |
|
| 102 | +(defmethod retrieve-by-id :default |
| 103 | + [resource-id & [request]] |
| 104 | + (retrieve-by-id-default resource-id request)) |
| 105 | + |
93 | 106 |
|
94 | 107 | (defn retrieve-by-id-as-admin |
95 | 108 | "Calls the retrieve-by-id multimethod with options that set the user |
|
102 | 115 | "Same as `retrieve-by-id-as-admin` but if the resource is not found returns nil |
103 | 116 | instead of throwing an exception." |
104 | 117 | [resource-id] |
105 | | - (try (retrieve-by-id-as-admin resource-id) |
106 | | - (catch Exception ex |
107 | | - (when-not (= 404 (:status (ex-data ex))) |
108 | | - (throw ex))))) |
| 118 | + (try |
| 119 | + (retrieve-by-id-as-admin resource-id) |
| 120 | + (catch Exception ex |
| 121 | + (when-not (= 404 (:status (ex-data ex))) |
| 122 | + (throw ex))))) |
109 | 123 |
|
110 | 124 |
|
111 | 125 | (defn id->user-request |
|
0 commit comments