Browse Source

Sessão 14

master
eduveks 5 years ago
parent
commit
cc0faba694
16 changed files with 268 additions and 8 deletions
  1. +18
    -8
      config/_development.json
  2. BIN
      dbs/social_ma.mv.db
  3. +11
    -0
      server/core/social/userPessoa.js
  4. +2
    -0
      server/services/api/communities/follow.options.js
  5. +12
    -0
      server/services/api/communities/follow.put.js
  6. +24
    -0
      server/services/api/communities/get.js
  7. +10
    -0
      server/services/api/communities/image.get.js
  8. +2
    -0
      server/services/api/communities/options.js
  9. +3
    -0
      server/services/test-antiga.js
  10. +30
    -0
      server/setup/002-cidades.js
  11. +40
    -0
      server/setup/003-comunidades.js
  12. +7
    -0
      website/src/App.js
  13. +34
    -0
      website/src/pages/Communities/Item/index.js
  14. +8
    -0
      website/src/pages/Communities/Item/index.less
  15. +49
    -0
      website/src/pages/Communities/index.js
  16. +18
    -0
      website/src/pages/Communities/index.less

+ 18
- 8
config/_development.json View File

@ -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,


BIN
dbs/social_ma.mv.db View File


+ 11
- 0
server/core/social/userPessoa.js View File

@ -0,0 +1,11 @@
const userPessoa = ()=> {
const dbPessoa = _db.queryFirst(
`
SELECT *
FROM pessoa
WHERE usuario_id = ?
`, _user.id()
)
return dbPessoa
}

+ 2
- 0
server/services/api/communities/follow.options.js View File

@ -0,0 +1,2 @@
_out.json(_val.map().set("result", true))

+ 12
- 0
server/services/api/communities/follow.put.js View File

@ -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))

+ 24
- 0
server/services/api/communities/get.js View File

@ -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)

+ 10
- 0
server/services/api/communities/image.get.js View File

@ -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())
}

+ 2
- 0
server/services/api/communities/options.js View File

@ -0,0 +1,2 @@
_out.json(_val.map().set("result", true))

+ 3
- 0
server/services/test-antiga.js View File

@ -0,0 +1,3 @@
const dbAntiga = _db.init("antiga")
_out.json(dbAntiga.query("select * from cidade"))

+ 30
- 0
server/setup/002-cidades.js View File

@ -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")
);

+ 40
- 0
server/setup/003-comunidades.js View File

@ -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", "<p>Pedalada de bicicleta no mato, na cidade e na praia!</p>")
.set("imagem", "btt-chapada-mesa-cvVKi0a6.jpg")
);

+ 7
- 0
website/src/App.js View File

@ -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() {
<Menu.Item>
<Link to="/main">Principal</Link>
</Menu.Item>
<Menu.Item>
<Link to="/communities">Comunidades</Link>
</Menu.Item>
</>;
} else {
menu = <>
@ -85,6 +89,9 @@ function App() {
<Route path="/register">
<Register />
</Route>
<Route path="/communities">
<Communities />
</Route>
<Route path="/main">
<Main />
</Route>


+ 34
- 0
website/src/pages/Communities/Item/index.js View File

@ -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 (
<li style={{ backgroundImage: `url(${ servicePrefix }/api/communities/image?uid=${ data.uid })` }}>
<h1>{ data.name } <Button type="link" onClick={onFollow}>Seguir</Button></h1>
</li>
);
};

+ 8
- 0
website/src/pages/Communities/Item/index.less View File

@ -0,0 +1,8 @@
.communities {
&__list {
list-style: none;
padding: 0;
margin: 0;
}
}

+ 49
- 0
website/src/pages/Communities/index.js View File

@ -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 <Redirect to="/login" />;
}
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 (
<div className="communities">
<h1>Comunidades...</h1>{servicePrefix}
<ul className="communities__list">
{ communities.length > 0 && communities.map(
(community) => {
return <Item data={ community }/>;
}
) }
</ul>
</div>
);
};

+ 18
- 0
website/src/pages/Communities/index.less View File

@ -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;
}
}
}
}

Loading…
Cancel
Save