Changed controllers to classes, added image functionality
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user