-
Notifications
You must be signed in to change notification settings - Fork 0
/
portfolio.clj
87 lines (70 loc) · 2.88 KB
/
portfolio.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(ns andrewslai.clj.entities.portfolio
(:require [andrewslai.clj.persistence.postgres2 :as pg]
[clojure.spec.alpha :as s]))
(s/def :andrewslai.portfolio/id int?)
(s/def :andrewslai.portfolio/name string?)
(s/def :andrewslai.portfolio/url string?)
(s/def :andrewslai.portfolio/image_url string?)
(s/def :andrewslai.portfolio/description string?)
(s/def :andrewslai.portfolio/organization
(s/keys :req-un [:andrewslai.portfolio/id
:andrewslai.portfolio/name
:andrewslai.portfolio/url
:andrewslai.portfolio/image_url
:andrewslai.portfolio/description]))
(s/def :andrewslai.portfolio/organizations
(s/coll-of :andrewslai.portfolio/organization))
(s/def :andrewslai.portfolio/organization_names
(s/coll-of :andrewslai.portfolio/name))
(s/def :andrewslai.portfolio/skills-names
(s/coll-of :andrewslai.portfolio/name))
(s/def :andrewslai.portfolio/project
(s/keys :req-un [:andrewslai.portfolio/id
:andrewslai.portfolio/name
:andrewslai.portfolio/url
:andrewslai.portfolio/image_url
:andrewslai.portfolio/description
:andrewslai.portfolio/organization_names
:andrewslai.portfolio/skills_names]))
(s/def :andrewslai.portfolio/projects (s/coll-of :andrewslai.portfolio/project))
(s/def :andrewslai.portfolio/skill_category string?)
(s/def :andrewslai.portfolio/skill
(s/keys :req-un [:andrewslai.portfolio/id
:andrewslai.portfolio/name
:andrewslai.portfolio/url
:andrewslai.portfolio/image_url
:andrewslai.portfolio/description
:andrewslai.portfolio/skill_category]))
(s/def :andrewslai.portfolio/skills
(s/coll-of :andrewslai.portfolio/skill))
(s/def :andrewslai.portfolio/portfolio
(s/keys :req-un [:andrewslai.portfolio/organizations
:andrewslai.portfolio/projects
:andrewslai.portfolio/skills]))
(defn get-portfolio [database]
(let [orgs (pg/select database
{:select [:*] :from [:organizations]})
projects (pg/select database
{:select [:*] :from [:projects]})
skills (pg/select database
{:select [:*] :from [:skills]})]
{:organizations orgs
:projects projects
:skills skills}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions to test DB connection
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(comment
(-> pg-db
->ProjectPortfolioDatabase
get-project-portfolio
:projects
clojure.pprint/pprint)
(-> pg-db
->ProjectPortfolioDatabase
get-project-portfolio
:organizations
first
clojure.pprint/pprint)
(sql/query pg-db ["SELECT name FROM projects "])
)