-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retrieving categories and articles from db
- Loading branch information
fabrv
committed
Feb 22, 2021
1 parent
8f5144e
commit ac6d960
Showing
17 changed files
with
285 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules/ | |
.cljs_node_repl/ | ||
out/ | ||
.cpcache | ||
.lsp/ | ||
.lsp/ | ||
*.log |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
(ns sindicato-ufm.routes.index) | ||
(ns sindicato-ufm.routes.index | ||
(:require | ||
[sindicato-ufm.services.index :as index])) | ||
|
||
(def express (js/require "express")) | ||
(def router (.Router express)) | ||
|
||
(defn index [] #js{"title" "Clojurexpress"}) | ||
(defn index-routes [pgclient] | ||
(.get router | ||
"/" | ||
(fn [_ res] | ||
(index/category pgclient "opinion" 0 | ||
(fn [data] | ||
(.render res "index" data))))) | ||
|
||
(.get router | ||
"/articulo/:article" | ||
(fn [req res] | ||
)) | ||
|
||
(defn index-routes [] | ||
(.get router "/" (fn [_ res] | ||
(.render res "index" (index)))) | ||
(.get router | ||
"/:category" | ||
(fn [req res] | ||
(index/category pgclient (.. req -params -category) 0 | ||
(fn [data] | ||
(.render res "index" data))))) | ||
|
||
router) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns sindicato-ufm.services.articles) | ||
|
||
(defn get-all [pgclient limit offset callback] | ||
(-> | ||
(.query pgclient "select * from article limit $1 offset $2" #js[limit offset]) | ||
(.then (fn [a] (callback (js->clj (. a -rows)) nil))) | ||
(.catch (fn [e] (callback nil e))))) | ||
|
||
(defn get-row [pgclient id callback] | ||
(-> | ||
(.query pgclient "select * from article where id = $1" #js[id]) | ||
(.then (fn [a] (callback (js->clj (. a -rows)) nil))) | ||
(.catch (fn [e] (callback nil e))))) | ||
|
||
(defn get-by-category [pgclient category limit offset callback] | ||
(-> | ||
(.query pgclient "select * from article where category = $1 limit $2 offset $3" #js[category limit offset]) | ||
(.then (fn [a] (callback (js->clj (. a -rows)) nil))) | ||
(.catch (fn [e] (callback nil e))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns sindicato-ufm.services.categories) | ||
|
||
(defn get-all [pgclient limit offset callback] | ||
(-> | ||
(.query pgclient "select * from category order by id desc limit $1 offset $2" #js[limit offset]) | ||
(.then (fn [a] (callback (js->clj (. a -rows)) nil))) | ||
(.catch (fn [e] (callback nil e))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns sindicato-ufm.services.index | ||
(:require | ||
[sindicato-ufm.services.categories :as cats] | ||
[sindicato-ufm.services.articles :as arts])) | ||
|
||
(defn index-view [title links articles] | ||
(clj->js { | ||
:title title | ||
:links links | ||
:articles articles | ||
})) | ||
|
||
(defn category [pgclient category page callback] | ||
(arts/get-by-category | ||
pgclient | ||
category | ||
6 | ||
(* page 6) | ||
(fn [articles err] | ||
(if err | ||
(throw err) | ||
(cats/get-all | ||
pgclient | ||
100 | ||
0 | ||
(fn [categories err] | ||
(if err | ||
(throw err) | ||
(callback (index-view "Opinión" categories articles))))))))) |
Oops, something went wrong.