Changed controllers to classes, added image functionality

This commit is contained in:
Torsten Schulz
2024-09-21 15:26:29 +02:00
parent e494fe41db
commit f1b6dd74f7
20 changed files with 836 additions and 581 deletions

View File

@@ -1,79 +1,94 @@
import AdminService from '../services/adminService.js';
import Joi from 'joi';
export const getOpenInterests = async (req, res) => {
try {
const { userid: userId} = req.headers;
const openInterests = await AdminService.getOpenInterests(userId);
res.status(200).json(openInterests);
} catch (error) {
res.status(403).json({error: error.message });
class AdminController {
constructor() {
this.getOpenInterests = this.getOpenInterests.bind(this);
this.changeInterest = this.changeInterest.bind(this);
this.deleteInterest = this.deleteInterest.bind(this);
this.changeTranslation = this.changeTranslation.bind(this);
this.getOpenContacts = this.getOpenContacts.bind(this);
this.answerContact = this.answerContact.bind(this);
}
}
export const changeInterest = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { id: interestId, active, adult: adultOnly} = req.body;
AdminService.changeInterest(userId, interestId, active, adultOnly);
res.status(200).json(AdminService.getOpenInterests(userId));
} catch (error) {
res.status(403).json({ error: error.message });
}
}
export const deleteInterest = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { id: interestId } = req.params;
AdminService.deleteInterest(userId, interestId);
res.status(200).json(AdminService.getOpenInterests(userId));
} catch (error) {
res.status(403).json({ error: error.message });
}
}
export const changeTranslation = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { id: interestId, translations } = req.body;
AdminService.changeTranslation(userId, interestId, translations);
res.status(200).json(AdminService.getOpenInterests(userId))
} catch(error) {
res.status(403).json({ error: error.message });
}
}
export const getOpenContacts = async (req, res) => {
try {
const { userid: userId } = req.headers;
const openContacts = await AdminService.getOpenContacts(userId);
res.status(200).json(openContacts);
} catch (error) {
res.status(403).json({ error: error.message });
}
}
export const answerContact = async (req, res) => {
try {
const schema = Joi.object({
id: Joi.number().integer().required(),
answer: Joi.string().min(1).required()
});
const { error, value } = schema.validate(req.body);
if (error) {
return res.status(400).json({ error: error.details[0].message });
async getOpenInterests(req, res) {
try {
const { userid: userId } = req.headers;
const openInterests = await AdminService.getOpenInterests(userId);
res.status(200).json(openInterests);
} catch (error) {
res.status(403).json({ error: error.message });
}
const { id, answer } = value;
await AdminService.answerContact(id, answer);
res.status(200).json({ status: 'ok' });
} catch (error) {
console.error('Error in answerContact:', error);
res.status(error.status || 500).json({ error: error.message || 'Internal Server Error' });
}
};
async changeInterest(req, res) {
try {
const { userid: userId } = req.headers;
const { id: interestId, active, adult: adultOnly } = req.body;
await AdminService.changeInterest(userId, interestId, active, adultOnly);
const updatedInterests = await AdminService.getOpenInterests(userId);
res.status(200).json(updatedInterests);
} catch (error) {
res.status(403).json({ error: error.message });
}
}
async deleteInterest(req, res) {
try {
const { userid: userId } = req.headers;
const { id: interestId } = req.params;
await AdminService.deleteInterest(userId, interestId);
const updatedInterests = await AdminService.getOpenInterests(userId);
res.status(200).json(updatedInterests);
} catch (error) {
res.status(403).json({ error: error.message });
}
}
async changeTranslation(req, res) {
try {
const { userid: userId } = req.headers;
const { id: interestId, translations } = req.body;
await AdminService.changeTranslation(userId, interestId, translations);
const updatedInterests = await AdminService.getOpenInterests(userId);
res.status(200).json(updatedInterests);
} catch (error) {
res.status(403).json({ error: error.message });
}
}
async getOpenContacts(req, res) {
try {
const { userid: userId } = req.headers;
const openContacts = await AdminService.getOpenContacts(userId);
res.status(200).json(openContacts);
} catch (error) {
res.status(403).json({ error: error.message });
}
}
async answerContact(req, res) {
try {
const schema = Joi.object({
id: Joi.number().integer().required(),
answer: Joi.string().min(1).required(),
});
const { error, value } = schema.validate(req.body);
if (error) {
return res.status(400).json({ error: error.details[0].message });
}
const { id, answer } = value;
await AdminService.answerContact(id, answer);
res.status(200).json({ status: 'ok' });
} catch (error) {
console.error('Error in answerContact:', error);
res.status(error.status || 500).json({ error: error.message || 'Internal Server Error' });
}
}
}
export default AdminController;

View File

@@ -1,49 +1,57 @@
import * as userService from '../services/authService.js';
export const register = async (req, res) => {
const { email, username, password, language } = req.body;
try {
const result = await userService.registerUser({ email, username, password, language });
res.status(201).json(result);
} catch (error) {
console.log(error);
res.status(500).json({ error: error.message });
class AuthController {
constructor() {
this.register = this.register.bind(this);
this.login = this.login.bind(this);
this.forgotPassword = this.forgotPassword.bind(this);
this.activateAccount = this.activateAccount.bind(this);
}
};
export const login = async (req, res) => {
const { username, password } = req.body;
try {
const result = await userService.loginUser({ username, password });
res.status(200).json(result);
} catch (error) {
if (error.message === 'credentialsinvalid') {
res.status(404).json({ error: error.message })
} else {
async register(req, res) {
const { email, username, password, language } = req.body;
try {
const result = await userService.registerUser({ email, username, password, language });
res.status(201).json(result);
} catch (error) {
console.log(error);
res.status(500).json({ error: error.message });
}
}
};
export const forgotPassword = async (req, res) => {
const { email } = req.body;
try {
const result = await userService.handleForgotPassword({ email });
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
async login(req, res) {
const { username, password } = req.body;
try {
const result = await userService.loginUser({ username, password });
res.status(200).json(result);
} catch (error) {
if (error.message === 'credentialsinvalid') {
res.status(404).json({ error: error.message });
} else {
res.status(500).json({ error: error.message });
}
}
}
};
export const activateAccount = async (req, res) => {
const { token } = req.body;
try {
const result = await userService.activateUserAccount({ token });
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
async forgotPassword(req, res) {
const { email } = req.body;
try {
const result = await userService.handleForgotPassword({ email });
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
};
async activateAccount(req, res) {
const { token } = req.body;
try {
const result = await userService.activateUserAccount({ token });
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
}
export default AuthController;

View File

@@ -1,43 +1,85 @@
import { getMessages as getMessagesService, findMatch, registerUser as registerUserService, addMessage, endChat } from '../services/chatService.js';
import {
getMessages as getMessagesService,
findMatch,
registerUser as registerUserService,
addMessage,
endChat,
removeUser as removeUserService
} from '../services/chatService.js';
export const getMessages = (req, res) => {
const { to, from } = req.body;
const messages = getMessagesService(to, from);
res.status(200).json(messages);
};
export const findRandomChatMatch = (req, res) => {
const { genders, age, id } = req.body;
const match = findMatch(genders, age, id);
if (match) {
res.status(200).json({ status: 'matched', user: match });
} else {
res.status(200).json({ status: 'waiting' });
class ChatController {
constructor() {
this.getMessages = this.getMessages.bind(this);
this.findRandomChatMatch = this.findRandomChatMatch.bind(this);
this.registerUser = this.registerUser.bind(this);
this.sendMessage = this.sendMessage.bind(this);
this.stopChat = this.stopChat.bind(this);
this.removeUser = this.removeUser.bind(this);
}
};
export const registerUser = (req, res) => {
const { gender, age } = req.body;
const userId = registerUserService(gender, age);
res.status(200).json({ id: userId });
};
async getMessages(req, res) {
const { to, from } = req.body;
try {
const messages = await getMessagesService(to, from);
res.status(200).json(messages);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
export const sendMessage = (req, res) => {
const from = req.body.from;
const to = req.body.to;
const text = req.body.text;
const message = addMessage(from, to, text);
res.status(200).json(message);
};
async findRandomChatMatch(req, res) {
const { genders, age, id } = req.body;
try {
const match = await findMatch(genders, age, id);
if (match) {
res.status(200).json({ status: 'matched', user: match });
} else {
res.status(200).json({ status: 'waiting' });
}
} catch (error) {
res.status(500).json({ error: error.message });
}
}
export const removeUser = (req, res) => {
const { id } = req.body;
removeUserService(id);
res.sendStatus(200);
};
async registerUser(req, res) {
const { gender, age } = req.body;
try {
const userId = await registerUserService(gender, age);
res.status(200).json({ id: userId });
} catch (error) {
res.status(500).json({ error: error.message });
}
}
export const stopChat = (req, res) => {
const { id } = req.body;
endChat(id);
res.sendStatus(200);
}
async sendMessage(req, res) {
const { from, to, text } = req.body;
try {
const message = await addMessage(from, to, text);
res.status(200).json(message);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async removeUser(req, res) {
const { id } = req.body;
try {
await removeUserService(id);
res.sendStatus(200);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async stopChat(req, res) {
const { id } = req.body;
try {
await endChat(id);
res.sendStatus(200);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
}
export default ChatController;

View File

@@ -1,11 +1,19 @@
import ContactService from '../services/ContactService.js';
export const addContactMessage = async(req, res) => {
try {
const { email, name, message, acceptDataSave } = req.body;
await ContactService.addContactMessage(email, name, message, acceptDataSave);
res.status(200).json({ status: 'ok' });
} catch (error) {
res.status(409).json({ error: error });
class ContactController {
constructor() {
this.addContactMessage = this.addContactMessage.bind(this);
}
}
async addContactMessage(req, res) {
try {
const { email, name, message, acceptDataSave } = req.body;
await ContactService.addContactMessage(email, name, message, acceptDataSave);
res.status(200).json({ status: 'ok' });
} catch (error) {
res.status(409).json({ error: error.message });
}
}
}
export default ContactController;

View File

@@ -2,7 +2,7 @@ import User from '../models/community/user.js';
import UserParam from '../models/community/user_param.js';
import UserRight from '../models/community/user_right.js';
import UserRightType from '../models/type/user_right.js';
import UserParamType from '../models/type/user_param.js';
import UserParamType from '../models/type/user_param.js';
const menuStructure = {
home: {
@@ -14,7 +14,7 @@ const menuStructure = {
friends: {
visible: ["all"],
children: {
manageFriends : {
manageFriends: {
visible: ["all"],
path: "/socialnetwork/friends",
icon: "friends24.png"
@@ -70,7 +70,7 @@ const menuStructure = {
visible: ["over12"],
action: "openRanomChat"
}
}
}
},
falukant: {
visible: ["all"],
@@ -220,75 +220,74 @@ const menuStructure = {
}
};
const calculateAge = (birthDate) => {
const today = new Date();
const birthDateObj = new Date(birthDate);
let age = today.getFullYear() - birthDateObj.getFullYear();
const monthDiff = today.getMonth() - birthDateObj.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDateObj.getDate())) {
age--;
class NavigationController {
constructor() {
this.menu = this.menu.bind(this);
}
return age;
};
calculateAge(birthDate) {
const today = new Date();
const birthDateObj = new Date(birthDate);
let age = today.getFullYear() - birthDateObj.getFullYear();
const monthDiff = today.getMonth() - birthDateObj.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDateObj.getDate())) {
age--;
}
return age;
}
const filterMenu = (menu, rights, age) => {
const filteredMenu = {};
for (const [key, value] of Object.entries(menu)) {
if (value.visible.includes("all")
|| value.visible.some(v => rights.includes(v)
|| (value.visible.includes("anyadmin") && rights.length > 0))
|| (value.visible.includes("over14") && age >= 14)) {
const { visible, ...itemWithoutVisible } = value;
filteredMenu[key] = { ...itemWithoutVisible };
if (value.children) {
filteredMenu[key].children = filterMenu(value.children, rights, age);
filterMenu(menu, rights, age) {
const filteredMenu = {};
for (const [key, value] of Object.entries(menu)) {
if (value.visible.includes("all")
|| value.visible.some(v => rights.includes(v)
|| (value.visible.includes("anyadmin") && rights.length > 0))
|| (value.visible.includes("over14") && age >= 14)) {
const { visible, ...itemWithoutVisible } = value;
filteredMenu[key] = { ...itemWithoutVisible };
if (value.children) {
filteredMenu[key].children = this.filterMenu(value.children, rights, age);
}
}
}
return filteredMenu;
}
return filteredMenu;
};
export const menu = async (req, res) => {
try {
const { userid } = req.params;
const user = await User.findOne({ where: { hashedId: userid } });
if (!user) {
return res.status(404).json({ error: 'User not found' });
}
const userRights = await UserRight.findAll({
where: { userId: user.id },
include: [{
model: UserRightType,
as: 'rightType',
required: false
}]
});
const userBirthdateParams = await UserParam.findAll({
where: {
userId: user.id
},
include: [
{
model: UserParamType,
as: 'paramType',
where: {
description: 'birthdate'
async menu(req, res) {
try {
const { userid } = req.params;
const user = await User.findOne({ where: { hashedId: userid } });
if (!user) {
return res.status(404).json({ error: 'User not found' });
}
const userRights = await UserRight.findAll({
where: { userId: user.id },
include: [{
model: UserRightType,
as: 'rightType',
required: false
}]
});
const userBirthdateParams = await UserParam.findAll({
where: { userId: user.id },
include: [
{
model: UserParamType,
as: 'paramType',
where: { description: 'birthdate' }
}
}
]
});
const ageFunction = function() {
]
});
const birthDate = userBirthdateParams.length > 0 ? userBirthdateParams[0].value : (new Date()).toDateString();
const age = calculateAge(birthDate);
return age;
const age = this.calculateAge(birthDate);
const rights = userRights.map(ur => ur.rightType.title);
const filteredMenu = this.filterMenu(menuStructure, rights, age);
res.status(200).json(filteredMenu);
} catch (error) {
console.error('Error fetching menu:', error);
res.status(500).json({ error: 'An error occurred while fetching the menu' });
}
const age = ageFunction();
const rights = userRights.map(ur => ur.rightType.title);
const filteredMenu = filterMenu(menuStructure, rights, age);
res.status(200).json(filteredMenu);
} catch (error) {
console.error('Error fetching menu:', error);
res.status(500).json({ error: 'An error occurred while fetching the menu' });
}
};
}
export default NavigationController;

View File

@@ -1,157 +1,161 @@
import settingsService from '../services/settingsService.js';
export const filterSettings = async (req, res) => {
const { userid, type } = req.body;
try {
const responseFields = await settingsService.filterSettings(userid, type);
res.status(200).json(responseFields);
} catch (error) {
console.error('Error filtering settings:', error);
res.status(500).json({ error: 'An error occurred while filtering the settings' });
class SettingsController {
async filterSettings(req, res) {
const { userid, type } = req.body;
try {
const responseFields = await settingsService.filterSettings(userid, type);
res.status(200).json(responseFields);
} catch (error) {
console.error('Error filtering settings:', error);
res.status(500).json({ error: 'An error occurred while filtering the settings' });
}
}
};
export const updateSetting = async (req, res) => {
const { userid, settingId, value } = req.body;
try {
await settingsService.updateSetting(userid, settingId, value);
res.status(200).json({ message: 'Setting updated successfully' });
} catch (error) {
console.error('Error updating user setting:', error);
res.status(500).json({ error: 'Internal server error' });
async updateSetting(req, res) {
const { userid, settingId, value } = req.body;
try {
await settingsService.updateSetting(userid, settingId, value);
res.status(200).json({ message: 'Setting updated successfully' });
} catch (error) {
console.error('Error updating user setting:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
};
export const getTypeParamValueId = async (req, res) => {
const { paramValue } = req.body;
try {
const paramValueId = await settingsService.getTypeParamValueId(paramValue);
res.status(200).json({ paramValueId });
} catch (error) {
console.error('Error retrieving parameter value ID:', error);
res.status(404).json({ error: "notfound" });
async getTypeParamValueId(req, res) {
const { paramValue } = req.body;
try {
const paramValueId = await settingsService.getTypeParamValueId(paramValue);
res.status(200).json({ paramValueId });
} catch (error) {
console.error('Error retrieving parameter value ID:', error);
res.status(404).json({ error: "notfound" });
}
}
};
export const getTypeParamValues = async (req, res) => {
const { type } = req.body;
try {
const paramValues = await settingsService.getTypeParamValues(type);
res.status(200).json(paramValues);
} catch (error) {
console.error('Error retrieving parameter values:', error);
res.status(500).json({ error: 'An error occurred while retrieving the parameter values' });
async getTypeParamValues(req, res) {
const { type } = req.body;
try {
const paramValues = await settingsService.getTypeParamValues(type);
res.status(200).json(paramValues);
} catch (error) {
console.error('Error retrieving parameter values:', error);
res.status(500).json({ error: 'An error occurred while retrieving the parameter values' });
}
}
async getTypeParamValue(req, res) {
const { id } = req.params;
try {
const paramValue = await settingsService.getTypeParamValue(id);
res.status(200).json({ paramValue });
} catch (error) {
console.error('Error retrieving parameter value:', error);
res.status(404).json({ error: "notfound" });
}
}
async getAccountSettings(req, res) {
try {
const { userId } = req.body;
const accountSettings = await settingsService.getAccountSettings(userId);
res.status(200).json(accountSettings);
} catch (error) {
console.error('Error retrieving account settings:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async setAccountSettings(req, res) {
try {
await settingsService.setAccountSettings(req.body);
res.status(200).json({ message: 'Account settings updated successfully' });
} catch (error) {
console.error('Error updating account settings:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async getPossibleInterests(req, res) {
try {
const { userid: userId } = req.headers;
const interests = await settingsService.getPossibleInterests(userId);
res.status(200).json(interests);
} catch (error) {
console.error('Error retrieving possible interests:', error);
res.status(500).json({ error: 'An error occurred while retrieving the possible interests' });
}
}
async getInterests(req, res) {
try {
const { userid: userId } = req.headers;
const interests = await settingsService.getInterests(userId);
res.status(200).json(interests);
} catch (error) {
console.error('Error retrieving interests:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async addInterest(req, res) {
try {
const { userid: userId } = req.headers;
const { name } = req.body;
const interest = await settingsService.addInterest(userId, name);
res.status(200).json({ interest });
} catch (error) {
console.error('Error adding interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async addUserInterest(req, res) {
try {
const { userid: userId } = req.headers;
const { interestid: interestId } = req.body;
await settingsService.addUserInterest(userId, interestId);
res.status(200).json({ message: 'User interest added successfully' });
} catch (error) {
console.error('Error adding user interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async removeInterest(req, res) {
try {
const { userid: userId } = req.headers;
const { id: interestId } = req.params;
await settingsService.removeInterest(userId, interestId);
res.status(200).json({ message: 'Interest removed successfully' });
} catch (error) {
console.error('Error removing interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async getVisibilities(req, res) {
try {
const visibilities = await settingsService.getVisibilities();
res.status(200).json(visibilities);
} catch (error) {
console.error('Error retrieving visibilities:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
async updateVisibility(req, res) {
const { userParamTypeId, visibilityId } = req.body;
const hashedUserId = req.headers.userid;
try {
await settingsService.updateVisibility(hashedUserId, userParamTypeId, visibilityId);
res.status(200).json({ message: 'Visibility updated successfully' });
} catch (error) {
console.error('Error updating visibility:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
}
export const getTypeParamValue = async (req, res) => {
const { id } = req.params;
try {
const paramValue = await settingsService.getTypeParamValue(id);
res.status(200).json({ paramValue });
} catch (error) {
console.error('Error retrieving parameter value:', error);
res.status(404).json({ error: "notfound" });
}
};
export const getAccountSettings = async (req, res) => {
try {
const { userId } = req.body;
const accountSettings = await settingsService.getAccountSettings(userId);
res.status(200).json(accountSettings);
} catch (error) {
console.error('Error retrieving account settings:', error);
res.status(500).json({ error: 'Internal server error' });
}
};
export const setAccountSettings = async (req, res) => {
try {
await settingsService.setAccountSettings(req.body);
res.status(200).json({ message: 'Account settings updated successfully' });
} catch (error) {
console.error('Error updating account settings:', error);
res.status(500).json({ error: 'Internal server error' });
}
};
export const getPossibleInterests = async (req, res) => {
try {
const { userid: userId } = req.headers;
const interests = await settingsService.getPossibleInterests(userId);
res.status(200).json(interests);
} catch (error) {
console.error('Error retrieving possible interests:', error);
res.status(500).json({ error: 'An error occurred while retrieving the possible interests' });
}
}
export const getInterests = async (req, res) => {
try {
const { userid: userId } = req.headers;
const interests = await settingsService.getInterests(userId);
res.status(200).json(interests);
} catch (error) {
console.error('Error retrieving interests:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const addInterest = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { name } = req.body;
const interest = await settingsService.addInterest(userId, name);
res.status(200).json({ interest });
} catch (error) {
console.error('Error adding interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const addUserInterest = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { interestid: interestId } = req.body;
await settingsService.addUserInterest(userId, interestId);
res.status(200).json({ message: 'User interest added successfully' });
} catch (error) {
console.error('Error adding user interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const removeInterest = async (req, res) => {
try {
const { userid: userId } = req.headers;
const { id: interestId } = req.params;
await settingsService.removeInterest(userId, interestId);
res.status(200).json({ message: 'Interest removed successfully' });
} catch (error) {
console.error('Error removing interest:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const getVisibilities = async (req, res) => {
try {
const visibilities = await settingsService.getVisibilities();
res.status(200).json(visibilities);
} catch (error) {
console.error('Error retrieving visibilities:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const updateVisibility = async (req, res) => {
const { userParamTypeId, visibilityId } = req.body;
const hashedUserId = req.headers.userid;
try {
await settingsService.updateVisibility(hashedUserId, userParamTypeId, visibilityId);
res.status(200).json({ message: 'Visibility updated successfully' });
} catch (error) {
console.error('Error updating visibility:', error);
res.status(500).json({ error: 'Internal server error' });
}
};
export default SettingsController;

View File

@@ -5,6 +5,10 @@ class SocialNetworkController {
this.socialNetworkService = new SocialNetworkService();
this.userSearch = this.userSearch.bind(this);
this.profile = this.profile.bind(this);
this.createFolder = this.createFolder.bind(this);
this.getFolders = this.getFolders.bind(this);
this.uploadImage = this.uploadImage.bind(this);
this.getImage = this.getImage.bind(this);
}
async userSearch(req, res) {
@@ -32,6 +36,50 @@ class SocialNetworkController {
res.status(500).json({ error: error.message });
}
}
async createFolder(req, res) {
try {
const folderData = req.body;
const folder = await this.socialNetworkService.createFolder(folderData);
res.status(201).json(folder);
} catch (error) {
console.error('Error in createFolder:', error);
res.status(500).json({ error: error.message });
}
}
async getFolders(req, res) {
try {
const userId = req.headers.userid;
const folders = await this.socialNetworkService.getFolders(userId);
res.status(200).json(folders);
} catch (error) {
console.error('Error in getFolders:', error);
res.status(500).json({ error: error.message });
}
}
async uploadImage(req, res) {
try {
const imageData = req.body;
const image = await this.socialNetworkService.uploadImage(imageData);
res.status(201).json(image);
} catch (error) {
console.error('Error in uploadImage:', error);
res.status(500).json({ error: error.message });
}
}
async getImage(req, res) {
try {
const { imageId } = req.params;
const image = await this.socialNetworkService.getImage(imageId);
res.status(200).json(image);
} catch (error) {
console.error('Error in getImage:', error);
res.status(500).json({ error: error.message });
}
}
}
export default SocialNetworkController;