-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(user should follow each other):user should follow each other
user should follow each other [finishes #166841021]
- Loading branch information
Showing
12 changed files
with
516 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import UserServices from '../services/user'; | ||
import statusCheckerHelper from '../helpers/statusChecker'; | ||
|
||
const { | ||
statusChecker | ||
} = statusCheckerHelper; | ||
|
||
const { | ||
followUser, | ||
unFollowUser | ||
} = UserServices; | ||
|
||
/** | ||
* User Controller | ||
* @constructor | ||
*/ | ||
class UserController { | ||
/** | ||
* User Follow | ||
* @constructor | ||
* @param {*} req - req | ||
* @param {*} res - res | ||
*/ | ||
static async followUser(req, res) { | ||
try { | ||
const { | ||
userId | ||
} = req.params; | ||
const { | ||
statusCode, | ||
errorMessage, | ||
successMessage | ||
} = await followUser(req.authorizedData, userId); | ||
|
||
const response = await statusChecker( | ||
req, | ||
res, | ||
statusCode, | ||
errorMessage, | ||
successMessage | ||
); | ||
return response; | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
|
||
/** | ||
* Un Follow User | ||
* @constructor | ||
* @param {*} req - req | ||
* @param {*} res - res | ||
*/ | ||
static async unFollowUser(req, res) { | ||
try { | ||
const { | ||
userId | ||
} = req.params; | ||
const { | ||
statusCode, | ||
errorMessage, | ||
successMessage | ||
} = await unFollowUser(req.authorizedData, userId); | ||
|
||
const response = await statusChecker( | ||
req, | ||
res, | ||
statusCode, | ||
errorMessage, | ||
successMessage | ||
); | ||
return response; | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
} | ||
|
||
export default UserController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Follows', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
required: true, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
as: 'user' | ||
}, | ||
onUpdate: 'cascade', | ||
onDelete: 'cascade' | ||
}, | ||
followId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
required: true, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
as: 'user' | ||
}, | ||
onUpdate: 'cascade', | ||
onDelete: 'cascade' | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Follows'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Follow = sequelize.define('Follow', { | ||
followId: { | ||
type: DataTypes.STRING, | ||
required: true | ||
}, | ||
}, {}); | ||
Follow.associate = (models) => { | ||
// associations can be defined here | ||
Follow.belongsTo(models.User, { | ||
foreignKey: 'id', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
}; | ||
return Follow; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import express from 'express'; | ||
import UserController from '../controllers/user'; | ||
import generateToken from '../middleware/tokenGenerator'; | ||
|
||
const router = express.Router(); | ||
const { | ||
followUser, | ||
unFollowUser | ||
} = UserController; | ||
|
||
|
||
router.post('/follow/:userId', | ||
generateToken.verifyToken, | ||
followUser); | ||
router.post('/unfollow/:userId', | ||
generateToken.verifyToken, | ||
unFollowUser); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.