Skip to content
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
30 changes: 29 additions & 1 deletion backend/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const serverlessConfiguration: AwsConfig.Serverless = {
service: 'dojo-serverless-backend',
frameworkVersion: '>=1.83',
plugins: ['serverless-webpack', 'serverless-step-functions'],
configValidationMode: 'error',
provider: {
name: 'aws',
runtime: 'nodejs10.x',
Expand Down Expand Up @@ -38,6 +37,35 @@ const serverlessConfiguration: AwsConfig.Serverless = {
},
],
},
getVirus: {
handler: 'src/handlers/virus/get.main',
events: [
{
http: {
method: 'get',
path: 'virus',
cors: true,
},
},
],
},
createVirus: {
handler: 'src/handlers/virus/create.main',
events: [
/* {
schedule: 'rate(1 minute)',
je l'ai commentée car sinon elle va tourner
tout le temps
}, */
{
http: {
method: 'post', // pour l'instant elle ne poste rien dans la session 1
path: 'virus',
cors: true,
},
},
],
},
},
resources: {
Resources: {
Expand Down
8 changes: 8 additions & 0 deletions backend/src/handlers/virus/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { APIGatewayProxyHandler } from 'aws-lambda';

import { success } from '@libs/response';

export const main: APIGatewayProxyHandler = async event => {
console.log(event);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu peux retirer le console.log

return success({});
};
29 changes: 29 additions & 0 deletions backend/src/handlers/virus/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { APIGatewayProxyHandler } from 'aws-lambda';
import uuid from 'uuid';

import { success } from '@libs/response';


export const main: APIGatewayProxyHandler = async (event) => {
/*
La fonction doit générer 1 virus si un id est passé en query param

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de base les commentaires, c'est pas ouf, mieux vaut les retirer.
Si le code a besoin de commentaires, c'est qu'il n'est pas assez découpé ou que le nom des variables n'est pas assez clair :)

Sinon elle en génère 4
*/
let viruses = [{}]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialise le seulement avec une liste vide non ?
et type ton tableau, ex: let viruses: Virus[] = [] où Virus est un type {id: string}

if (event.queryStringParameters) {
if (event.queryStringParameters.id) {
viruses = [
{ id: uuid() },
];
} else {
viruses = [
{ id: uuid() },
{ id: uuid() },
{ id: uuid() },
{ id: uuid() }
];
}
}

return success({ viruses });
};
23 changes: 14 additions & 9 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Typography, Row, Button } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import styled from 'styled-components';
import { v4 } from 'uuid';

import { useAsync } from 'react-use';
import virus1 from 'assets/Virus1.png';
import virus2 from 'assets/Virus2.png';
import virus3 from 'assets/Virus3.png';
Expand Down Expand Up @@ -51,22 +51,27 @@ const Virus = styled.img<VirusProps>`

const getRandomPosition = (n: number) => Math.floor(Math.random() * n);

const getRandomVirus = () => ({
id: v4(),
const getRandomVirus = (id: string) => ({
id,
positionX: getRandomPosition(100),
positionY: getRandomPosition(100),
src: VirusImgs[getRandomPosition(6)],
});

export default () => {
const [viruses, setViruses] = useState<VirusProps[]>([
getRandomVirus(),
getRandomVirus(),
getRandomVirus(),
]);
const [viruses, setViruses] = useState<VirusProps[]>([]);

useAsync(async (id = 'TEST') => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faudra qu'on reparle ensemble en live de tout ça :) j'ai besoin d'un peu de contexte

const response = await fetch(
`${process.env.REACT_APP_API_BASE_URL}/virus?id=${encodeURIComponent(id)}`,
{ method: 'GET' },
);
const { viruses } = await response.json();
setViruses(viruses.map(({ id }: { id: string }) => getRandomVirus(id)));

});
const addVirus = () =>
setViruses((prevViruses) => prevViruses.concat(getRandomVirus()));
setViruses((prevViruses) => prevViruses.concat(getRandomVirus(v4())));

const killVirus = (virusId: string) =>
setViruses((prevViruses) => prevViruses.filter(({ id }) => id !== virusId));
Expand Down