-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
save button draft #30
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import Router from '@koa/router'; | |
import Post from '../models/post'; | ||
import mongodb from 'mongodb'; | ||
import bodyParser from 'koa-bodyparser'; | ||
import User from '../models/user'; | ||
|
||
const router = new Router({ | ||
prefix: '/posts', | ||
|
@@ -25,7 +26,7 @@ router.get('/:postID', async (ctx, next) => { | |
router.post('/', async (ctx, next) => { | ||
const post = new Post(); | ||
post.id = new mongodb.ObjectId(); | ||
post.author = null; //This is dependent on Auth to determine the author | ||
post.author = ctx.state.user.id; | ||
post.numLikes = 0; | ||
|
||
const requestBody = ctx.request.body as any; | ||
|
@@ -58,7 +59,17 @@ router.post('/:postID/unlike', async (ctx, next) => { | |
await post.save(); | ||
ctx.body = post; | ||
}); | ||
|
||
router.post('/:postID/save', async (ctx, next) => { | ||
const post = await Post.findOneBy(mongodb.ObjectId(ctx.params.postID)); | ||
if (post === null) { | ||
ctx.status = 404; | ||
return; | ||
} | ||
const user = ctx.state.user.id; | ||
user.savedPosts.push(post.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ctx.state.user.id is just their id, so you'll have to use findOneBy with this id to grab the model first |
||
await user.save(); | ||
ctx.body = user.savedPosts; | ||
}); | ||
router.delete('/', async (ctx, next) => { | ||
const post = await Post.find(); | ||
ctx.body = await Post.remove(post); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,9 @@ class PostSongDetails extends StatelessWidget { | |
PostActionButton( | ||
icon: Icons.bookmark_border, | ||
text: "Save", | ||
onPressed: () {}, | ||
onPressed: () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be filled in now - ahmed added the structure for making requests like this. essentially u can do this in steps:
|
||
|
||
}, | ||
), | ||
], | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change this to store the username - you can grab it by finding the user model first via id then grabbing the username from the user model. you'll also need to change (in the post model file) the author field to be a string instead of a user model