-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bookmark): user can bookmark article to read later
- user log in - user specifies article slug they want to bookmark in the url - user can bookmark a certain article only once - when user tries to bookmark an already bookmarked article that bookmark is removed from the database and user can bookmark again - user can see all the bookmarks they made by logging in and using the get bookmarks endpoint. they also see basic information about the article they bookmarked. [wip #165413121]
- Loading branch information
Showing
10 changed files
with
400 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
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,39 @@ | ||
const bookmarkMigration = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Bookmarks', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
primaryKey: true, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Users', | ||
key: 'id' | ||
} | ||
}, | ||
titleSlug: { | ||
type: Sequelize.STRING, | ||
primaryKey: true, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Articles', | ||
key: 'slug' | ||
} | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Bookmarks') | ||
}; | ||
export default bookmarkMigration; |
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,29 @@ | ||
const bookmarks = (sequelize, DataTypes) => { | ||
const Bookmark = sequelize.define('Bookmark', { | ||
userId: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
}, | ||
titleSlug: { | ||
type: DataTypes.STRING, | ||
primaryKey: true, | ||
} | ||
}, {}); | ||
Bookmark.associate = (models) => { | ||
Bookmark.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
as: 'author', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
Bookmark.belongsTo(models.Article, { | ||
foreignKey: 'titleSlug', | ||
as: 'article', | ||
targetKey: 'slug', | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE' | ||
}); | ||
}; | ||
return Bookmark; | ||
}; | ||
export default bookmarks; |
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
Oops, something went wrong.