Bugs in settings fixed, profile added
This commit is contained in:
37
backend/controllers/socialnetworkController.js
Normal file
37
backend/controllers/socialnetworkController.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import SocialNetworkService from '../services/socialnetworkService.js';
|
||||
|
||||
class SocialNetworkController {
|
||||
constructor() {
|
||||
this.socialNetworkService = new SocialNetworkService();
|
||||
this.userSearch = this.userSearch.bind(this);
|
||||
this.profile = this.profile.bind(this);
|
||||
}
|
||||
|
||||
async userSearch(req, res) {
|
||||
try {
|
||||
const { username, ageFrom, ageTo, genders } = req.body;
|
||||
const users = await this.socialNetworkService.searchUsers({ username, ageFrom, ageTo, genders });
|
||||
res.status(200).json(users);
|
||||
} catch (error) {
|
||||
console.error('Error in userSearch:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async profile(req, res) {
|
||||
try {
|
||||
const { userId } = req.params;
|
||||
const requestingUserId = req.headers.userid;
|
||||
if (!userId || !requestingUserId) {
|
||||
return res.status(400).json({ error: 'Invalid user or requesting user ID.' });
|
||||
}
|
||||
const profile = await this.socialNetworkService.getProfile(userId, requestingUserId);
|
||||
res.status(200).json(profile);
|
||||
} catch (error) {
|
||||
console.error('Error in profile:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default SocialNetworkController;
|
||||
Reference in New Issue
Block a user