Skip to content

Justine dash 2 #12

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

Merged
merged 4 commits into from
Apr 22, 2025
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
92 changes: 91 additions & 1 deletion backend/controllers/dashboard.controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
import { client } from '../server.js';

export async function getCompanyFlights(req, res) {}
export async function getCompanyFlights(req, res) {
const { company_id } = req.params;

try {
const query = {
text: `
SELECT f.*, c.company_name
FROM Flight f
JOIN FlightCompany_Offers_Flight fcof ON f.ServiceType_Id = fcof.ServiceType_Id
JOIN Company c ON fcof.Company_Id = c.Company_Id
WHERE c.Company_Id = $1
`,
values: [company_id],
};

const result = await client.query(query);
res.json(result.rows);
} catch (err) {
console.error('Error fetching company flights:', err);
res.status(500).json({ error: 'Failed to fetch company flights' });
}
}

export async function getCompanyBuses(req, res) {
const { company_id } = req.params;

try {
const query = {
text: `
SELECT b.*, c.company_name
FROM Bus b
JOIN BusCompany_Offers_Bus bcob ON b.ServiceType_Id = bcob.ServiceType_Id
JOIN Company c ON bcob.Company_Id = c.Company_Id
WHERE c.Company_Id = $1
`,
values: [company_id],
};

const result = await client.query(query);
res.json(result.rows);
} catch (err) {
console.error('Error fetching company buses:', err);
res.status(500).json({ error: 'Failed to fetch company buses' });
}
}

export async function getCompanyHotelRooms(req, res) {
const { company_id } = req.params;

try {
const query = {
text: `
SELECT h.*, c.company_name
FROM HotelRoom h
JOIN HotelCompany_Offers_HotelRoom hcoh ON h.ServiceType_Id = hcoh.ServiceType_Id
JOIN Company c ON hcoh.Company_Id = c.Company_Id
WHERE c.Company_Id = $1
`,
values: [company_id],
};

const result = await client.query(query);
res.json(result.rows);
} catch (err) {
console.error('Error fetching company hotel rooms:', err);
res.status(500).json({ error: 'Failed to fetch company hotel rooms' });
}
}

export async function getCompanyActivities(req, res) {
const { company_id } = req.params;

try {
const query = {
text: `
SELECT a.*, c.company_name
FROM Activity a
JOIN ActivityCompany_Offers_Activity acoa ON a.ServiceType_Id = acoa.ServiceType_Id
JOIN Company c ON acoa.Company_Id = c.Company_Id
WHERE c.Company_Id = $1
`,
values: [company_id],
};

const result = await client.query(query);
res.json(result.rows);
} catch (err) {
console.error('Error fetching company activities:', err);
res.status(500).json({ error: 'Failed to fetch company activities' });
}
}
2 changes: 1 addition & 1 deletion backend/routes/company.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

const router = express.Router();

router.get('/:company_id', getCompanyDetails);
router.get('/companies/:company_id', getCompanyDetails);
router.post('/auth/company/login', loginCompany);
router.post('/auth/company/signup', signupCompany);

Expand Down
21 changes: 19 additions & 2 deletions backend/routes/dashboard.routes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import { Router } from 'express';
import { getCompanyFlights } from '../controllers/dashboard.controller.js';
import {
getCompanyFlights,
getCompanyBuses,
getCompanyHotelRooms,
getCompanyActivities,
} from '../controllers/dashboard.controller.js';

const dashboardRouter = Router();

dashboardRouter.get(
'/company/dashboard/flights/:company_id',
'/dashboard/company/:company_id/flights',
getCompanyFlights
);

dashboardRouter.get('/dashboard/company/:company_id/buses', getCompanyBuses);

dashboardRouter.get(
'/dashboard/company/:company_id/hotel-rooms',
getCompanyHotelRooms
);

dashboardRouter.get(
'/dashboard/company/:company_id/activities',
getCompanyActivities
);

export default dashboardRouter;
176 changes: 176 additions & 0 deletions frontend/src/api/dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
const API_BASE_URL = 'http://localhost:8080/api';

export interface Flight {
servicetype_id: number;
departure_city: string;
arrival_city: string;
departure_time: string;
arrival_time: string;
flightclassoptions: string;
flight_price: number;
company_name: string;
}

export interface Bus {
servicetype_id: number;
departure_city: string;
arrival_city: string;
departure_time: string;
arrival_time: string;
seats_available: number;
capacity: number;
bus_price: number;
amenities: string;
company_name: string;
}

export interface HotelRoom {
servicetype_id: number;
room_number: string;
room_type: string;
check_in_time: string;
check_out_time: string;
price: number;
bed_type: string;
city: string;
capacity: number;
amenities: string;
floor_number: number;
status: string;
company_name: string;
}

export interface Activity {
servicetype_id: number;
description: string;
price: number;
capacity: number;
age_restriction: boolean;
start_time: string;
end_time: string;
signups: number;
city: string;
company_name: string;
}

// GET functions
export async function getCompanyFlights(companyId: number): Promise<Flight[]> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/flights`
);
if (!response.ok) {
throw new Error('Failed to fetch flights');
}
return response.json();
}

export async function getCompanyBuses(companyId: number): Promise<Bus[]> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/buses`
);
if (!response.ok) {
throw new Error('Failed to fetch buses');
}
return response.json();
}

export async function getCompanyHotelRooms(
companyId: number
): Promise<HotelRoom[]> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/hotel-rooms`
);
if (!response.ok) {
throw new Error('Failed to fetch hotel rooms');
}
return response.json();
}

export async function getCompanyActivities(
companyId: number
): Promise<Activity[]> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/activities`
);
if (!response.ok) {
throw new Error('Failed to fetch activities');
}
return response.json();
}

// POST functions
export async function addCompanyFlight(
companyId: number,
flightData: Omit<Flight, 'servicetype_id'>
): Promise<void> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/flights`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(flightData),
}
);
if (!response.ok) {
throw new Error('Failed to add flight');
}
}

export async function addCompanyBus(
companyId: number,
busData: Omit<Bus, 'servicetype_id'>
): Promise<void> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/buses`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(busData),
}
);
if (!response.ok) {
throw new Error('Failed to add bus');
}
}

export async function addCompanyHotelRoom(
companyId: number,
hotelRoomData: Omit<HotelRoom, 'servicetype_id'>
): Promise<void> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/hotel-rooms`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(hotelRoomData),
}
);
if (!response.ok) {
throw new Error('Failed to add hotel room');
}
}

export async function addCompanyActivity(
companyId: number,
activityData: Omit<Activity, 'servicetype_id'>
): Promise<void> {
const response = await fetch(
`${API_BASE_URL}/dashboard/company/${companyId}/activities`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(activityData),
}
);
if (!response.ok) {
throw new Error('Failed to add activity');
}
}
Loading