2 |
3 | # 
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | **Ecoleta é uma aplicação que ajuda a encontrar pontos de coleta de lixo reciclável no Brasil.**
13 |
14 | Página principal
15 |
16 |
17 |
18 | Página de pesquisa de Pontos de Coleta em uma determinada cidade
19 |
20 |
21 |
22 | Página de cadastro de Ponto de Coleta
23 |
24 |
25 |
26 | ---
27 |
28 |
29 | _Aplicação feita na Next Level Week #1 da [@Rocketseat](https://github.com/Rocketseat), nos dias 1 a 5 de Junho_
30 | 
31 |
32 |
33 |
34 | ### Tecnologias
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | #### Front-end:
44 |
45 | - [Nunjucks](https://mozilla.github.io/nunjucks/)
46 | - [HTML 5](http://www.w3.org/TR/html5/)
47 | - [CSS 3](https://www.w3schools.com/Css/)
48 | - [JavaScript](https://www.javascript.com/)
49 |
50 | #### Back-end:
51 |
52 | - [NodeJS](https://nodejs.org/)
53 | - [Express](https://expressjs.com/)
54 | - [Nodemon](https://nodemon.io/)
55 | - [SQLite3](https://www.sqlite.org/)
56 |
57 | #### APIs
58 |
59 | - [IBGE](https://servicodados.ibge.gov.br/api/docs/localidades?versao=1)
60 |
61 | ### Uso
62 |
63 | #### Instalar dependencias:
64 |
65 | com npm
66 |
67 | ```bash
68 | $ npm install
69 | ```
70 |
71 |
72 | com yarn
73 |
74 | ```bash
75 | $ yarn install
76 | ```
77 |
78 |
79 | #### Iniciar servidor:
80 |
81 | com npm
82 |
83 | ```bash
84 | $ npm start
85 | ```
86 |
87 |
88 | com yarn
89 |
90 | ```bash
91 | $ yarn run start
92 | ```
93 |
94 |
95 | > porta: 3000
96 |
97 | Para trocar a porta basta ir em [src/server.js:97](https://github.com/mateusfg7/Ecoleta/blob/master/src/server.js#L97), e trocar o porta 3000 para a porta desejada.
98 | ```javascript
99 | // turn on the server
100 | server.listen(3000);
101 | ```
102 |
103 | ### Criar Bando de Dados
104 |
105 | Para criar o banco de dados descomente as linhas 9 a 79, depois as linhas 11 a 26 do arquivo [src/database/db.js](https://github.com/mateusfg7/Ecoleta/blob/master/src/database/db.js)
106 |
107 | ```js
108 | // use the object of the database, for our operations
109 | db.serialize(() => {
110 | // create a table with SQL commands:
111 | // the firs param of data is the type of same
112 | // PRIMARY KEY -> main data
113 | // AUTOINCRMENT -> autoincrement when add a new register
114 | db.run(`
115 | CREATE TABLE IF NOT EXISTS places (
116 | id INTEGER PRIMARY KEY AUTOINCREMENT,
117 | image TEXT,
118 | name TEXT,
119 | address TEXT,
120 | address2 TEXT,
121 | state TEXT,
122 | city TEXT,
123 | items TEXT
124 | );
125 | `);
126 |
127 | // // insert data into the table with SQL commands
128 | // const query = `
129 | // INSERT INTO places (
130 | // image,
131 | // name,
132 | // address,
133 | // address2,
134 | // state,
135 | // city,
136 | // items
137 | // ) VALUES (?,?,?,?,?,?,?);
138 | // `
139 | // const values = [
140 | // "https://images.unsplash.com/photo-1567393528677-d6adae7d4a0a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80",
141 | // "Papersider",
142 | // "Gulherme Gemballa, Jardim América",
143 | // "Nº 260",
144 | // "Santa Catarina",
145 | // "Rio do Sul",
146 | // "Papéis e Papelão"
147 | // ]
148 |
149 | // function afterInsertData(err) {
150 | // if (err) {
151 | // return console.log(err)
152 | // }
153 |
154 | // console.log("[personal] Cadastrado com sucesso")
155 | // console.log(this)
156 | // }
157 |
158 | // db.run(query, values, afterInsertData);
159 |
160 | // // query table data with SQL commands
161 | // db.all(`SELECT * FROM places`, function(err, rows) {
162 | // if (err) {
163 | // return console.log(err)
164 | // }
165 |
166 | // console.log("[personal] Aqui estão seus registros")
167 | // console.log(rows)
168 | // })
169 |
170 | // // delete a table data with SQL commands
171 | // db.run(`DELETE FROM places WHERE id = ?`, [8], function(err) {
172 | // if (err) {
173 | // return console.log(err)
174 | // }
175 |
176 | // console.log("[personal] Registro deletado com sucesso")
177 | // })
178 | });
179 | ```
180 |
181 | e rode com
182 | ```bash
183 | $ node src/database/db.js
184 | ```
185 | Depois de criado, recomente as linhas e [rode o servidor](#iniciar-servidor).
186 |
187 | > O arquivo do banco de dados ficara salvo em src/database/database.db
188 |
189 | ---
190 |
191 |