Skip to content
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

Projeto pratico - Ana Carolina #14

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions .idea/libraries/Leiningen__clj_tuple_0_2_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/Leiningen__clojure_java_time_0_3_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/Leiningen__prismatic_schema_1_2_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

### Uau! É funcional!!!

Projeto bancário para mergulhar no mundo da **programação funcional** com Clojure + Datomic!
Projeto bancário para mergulhar no mundo da **Programação funcional** com Clojure + Datomic!


Desenvolvido por *[COLOCAR NOME AQUI]* (*[COLOCAR SEU EMAIL AQUI]*).
Desenvolvido por *Ana Carolina Santos Silva* (*ana.ssilva@nubank.com.br*).
4 changes: 3 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.1"]]
:dependencies [[org.clojure/clojure "1.10.1"]
[clojure.java-time "0.3.3"]
[prismatic/schema "1.2.0"]]
:repl-options {:init-ns yes-she-codes.core})
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/yes_she_codes/.DS_Store
Binary file not shown.
49 changes: 49 additions & 0 deletions src/yes_she_codes/atom.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(ns yes-she-codes.atom
(:use [clojure pprint])
(:require [yes-she-codes.db :as y.db]))

(def repositorio-de-compras (atom []))

(defrecord Compras [id,
data,
valor,
estabelecimento,
categoria,
cartao])

(defn lista-de-compras-atomo []
@repositorio-de-compras)

(defn id-uuid []
(.toString (java.util.UUID/randomUUID)))

(defn inserir-id-compra [[data, valor, estabelecimento, categoria, cartao]]
(Compras. (id-uuid), data, valor, estabelecimento, categoria, cartao))

(defn inserir-id-compra-vetor [repositorio-de-compras antiga-compra]
(let [nova-compra
(inserir-id-compra antiga-compra)]
(conj repositorio-de-compras nova-compra)))

(defn inserir-compras-atom! [antiga-compra]
(swap! repositorio-de-compras inserir-id-compra-vetor antiga-compra))

(defn transforma-compras [array]
(doseq [x array]
(inserir-compras-atom! x)))

(defn lista-compras []
(transforma-compras (y.db/busca-registros-de-compras)))

(lista-compras)

(pprint (lista-de-compras-atomo))

(defn pesquisa-compra-por-id! [entidades id]
(first (filter #(= id (:id %)) entidades)))

(defn pesquisa-compra-id-atom [id repositorio-de-compras]
(pesquisa-compra-por-id! @repositorio-de-compras id))

(pesquisa-compra-por-id! @repositorio-de-compras "1b78b5e0-940e-4dd9-aabb-c588742bcd82")
(pesquisa-compra-id-atom "1b78b5e0-940e-4dd9-aabb-c588742bcd82" repositorio-de-compras)
122 changes: 117 additions & 5 deletions src/yes_she_codes/core.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,118 @@
(ns yes-she-codes.core)
(ns yes-she-codes.core
(:require yes-she-codes.dominio.compras :as y.compras)
(:require yes-she-codes.atom :as y.atom)
(:require yes-she-codes.dominio.clientes :as y.clientes)
(:require yes-she-codes.dominio.cartao :as y.cartao))


(println "Lista de clientes\n" (y.clientes/lista-clientes))
(println "Lista de cartoes\n" (y.cartao/lista-cartoes))
(println "Lista de compras\n" (y.compras/lista-compras))
(println "Total gasto em compras de todos os cartões\n" (y.compras/total-gasto (y.compras/lista-compras)))
(println "Total gasto em compras de apenas um cartao\n" (y.cartao/total-gasto-no-cartao 1234123412341234 (y.logic/lista-compras)))
(println "Busca das compras de um mes\n " (y.compras/compras-no-mes "04" (y.compras/lista-compras)))
(println "Calcular o total da fatura de um mês\n" (y.compras/total-gasto-no-mes "04" (y.compras/lista-compras)))
(println "Busca de um estabelecimento\n" (y.compras/comprei-no-estabelecimento? "Alura" (y.compras/lista-compras)))
























































;(defn insere-compra
; [compra compras]
; (let [id (inc (count compras))
; compras-inserir (assoc compra :ID id)]
; (conj compras compras-inserir)))

;(defn insere-compra!
; [compras compra]
; (swap! compras insere-compra compra))

(defn id-uuid []
(.toString (java.util.UUID/randomUUID)))

(defrecord Paciente [id nome nascimento])

;(pprint (->Paciente 15, "Guilherme", "19/09/1981"))
(pprint (Paciente. (id-uuid), "Guilherme", "19/09/1981"))





;(defn nova-compra [data, valor, estabelecimento, categoria, cartao]
; {:data data,
; :valor valor,
; :estabelecimento estabelecimento,
; :categoria categoria,
; :cartao cartao})
;
;(defn transforma-compra []
; (Compras))
;
;(defn transforma-compras [array]
; (map transforma-compra array))
;
;(defn lista-compras []
; (transforma-compras (y.db/busca-registros-de-compras)))
;
;(println "Lista de compras\n" (lista-compras))


;(defn insere-compra-atomo
; [Compras @repositorio-de-compras]
; (update Compras @repositorio-de-compras pop))



(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
37 changes: 37 additions & 0 deletions src/yes_she_codes/db.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns yes-she-codes.db)
;banco de dados com todas as informações de clientes, cartões e compras.
(defn busca-registros-de-clientes []
[
["Feiticeira Escarlate", "000.111.222-33", "feiticeira.poderosa@vingadoras.com.br"]
["Viúva Negra", "333.444.555-66", "viuva.casca.grossa@vingadoras.com.br"]
["Hermione Granger", "666.777.888-99", "hermione.salvadora@hogwarts.com"]
["Daenerys Targaryen", "999.123.456-78", "mae.dos.dragoes@got.com"]])

(defn busca-registros-de-cartoes []
[[1234123412341234, 111, "2023-01", 1000, "000.111.222-33"]
[4321432143214321, 222, "2024-02", 2000, "333.444.555-66"]
[1598159815981598, 333, "2021-03", 3000, "666.777.888-99"]
[6655665566556655, 444, "2025-04", 4000, "666.777.888-99"]
[3939393939393939, 555, "2026-05", 5000, "999.123.456-78"]])

(defn busca-registros-de-compras []
[
["2022-01-01", 129.90, "Outback", "Alimentação" 1234123412341234]
["2022-01-02", 260.00, "Dentista", "Saúde" 1234123412341234]
["2022-02-01", 20.00, "Cinema", "Lazer" 1234123412341234]
["2022-01-10", 150.00, "Show", "Lazer" 4321432143214321]
["2022-02-10", 289.99, "Posto de gasolina", "Automóvel" 4321432143214321]
["2022-02-20", 79.90, "iFood", "Alimentação", 4321432143214321]
["2022-03-01", 85.00, "Alura", "Educação", 4321432143214321]
["2022-01-30", 85.00, "Alura", "Educação", 1598159815981598]
["2022-01-31", 350.00, "Tok&Stok", "Casa", 1598159815981598]
["2022-02-01", 400.00, "Leroy Merlin", "Casa", 1598159815981598]
["2022-03-01", 50.00, "Madero", "Alimentação", 6655665566556655]
["2022-03-01", 70.00, "Teatro", "Lazer", 6655665566556655]
["2022-03-04", 250.00, "Hospital", "Saúde", 6655665566556655]
["2022-04-10", 130.00, "Drogaria", "Saúde", 6655665566556655]
["2022-03-10", 100.00, "Show de pagode", "Lazer", 3939393939393939]
["2022-03-11", 25.90, "Dogão", "Alimentação", 3939393939393939]
["2022-03-12", 215.87, "Praia", "Lazer", 3939393939393939]
["2022-04-01", 976.88, "Oficina", "Automóvel", 3939393939393939]
["2022-04-10", 85.00, "Alura", "Educação", 3939393939393939]])
41 changes: 41 additions & 0 deletions src/yes_she_codes/dominio/cartao.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(ns yes-she-codes.dominio.cartao
(:require [yes-she-codes.db :as y.db])
(:require [yes-she-codes.dominio.compras :as y.compras]))

(defn novo-cartao [numero, cvv, validade, limite, cliente]
{:numero numero,
:cvv cvv,
:validade validade,
:limite limite,
:cliente cliente})

(defn transforma-cartao [[numero, cvv, validade, limite, cliente]]
(novo-cartao numero, cvv, validade, limite, cliente))

(defn transforma-cartoes [array]
(map transforma-cartao array))

(defn lista-cartoes []
(transforma-cartoes (y.db/busca-registros-de-cartoes)))

;fiz essa etapa para encontrar o cartão dentro da lista de compras

(defn achei-o-cartao-na-lista-de-compras? [cartao todas-as-compras]
(= cartao (:cartao todas-as-compras)))

(defn comprei-no-cartao? [cartao lista-de-cartoes]
(filter #(achei-o-cartao-na-lista-de-compras? cartao %) lista-de-cartoes))

(comprei-no-cartao? 1234123412341234 (y.compras/lista-compras))

;fiz essa etapa para somar valores de um o cartão na lista

(defn compra [x y]
(+ x (:valor y)))

(defn total-gasto [lista-de-compras]
(reduce compra 0 lista-de-compras))

(def total-gasto-no-cartao (comp total-gasto comprei-no-cartao?))

(println "Valor total das compras de um cartao" (total-gasto-no-cartao 1234123412341234 (y.compras/lista-compras)))
24 changes: 24 additions & 0 deletions src/yes_she_codes/dominio/clientes.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns yes-she-codes.dominio.clientes
(:require [yes-she-codes.db :as y.db])
(:require [clojure.string :as str]))


; schema para clientes

(defn novo-cliente [nome, cpf, email]
{:nome nome
:cpf cpf
:email email})

; recebe o array quebrado; e passa os dados para novo-cliente.
(defn transforma-cliente [[nome, cpf, email]]
(novo-cliente nome, cpf, email))

; recebe o array, que é o meu banco de dados com todos os clientes. Quebra o array através do map
(defn transforma-clientes [array]
(map transforma-cliente array))

(defn lista-clientes []
(transforma-clientes (y.db/busca-registros-de-clientes)))


Loading