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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
dist/
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM node:alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --omit=dev
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8081
CMD ["node", "api/server.js"]
CMD ["node", "dist/server.js"]
78 changes: 0 additions & 78 deletions api/models/Alumni.js

This file was deleted.

93 changes: 93 additions & 0 deletions api/models/Alumni.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import mongoose, { Document, Schema } from "mongoose";

export interface IExperience {
company: string;
title: string;
startDate?: Date;
endDate?: Date;
isCurrent: boolean;
description: string;
}

export interface IAlumni extends Document {
userId: string;
name: string;
bio: string;
headline: string;
linkedInUrl: string;
startYear?: number;
graduationYear?: number;
major: string;
experiences: IExperience[];
}

const ExperienceSchema = new Schema<IExperience>({
company: {
type: String,
required: true,
},
title: {
type: String,
required: true,
},
startDate: {
type: Date,
},
endDate: {
type: Date,
},
isCurrent: {
type: Boolean,
default: false,
},
description: {
type: String,
default: "",
},
});

const AlumniSchema = new Schema<IAlumni>(
{
userId: {
type: String,
required: true,
unique: true,
},
name: {
type: String,
default: "",
},
bio: {
type: String,
default: "",
},
headline: {
type: String,
default: "",
},
linkedInUrl: {
type: String,
default: "",
},
startYear: {
type: Number,
},
graduationYear: {
type: Number,
},
major: {
type: String,
default: "",
},
experiences: {
type: [ExperienceSchema],
default: [],
},
},
{
collection: "AlumniProfile",
timestamps: true,
},
);

export default mongoose.model<IAlumni>("Alumni", AlumniSchema);
28 changes: 14 additions & 14 deletions api/routes/Alumni.js → api/routes/Alumni.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
const express = require('express');
const Alumni = require('../models/Alumni');
import { Router, Request, Response } from 'express';
import Alumni from '../models/Alumni';

const router = express.Router();
const router = Router();

// List all alumni profiles
router.get('/', async (req, res) => {
router.get('/', async (req: Request, res: Response) => {
try {
const alumni = await Alumni.find();
res.json(alumni);
} catch (err) {
res.status(500).json({ error: err.message });
res.status(500).json({ error: (err as Error).message });
}
});

// Get a single alumni profile by ID
router.get('/:id', async (req, res) => {
router.get('/:id', async (req: Request, res: Response) => {
try {
const alumni = await Alumni.findById(req.params.id);
if (!alumni) return res.status(404).json({ error: 'Alumni not found' });
res.json(alumni);
} catch (err) {
res.status(500).json({ error: err.message });
res.status(500).json({ error: (err as Error).message });
}
});

// Create a new alumni profile
router.post('/', async (req, res) => {
router.post('/', async (req: Request, res: Response) => {
try {
const alumni = await new Alumni(req.body).save();
res.status(201).json(alumni);
} catch (err) {
res.status(500).json({ error: err.message });
res.status(500).json({ error: (err as Error).message });
}
});

// Update an existing alumni profile
router.put('/:id', async (req, res) => {
router.put('/:id', async (req: Request, res: Response) => {
try {
const alumni = await Alumni.findByIdAndUpdate(req.params.id, req.body, {
new: true,
Expand All @@ -44,19 +44,19 @@ router.put('/:id', async (req, res) => {
if (!alumni) return res.status(404).json({ error: 'Alumni not found' });
res.json(alumni);
} catch (err) {
res.status(500).json({ error: err.message });
res.status(500).json({ error: (err as Error).message });
}
});

// Delete an alumni profile
router.delete('/:id', async (req, res) => {
router.delete('/:id', async (req: Request, res: Response) => {
try {
const alumni = await Alumni.findByIdAndDelete(req.params.id);
if (!alumni) return res.status(404).json({ error: 'Alumni not found' });
res.json(alumni);
} catch (err) {
res.status(500).json({ error: err.message });
res.status(500).json({ error: (err as Error).message });
}
});

module.exports = router;
export default router;
23 changes: 0 additions & 23 deletions api/server.js

This file was deleted.

23 changes: 23 additions & 0 deletions api/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import express from "express";
import mongoose from "mongoose";
import alumniRouter from "./routes/Alumni";

const app = express();
const PORT = 8081;

app.use(express.json());
app.use("/api", alumniRouter);

const dbHost = process.env.DATABASE_HOST || "127.0.0.1";
mongoose
.connect(`mongodb://${dbHost}:27017/sce_linkedin`)
.then(() => {
console.log("Connected to MongoDB");
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
})
.catch((err) => {
console.error("Failed to connect to MongoDB:", err);
process.exit(1);
});
19 changes: 16 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ services:
volumes:
- alumni_mongodb_data:/data/db
ports:
- '27018:27017'
- "27018:27017"

alumni-app:
build: .
container_name: alumni-app
command: npx nodemon api/server.js
command: npx ts-node api/server.ts
environment:
- DATABASE_HOST=alumni-mongodb
- NODE_ENV=development
ports:
- '8081:8081'
- "8081:8081"
depends_on:
- alumni-mongodb
volumes:
- ./api:/app/api

alumni-frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: alumni-frontend
ports:
- "5173:5173"
depends_on:
- alumni-app
volumes:
- ./frontend/src:/app/src
- ./frontend/index.html:/app/index.html

volumes:
alumni_mongodb_data:
24 changes: 24 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
7 changes: 7 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5173
CMD ["npm", "run", "dev"]
Loading