diff --git a/config/_development.json b/config/_development.json index 41eccab..62aff48 100644 --- a/config/_development.json +++ b/config/_development.json @@ -31,14 +31,24 @@ "enabled": true } ], - "db": {"default": { - "password": "", - "engine": "h2", - "port": "", - "host": "", - "name": "social_ma", - "username": "" - }}, + "db": { + "default": { + "password": "S3cR3t", + "engine": "pg", + "port": "5432", + "host": "localhost", + "name": "social_ma", + "username": "social_ma" + }, + "antiga": { + "password": "", + "engine": "h2", + "port": "", + "host": "", + "name": "social_ma", + "username": "" + } + }, "cors": [ { "enabled": true, diff --git a/dbs/social_ma.mv.db b/dbs/social_ma.mv.db index 611341e..705181f 100644 Binary files a/dbs/social_ma.mv.db and b/dbs/social_ma.mv.db differ diff --git a/server/core/social/userPessoa.js b/server/core/social/userPessoa.js new file mode 100644 index 0000000..86e54fe --- /dev/null +++ b/server/core/social/userPessoa.js @@ -0,0 +1,11 @@ + +const userPessoa = ()=> { + const dbPessoa = _db.queryFirst( + ` + SELECT * + FROM pessoa + WHERE usuario_id = ? + `, _user.id() + ) + return dbPessoa +} diff --git a/server/services/api/communities/follow.options.js b/server/services/api/communities/follow.options.js new file mode 100644 index 0000000..472b23f --- /dev/null +++ b/server/services/api/communities/follow.options.js @@ -0,0 +1,2 @@ + +_out.json(_val.map().set("result", true)) diff --git a/server/services/api/communities/follow.put.js b/server/services/api/communities/follow.put.js new file mode 100644 index 0000000..d2eed98 --- /dev/null +++ b/server/services/api/communities/follow.put.js @@ -0,0 +1,12 @@ +// _core : social/userPessoa + +const dbComunidade = _db.get('comunidade', _req.getString("uid")) + +_db.insert( + "pessoa_comunidade", + _val.map() + .set("pessoa_id", userPessoa().getInt("id")) + .set("comunidade_id", dbComunidade.getInt("id")) +) + +_out.json(_val.map().set("result", true)) diff --git a/server/services/api/communities/get.js b/server/services/api/communities/get.js new file mode 100644 index 0000000..b6bf4e1 --- /dev/null +++ b/server/services/api/communities/get.js @@ -0,0 +1,24 @@ + +const dbComunidades = _db.query(` + SELECT + uid, + nome, + descricao, + imagem + FROM comunidade + WHERE active = true + ORDER BY nome +`) + +const data = _val.list() + +for (const dbComunidade of dbComunidades) { + data.add( + _val.map() + .set("uid", dbComunidade.getString("uid")) + .set("name", dbComunidade.getString("nome")) + .set("description", dbComunidade.getString("descricao")) + ) +} + +_out.json(data) diff --git a/server/services/api/communities/image.get.js b/server/services/api/communities/image.get.js new file mode 100644 index 0000000..56c3ce3 --- /dev/null +++ b/server/services/api/communities/image.get.js @@ -0,0 +1,10 @@ + +const dbComunidade = _db.get('comunidade', _req.getString("uid")) + +_header.contentTypeJPG() +_header.noCache() + +if (dbComunidade != null && dbComunidade.getString("imagem") != '') { + const storageImage = _storage.database('comunidade', 'imagem', dbComunidade.getString("imagem")) + _out.copy(storageImage.inputStream()) +} diff --git a/server/services/api/communities/options.js b/server/services/api/communities/options.js new file mode 100644 index 0000000..472b23f --- /dev/null +++ b/server/services/api/communities/options.js @@ -0,0 +1,2 @@ + +_out.json(_val.map().set("result", true)) diff --git a/server/services/test-antiga.js b/server/services/test-antiga.js new file mode 100644 index 0000000..18861db --- /dev/null +++ b/server/services/test-antiga.js @@ -0,0 +1,3 @@ +const dbAntiga = _db.init("antiga") + +_out.json(dbAntiga.query("select * from cidade")) \ No newline at end of file diff --git a/server/setup/002-cidades.js b/server/setup/002-cidades.js new file mode 100644 index 0000000..f7157ae --- /dev/null +++ b/server/setup/002-cidades.js @@ -0,0 +1,30 @@ +// ----------------------------------------------------------- +// +// CIDADE +// +// ----------------------------------------------------------- +// +// CODE GENERATED AUTOMATICALLY +// + + +_db.insertIfNotExists( + "cidade", + _val.init() + .set("uid", "2b63f424-eadf-4192-903d-0c45fc3b9a8f") + .set("nome", "Natal") +); + +_db.insertIfNotExists( + "cidade", + _val.init() + .set("uid", "9b41eb5c-0e08-40e1-8d2b-d519fcf0d2e5") + .set("nome", "S\u00E3o Lu\u00EDs") +); + +_db.insertIfNotExists( + "cidade", + _val.init() + .set("uid", "2e758e73-eae6-4eb8-afdd-0107f90d92e2") + .set("nome", "Fortaleza") +); \ No newline at end of file diff --git a/server/setup/003-comunidades.js b/server/setup/003-comunidades.js new file mode 100644 index 0000000..24275ee --- /dev/null +++ b/server/setup/003-comunidades.js @@ -0,0 +1,40 @@ +// ----------------------------------------------------------- +// +// COMUNIDADE +// +// ----------------------------------------------------------- +// +// CODE GENERATED AUTOMATICALLY +// + + +_db.insertIfNotExists( + "comunidade", + _val.init() + .set("uid", "587aa840-51c8-4d65-ba9d-4512d6d3ab9f") + .set("nome", "Paraquedismo") + .set("cidade_id", "2b63f424-eadf-4192-903d-0c45fc3b9a8f") + .set("descricao", "Teste...") + .set("imagem", "1_WznPMI5w0yRUNAS7Nswh-A-T6SHzKFr.jpeg") +); + +_db.insertIfNotExists( + "comunidade", + _val.init() + .set("uid", "660c2dc5-37d6-4b19-8e22-9a106801f477") + .set("nome", "Mergulho") + .set("cidade_id", "2e758e73-eae6-4eb8-afdd-0107f90d92e2") + .set("descricao", "Mergulho em mar aberto e pesca subaqu\u00E1tica.") + .set("imagem", "20180227002111_escolas-de-mergulho-em-sesimbra_portugal-1WgWunkr.jpg") +); + +_db.insertIfNotExists( + "comunidade", + _val.init() + .set("uid", "1a446247-40d8-4960-90b8-8845a2e62686") + .set("nome", "BTT") + .set("cidade_id", "9b41eb5c-0e08-40e1-8d2b-d519fcf0d2e5") + .set("descricao", "

Pedalada de bicicleta no mato, na cidade e na praia!

") + .set("imagem", "btt-chapada-mesa-cvVKi0a6.jpg") +); + diff --git a/website/src/App.js b/website/src/App.js index 388eda3..a68c871 100644 --- a/website/src/App.js +++ b/website/src/App.js @@ -13,6 +13,7 @@ import { import Home from './pages/Home'; import Login from './pages/Login'; import Register from './pages/Register'; +import Communities from './pages/Communities'; import Main from './pages/Main'; import Core from './Core'; @@ -54,6 +55,9 @@ function App() { Principal + + Comunidades + ; } else { menu = <> @@ -85,6 +89,9 @@ function App() { + + +
diff --git a/website/src/pages/Communities/Item/index.js b/website/src/pages/Communities/Item/index.js new file mode 100644 index 0000000..e5a1c86 --- /dev/null +++ b/website/src/pages/Communities/Item/index.js @@ -0,0 +1,34 @@ +import React, { useEffect, useState} from 'react'; + +import _service from '@netuno/service-client'; + +import { Button, notification } from 'antd'; + +import "./index.less"; + +export default ({ data })=> { + const [following, setFollowing] = useState(false); + const onFollow = ()=> { + _service({ + method: 'PUT', + url: "api/communities/follow", + data: {uid: data.uid}, + success: (response) => { + setFollowing(response.json.result); + }, + fail: (e) => { + console.log("Service Error", e); + notification["error"]({ + message: 'Informações', + description: 'Não foi possível carregar a informação.', + }); + } + }); + }; + const servicePrefix = _service.config().prefix; + return ( +
  • +

    { data.name }

    +
  • + ); +}; diff --git a/website/src/pages/Communities/Item/index.less b/website/src/pages/Communities/Item/index.less new file mode 100644 index 0000000..327cda4 --- /dev/null +++ b/website/src/pages/Communities/Item/index.less @@ -0,0 +1,8 @@ + +.communities { + &__list { + list-style: none; + padding: 0; + margin: 0; + } +} diff --git a/website/src/pages/Communities/index.js b/website/src/pages/Communities/index.js new file mode 100644 index 0000000..4106d5b --- /dev/null +++ b/website/src/pages/Communities/index.js @@ -0,0 +1,49 @@ +import React, { useEffect, useState} from 'react'; + +import { Redirect } from "react-router-dom"; + +import _auth from '@netuno/auth-client'; + +import _service from '@netuno/service-client'; + +import { Button, notification } from 'antd'; + +import Item from "./Item"; + +import "./index.less"; + +export default ()=> { + const [loading, setLoading] = useState(false); + const [communities, setCommunities] = useState([]); + if (!_auth.isLogged()) { + return ; + } + useEffect(()=> { + _service({ + url: "api/communities", + success: (response) => { + setCommunities(response.json); + }, + fail: (e) => { + console.log("Service Error", e); + notification["error"]({ + message: 'Informações', + description: 'Não foi possível carregar a informação.', + }); + } + }); + }, []); + const servicePrefix = _service.config().prefix; + return ( +
    +

    Comunidades...

    {servicePrefix} +
      + { communities.length > 0 && communities.map( + (community) => { + return ; + } + ) } +
    +
    + ); +}; diff --git a/website/src/pages/Communities/index.less b/website/src/pages/Communities/index.less new file mode 100644 index 0000000..fff6d62 --- /dev/null +++ b/website/src/pages/Communities/index.less @@ -0,0 +1,18 @@ + +.communities { + &__list { + list-style: none; + padding: 0; + margin: 0; + > li { + background-size: cover; + background-repeat: no-repeat; + background-position: 50% 50%; + height: 300px; + h1 { + background-color: rgba(0, 0, 0, 0.75); + padding: 10px; + } + } + } +}