Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/sakJH/GymNest
Browse files Browse the repository at this point in the history
  • Loading branch information
bourama1 committed Apr 23, 2024
2 parents e888db9 + a960c4e commit 1c10336
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 8 deletions.
15 changes: 15 additions & 0 deletions GymNest-IS/booking-service/src/controllers/ScheduleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ class ScheduleController {
}
}

async findAllSchedulesByRange(req, res) {
try {
const { start, end } = req.query;
let schedules;
if (start && end) {
schedules = await ScheduleService.findSchedulesByDateRange(start, end);
} else {
schedules = await ScheduleService.findAllSchedules();
}
res.json(schedules);
} catch (error) {
res.status(500).json({ message: error.message });
}
}

}

module.exports = new ScheduleController();
20 changes: 19 additions & 1 deletion GymNest-IS/booking-service/src/models/Schedule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Model, DataTypes } = require('sequelize');
const { Sequelize, Model, DataTypes } = require('sequelize');
const { Op } = require('sequelize');
const sequelize = require('../sequelize');

class Schedule extends Model {
Expand Down Expand Up @@ -62,6 +63,23 @@ class Schedule extends Model {
}
}

static async findSchedulesByDateRange(start, end) {
try {
return await this.findAll({
where: {
startTime: {
[Op.gte]: new Date(start)
},
endTime: {
[Op.lte]: new Date(end)
}
}
});
} catch (error) {
throw error;
}
}

}

Schedule.init({
Expand Down
3 changes: 3 additions & 0 deletions GymNest-IS/booking-service/src/routes/scheduleRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ router.get('/schedules/find/:scheduleId', ScheduleController.findScheduleById);
*/
router.get('/schedules/all', ScheduleController.findAllSchedules);

// Definování cesty pro získání seznamu všech harmonogramů podle zadaného rozsahu
router.get('/schedules/allByRange', ScheduleController.findAllSchedulesByRange);

module.exports = router;
9 changes: 9 additions & 0 deletions GymNest-IS/booking-service/src/services/ScheduleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class ScheduleService {
}
}

async findSchedulesByDateRange(start, end) {
try {
return await Schedule.findSchedulesByDateRange(start, end);
} catch (error) {
console.error("Error finding schedules by date range:", error);
throw error;
}
}

}

module.exports = new ScheduleService();
2 changes: 1 addition & 1 deletion GymNest-IS/frontend/src/hooks/useSchedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useSchedules(currentWeek, viewMode, setLoading, setError) {

try {
const [schedulesResponse, activitiesResponse] = await Promise.all([
axios.get(`${apiAddress}/schedules/all`, {
axios.get(`${apiAddress}/schedules/allByRange`, {
params: { start: startDate, end: endDate },
headers: { 'Authorization': `Bearer ${token}` },
}),
Expand Down
2 changes: 1 addition & 1 deletion GymNest-IS/membership-service/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function createInitialMembership(userId, typeId) {
endDate,
status: 'active'
});
console.log(`Membership created for user ID: ${userId}`);
console.log(`Membership created : ${userId}`);
return membership; // Return the created membership object for further use
} else {
console.log(`Membership already exists for user ID: ${userId}`);
Expand Down
10 changes: 5 additions & 5 deletions GymNest-IS/user-service/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ app.listen(PORT, () => {
// Synchronizace modelů s databází a nastavení asociací
sequelize.sync({ force: false }).then(() => {

createInitialUser('admin', 'Test_admin1', 'admin@email.com', 'Ada', 'admin', 4, 1000).then(r => console.log('Inicial user created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('coach', 'Test_coach1', 'coach@email.com', 'Cach', 'admin', 3, 500).then(r => console.log('Inicial user created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('member', 'Test_member1', 'member@email.com', 'Martin', 'admin', 2, 800).then(r => console.log('Inicial user created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('user', 'Test_user1', 'user@email.com', 'Usalam', 'admin', 1, 700).then(r => console.log('Inicial user created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('admin', 'Test_admin1', 'admin@email.com', 'Ada', 'Adida', 4, 1000).then(r => console.log('Inicial user "admin" was created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('coach', 'Test_coach1', 'coach@email.com', 'Cach', 'CocaCola', 3, 500).then(r => console.log('Inicial user "coach" was created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('member', 'Test_member1', 'member@email.com', 'Martin', 'Merino', 2, 800).then(r => console.log('Inicial user "member" was created')).catch(err => console.error('Failed to create inicial user:', err));
createInitialUser('user', 'Test_user1', 'user@email.com', 'Usalam', 'Upatla', 1, 700).then(r => console.log('Inicial user "user" was created')).catch(err => console.error('Failed to create inicial user:', err));
console.log('Databáze a tabulky byly synchronizovány');

}).catch(err => console.error('Při synchronizaci databáze došlo k chybě:', err));
Expand All @@ -84,7 +84,7 @@ async function createInitialUser(username, password, email, firstName, lastName,
credits
});

console.log('Initial user created:', user);
console.log('Initial user created:', username);
} else {
console.log('Initial user already exists:', username);
}
Expand Down

0 comments on commit 1c10336

Please sign in to comment.