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

Bootcamp - Yes She Codes 2022 #37

Open
wants to merge 5 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
9 changes: 9 additions & 0 deletions .idea/libraries/Leiningen__prismatic_schema_1_2_1.xml

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

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.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
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 *Jéssica Ayumi* (*jessica.ayumi@nubank.com.br*).
16 changes: 5 additions & 11 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
:description "FIXME: write description"
: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/"}

:repositories {"my.datomic.com" {:url "https://my.datomic.com/repo"
:username "cacio.cjcs@gmail.com"
:password "596550f1-921f-4ca2-9bca-87279cebc418"}}

:dependencies [[org.clojure/clojure "1.10.1"]
[clojure.java-time "0.3.3"]
[prismatic/schema "1.2.0"]
[com.datomic/datomic-pro "1.0.6344"]]

:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [
[org.clojure/clojure "1.10.1"]
[prismatic/schema "1.2.1"]
]
:repl-options {:init-ns yes-she-codes.core})
117 changes: 117 additions & 0 deletions src/yes_she_codes/core.clj
Original file line number Diff line number Diff line change
@@ -1 +1,118 @@
(ns yes-she-codes.core)

;Código não utilizado mais, deixado apenas para facilitar minha consulta do histórico

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

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

(defn nova-compra [data valor estabelecimento categoria cartao]
{
:data data
:valor valor
:estabelecimento estabelecimento
:categoria categoria
:cartao cartao})


(defn lista-clientes []
[{:nome "Feiticeira Escarlate", :cpf "000.111.222-33", :email "feiticeira.poderosa@vingadoras.com.br"}
{:nome "Viúva Negra", :cpf "333.444.555-66", :email "viuva.casca.grossa@vingadoras.com.br"}
{:nome "Hermione Granger", :cpf "666.777.888-99", :email "hermione.salvadora@hogwarts.com"}
{:nome "Daenerys Targaryen", :cpf "999.123.456-78", :email "mae.dos.dragoes@got.com"}])

(println (map lista-clientes))

(defn lista-cartoes []
[{:numero 1234123412341234, :cvv 111, :validade "2023-01", :limite 1.000, :cliente "000.111.222-33"}
{:numero 4321432143214321, :cvv 222, :validade "2024-02", :limite 2.000, :cliente "333.444.555-66"}
{:numero 1598159815981598, :cvv 333, :validade "2021-03" :limite 3.000, :cliente "666.777.888-99"}
{:numero 6655665566556655, :cvv 444, :validade "2025-04", :limite 4.000, :cliente "666.777.888-99"}
{:numero 3939393939393939, :cvv 555, :validade "2026-05", :limite 5.000, :cliente "999.123.456-78"}])

(defn lista-compras []
[{:data "2022-01-01", :valor 129.90, :estabelecimento "Outback", :categoria "Alimentação", :cartao 1234123412341234}
{:data "2022-01-02", :valor 260.00, :estabelecimento "Dentista", :categoria "Saúde", :cartao 1234123412341234}
{:data "2022-02-01", :valor 20.00, :estabelecimento "Cinema", :categoria "Lazer", :cartao 1234123412341234}
{:data "2022-01-10", :valor 150.00, :estabelecimento "Show", :categoria "Lazer", :cartao 4321432143214321}
{:data "2022-02-10", :valor 289.99, :estabelecimento "Posto de gasolina", :categoria "Automóvel", :cartao 4321432143214321}
{:data "2022-02-20", :valor 79.90, :estabelecimento "iFood", :categoria "Alimentação", :cartao 4321432143214321}
{:data "2022-03-01", :valor 85.00, :estabelecimento "Alura", :categoria "Educação", :cartao 4321432143214321}
{:data "2022-01-30", :valor 85.00, :estabelecimento "Alura", :categoria "Educação", :cartao 1598159815981598}
{:data "2022-01-31", :valor 350.00, :estabelecimento "Tok&Stok", :categoria "Casa", :cartao 1598159815981598}
{:data "2022-02-01", :valor 400.00, :estabelecimento "Leroy Merlin", :categoria "Casa", :cartao 1598159815981598}
{:data "2022-03-01", :valor 50.00, :estabelecimento "Madero", :categoria "Alimentação", :cartao 6655665566556655}
{:data "2022-03-01", :valor 70.00, :estabelecimento "Teatro", :categoria "Lazer", :cartao 6655665566556655}
{:data "2022-03-04", :valor 250.00, :estabelecimento "Hospital", :categoria "Saúde", :cartao 6655665566556655}
{:data "2022-04-10", :valor 130.00, :estabelecimento "Drogaria", :categoria "Saúde", :cartao 6655665566556655}
{:data "2022-03-10", :valor 100.00, :estabelecimento "Show de pagode", :categoria "Lazer", :cartao 3939393939393939}
{:data "2022-03-11", :valor 25.90, :estabelecimento "Dogão", :categoria "Alimentação", :cartao 3939393939393939}
{:data "2022-03-12", :valor 215.87, :estabelecimento "Praia", :categoria "Lazer", :cartao 3939393939393939}
{:data "2022-04-01", :valor 976.88, :estabelecimento "Oficina", :categoria "Automóvel", :cartao 3939393939393939}
{:data "2022-04-10", :valor 85.00, :estabelecimento "Alura", :categoria "Educação", :cartao 3939393939393939}])

(defn total-gasto [compras]
(reduce + (map :valor compras)))

(defn mes-da-data [data]
(second (re-matches #"\d{4}-(\d{2})-\d{2}" data)))


(defn filtra-compras [predicado compras]
(vec (filter predicado compras)))


(defn filtra-compras-no-mes [mes compras]
(filtra-compras #(= mes (mes-da-data (:data %)))
compras))

(defn filtra-compras-no-estabelecimento [estabelecimento compras]
(filtra-compras #(= estabelecimento (:estabelecimento %))
compras))

(defn filtra-compras-por-valor [minimo maximo compras]
(filtra-compras #(and (>= (:valor %) minimo)
(<= (:valor %) maximo))
compras))

(defn agrupa-gastos-por-categoria [compras]
(vec (map (fn [[categoria compras-da-categoria]]
{:categoria categoria
:total-gasto (total-gasto compras-da-categoria)})
(group-by :categoria compras))))


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

(defrecord Compra [^long ID, ^String data, ^BigDecimal valor, ^String estabelecimento, ^String categoria, ^Long cartao])

(defn insere-compra [compra compras]
(conj (assoc compra :ID (count compras)) compras))

(defn insere-compra! [compra atomo]
(swap! atomo conj compra))

(defn lista-compras! [atomo]
(deref atomo))

(defn pesquisa-compra-por-id [id compras]
(filter #(= id (:ID %)) compras))

(defn pesquisa-compra-por-id! [id compras]
(pesquisa-compra-por-id id compras))

; Colinha
; Command + Shift + L -> carregarmos esse arquivo e executarmos o conteúdo contido nele no REPL
; Command + Shift + K -> slurp
; Command + Shift + J -> barf
; Command + Shift + P -> executa fórmula específica
; Option + Command + L -> Formata código