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

[FEATURE] Pouvoir souscrire à un calendrier avec les évènements. #1

Merged
merged 16 commits into from
Sep 25, 2024
Merged
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
ci:
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm test
env:
NODE_ENV: test
TEST_DATABASE_API_URL: postgres://postgres:postgres@localhost:5432/test
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Voici les différentes étapes pour pouvoir préparer correctement sa venue :

![Les différentes étapes de réservation](./docs/étapes-reservation.png)

Le projet est composé actuellement de 3 grandes étapes :
Le projet est composé actuellement de 4 grandes étapes :

1. Vérifier qu'une nouvelle réservation a été demandée sur Gymlib
2. Remplir le formulaire de contremarque UCPA
3. Recevoir une notification dès que l'UCPA a validé les informations avec des créneaux arrangeants qui sont disponibles
4. Créer des évènements dans un calendrier et proposer une url pour s'abonner au calendrier `/reservations/calendar`.

A venir :

1. Créer un évènement de calendrier et créer un pass Apple Wallet
1. Créer un pass Apple Wallet pour chaque évènement
2. Me notifier de créneaux qui m'arrangent qui se libèrent

La réservation du créneau se fait donc toujours manuellement sur le site de l'UCPA, mais toutes les étapes contraignantes
Expand Down
27 changes: 21 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ function isFeatureEnabled(environmentVariable) {
return environmentVariable === 'true';
}

function getParsedJson(environmentVariable) {
if (environmentVariable === undefined) {
return undefined;
}
return JSON.parse(environmentVariable);
}

function buildConfiguration() {
const config = {
environment: env.NODE_ENV || 'development',
port: env.PORT || 3000,
logging: {
enabled: isFeatureEnabled(env.LOG_ENABLED),
logLevel: env.LOG_LEVEL || 'info',
Expand All @@ -21,7 +29,7 @@ function buildConfiguration() {
user: env.GYMLIB_MAIL_RECEIVER_IMAP_USER,
password: env.GYMLIB_MAIL_RECEIVER_IMAP_PASSWORD,
},
searchQuery: JSON.parse(env.GYMLIB_MAIL_RECEIVER_IMAP_SEARCH_QUERY),
searchQuery: getParsedJson(env.GYMLIB_MAIL_RECEIVER_IMAP_SEARCH_QUERY),
},
ucpa: {
imapConfig: {
Expand All @@ -30,16 +38,19 @@ function buildConfiguration() {
user: env.UCPA_MAIL_RECEIVER_IMAP_USER,
password: env.UCPA_MAIL_RECEIVER_IMAP_PASSWORD,
},
searchQuery: JSON.parse(env.UCPA_MAIL_RECEIVER_IMAP_SEARCH_QUERY),
formInfo: JSON.parse(env.FORM_RESPONSE),
searchQuery: getParsedJson(env.UCPA_MAIL_RECEIVER_IMAP_SEARCH_QUERY),
formInfo: getParsedJson(env.FORM_RESPONSE),
formSubmit: isFeatureEnabled(env.FORM_SUBMIT_ENABLED),
areaId: env.UCPA_AREA_ID,
},
notification: {
url: env.NOTFICATION_URL,
token: env.NOTFICATION_TOKEN,
url: env.NOTIFICATION_URL,
token: env.NOTIFICATION_TOKEN,
},
timeSlotsPreferences: JSON.parse(env.TIME_SLOTS_PREFERENCES),
calendar: {
name: env.CALENDAR_NAME,
},
timeSlotsPreferences: getParsedJson(env.TIME_SLOTS_PREFERENCES),
};
if (config.environment === 'test') {
config.logging.enabled = false;
Expand All @@ -52,6 +63,10 @@ function buildConfiguration() {
}

function verifyConfig(config) {
if (env.NODE_ENV === 'test') {
return true;
}

let allKeysHaveValues = true;

function checkDeep(object, path) {
Expand Down
28 changes: 28 additions & 0 deletions db/migrations/20240924193919_add_start_at_and_court_column.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
const up = async function (knex) {
await knex.schema.alterTable('reservations', (table) => {
table.dateTime('start_at').nullable();
table.string('court').nullable();
table.string('activity').nullable();
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
const down = async function (knex) {
await knex.schema.alterTable('reservations', (table) => {
table.dropColumn('start_at');
table.dropColumn('court');
table.dropColumn('activity');
});
};

export {
down,
up,
};
Empty file added db/seeds/.gitkeep
Empty file.
33 changes: 29 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import { CronJob } from 'cron';

import { config } from './config.js';

import { createServer } from './server.js';
import { ReservationController } from './src/application/ReservationController.js';
import { CreateReservationEventsUseCase } from './src/domain/usecases/CreateReservationEventsUseCase.js';
import { GetActiveReservationsUseCase } from './src/domain/usecases/GetActiveReservationsUseCase.js';
import { GetAllEventsUseCase } from './src/domain/usecases/GetAllEventsUseCase.js';
import { HandleNewReservationUseCase } from './src/domain/usecases/HandleNewReservationUseCase.js';
import { HandleScheduledReservationUseCase } from './src/domain/usecases/HandleScheduledReservationUseCase.js';
import { NotifyUseCase } from './src/domain/usecases/NotifyUseCase.js';
import { SubmitFormUseCase } from './src/domain/usecases/SubmitFormUseCase.js';
import { Browser } from './src/infrastructure/Browser.js';
import { CalendarRepository } from './src/infrastructure/CalendarRepository.js';
import { ImapClient } from './src/infrastructure/ImapClient.js';
import { logger } from './src/infrastructure/logger.js';
import { NotificationClient } from './src/infrastructure/NotificationClient.js';
import { reservationRepositories } from './src/infrastructure/ReservationRepositories.js';
import { reservationRepository } from './src/infrastructure/ReservationRepository.js';
import { TimeSlotDatasource } from './src/infrastructure/TimeSlotDatasource.js';

const parisTimezone = 'Europe/Paris';
Expand All @@ -30,6 +35,8 @@ async function main() {
start: true,
timeZone: parisTimezone,
});
const server = await createServer({ reservationController });
await server.start();
}

async function getReservationController() {
Expand All @@ -40,13 +47,13 @@ async function getReservationController() {
});

const getActiveReservationsUseCase = new GetActiveReservationsUseCase({
reservationRepositories,
reservationRepository,
});

const browser = await Browser.create();
const submitFormUseCase = new SubmitFormUseCase({
browser,
reservationRepositories,
reservationRepository,
formInfo: config.ucpa.formInfo,
dryRun: !config.ucpa.formSubmit,
});
Expand All @@ -57,18 +64,36 @@ async function getReservationController() {
const notifyUseCase = new NotifyUseCase({
imapClient: ucpaImapClient,
searchQuery: config.ucpa.searchQuery,
reservationRepositories,
reservationRepository,
timeSlotDatasource,
notificationClient,
timeSlotsPreferences: config.timeSlotsPreferences,
areaId: config.ucpa.areaId,
});

const handleScheduledReservationUseCase = new HandleScheduledReservationUseCase({
imapClient: ucpaImapClient,
searchQuery: config.ucpa.searchQuery,
reservationRepository,
});

const calendarRepository = new CalendarRepository(config.calendar.name);

const createReservationEventsUseCase = new CreateReservationEventsUseCase({
reservationRepository,
calendarRepository,
});

const getAllEventsUseCase = new GetAllEventsUseCase({ calendarRepository });

return new ReservationController({
handleNewReservationUseCase,
getActiveReservationsUseCase,
submitFormUseCase,
notifyUseCase,
handleScheduledReservationUseCase,
createReservationEventsUseCase,
getAllEventsUseCase,
logger,
});
}
Loading