Skip to content

Commit

Permalink
Merge pull request #4 from asozialdotdev/folder-structure
Browse files Browse the repository at this point in the history
Folder structure
  • Loading branch information
benjamindotdev authored Sep 13, 2024
2 parents 93dedc2 + 4d29c96 commit d5e13f8
Show file tree
Hide file tree
Showing 88 changed files with 3,288 additions and 3,085 deletions.
20 changes: 10 additions & 10 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import express from "express";
import "./db";

import dashboardRouter from "./routes/index";
import usersRouter from "./routes/Users.routes";
import projectsRouter from "./routes/Projects.routes";
import projectPostRouter from "./routes/ProjectPosts.routes";
import projectPostReplyRouter from "./routes/ProjectPostReply.routes";
import usersRouter from "./routes/Users";
import projectsRouter from "./routes/Projects";
import projectPostRouter from "./routes/ProjectsPosts";
import projectPostReplyRouter from "./routes/ProjectsPostsReply";
import githubRouter from "./routes/Auth.routes";
import friendshipsRouter from "./routes/Friendship.routes";
import userPostsRouter from "./routes/UserPosts.routes";
import messagesRouter from "./routes/Messages.routes";
import fileRouter from "./routes/FileUploader.routes";
import searchRouter from "./routes/Search.routes";
import matchRouter from "./routes/Match.routes";
import friendshipsRouter from "./routes/Friendship";
import userPostsRouter from "./routes/UserPosts";
import messagesRouter from "./routes/Messages";
import fileRouter from "./routes/FileUploader";
import searchRouter from "./routes/Search";
import matchRouter from "./routes/Match";

const app = express();
config(app);
Expand Down
58 changes: 0 additions & 58 deletions backend/src/routes/FileUploader.routes/index.ts

This file was deleted.

16 changes: 16 additions & 0 deletions backend/src/routes/FileUploader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import express, { Request, Response, NextFunction } from "express";
import fileUploader from "../../config/cloudinary.config";
import { uploadImage } from "./uploadImage";
import { updateUserImage } from "./updateUserImage";

const fileRouter = express.Router();

fileRouter.post("/upload-image", fileUploader.single("imageUrl"), uploadImage);

fileRouter.put(
"/upload-image",
fileUploader.single("imageUrl"),
updateUserImage
);

export default fileRouter;
30 changes: 30 additions & 0 deletions backend/src/routes/FileUploader/updateUserImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Request, Response, NextFunction } from "express";
import User from "../../models/User.models";

export const updateUserImage = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
if (!req.file) {
return res.status(400).json({ error: "No file uploaded" });
}

const user = await User.findByIdAndUpdate(
req.body.userId,
{
image: req.file.path,
},
{ new: true }
);

res.json(user);
} catch (error: any) {
console.error("Update image error:", error);

res
.status(500)
.json({ error: error.message || "An unknown error occurred" });
}
};
24 changes: 24 additions & 0 deletions backend/src/routes/FileUploader/uploadImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Request, Response, NextFunction } from "express";

export const uploadImage = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
if (!req.file) {
return res.status(400).json({ error: "No file uploaded" });
}

res.status(200).json({
message: "File uploaded successfully",
url: req.file.path,
});
} catch (error: any) {
console.error("Upload error:", error);

res
.status(500)
.json({ error: error.message || "An unknown error occurred" });
}
};
Loading

0 comments on commit d5e13f8

Please sign in to comment.