-
Notifications
You must be signed in to change notification settings - Fork 24
remaining parts #10
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
Open
mohamedsaleh1984
wants to merge
17
commits into
yelsayd:main
Choose a base branch
from
mohamedsaleh1984:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
remaining parts #10
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
863bc01
added Comment,Like handlers
mohamedsaleh1984 248cedd
Added Del,Get post handlers.
mohamedsaleh1984 a3e7c50
fix endpoints paths.
mohamedsaleh1984 9111548
Impl getLikes,isDuplicateLike InMemory
mohamedsaleh1984 cd6fb7a
missed impl in SqlDataStore
mohamedsaleh1984 45b7432
implemented sqlite functions
mohamedsaleh1984 de660d2
fixes-sql-migration
mohamedsaleh1984 1aa8bbc
fixes
mohamedsaleh1984 3a60caf
fixes
mohamedsaleh1984 7d1efa9
resolved PR comments.
mohamedsaleh1984 bc19900
cleanup
mohamedsaleh1984 79d0fc7
auth middleware, jwt, pwd hashing
mohamedsaleh1984 228d484
refactor, localStorage
mohamedsaleh1984 91967ed
refactor, rm localstorafe, replace res.locals
mohamedsaleh1984 8a4bc50
use pm2
mohamedsaleh1984 1e80571
droplet pipeline
mohamedsaleh1984 635ae40
Set up CI with Azure Pipelines
mohamedsaleh1984 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,32 +1,52 @@ | ||
import { Post, User } from './types'; | ||
import { Post, User,Like,Comment } from './types'; | ||
|
||
// Post APIs | ||
export interface ListPostsRequest {} | ||
export interface ListPostsResponse { | ||
posts: Post[]; | ||
} | ||
|
||
export type DeletePostRequest = { postId: string }; | ||
export type DeletePostResponse = {}; | ||
export type CreatePostRequest = Pick<Post, 'title' | 'url' | 'userId'>; | ||
export interface CreatePostResponse {} | ||
|
||
export interface GetPostRequest {} | ||
export type GetPostRequest = {postId:string} | ||
export interface GetPostResponse { | ||
post: Post; | ||
} | ||
|
||
// Comment APIs | ||
export type CreateCommentRequest = Pick<Comment, 'userId' | 'postId' | 'comment'>; | ||
export interface CreateCommentResponse {} | ||
export type GetCommentsRequest = { postId: string }; | ||
export interface GetCommentsResponse { | ||
comments: Comment[]; | ||
} | ||
export type DeleteCommentRequest = { commentId: string }; | ||
export type DeleteCommentResponse = {}; | ||
|
||
// Like APIs | ||
export type CreateLikeRequest = Like; | ||
export interface CreateLikeResponse {} | ||
export type GetLikesRequest = { postId: string }; | ||
export interface GetLikesResponse { | ||
likes: Number; | ||
} | ||
|
||
// User APIs | ||
export type SignUpRequest = Pick< | ||
User, | ||
'email' | 'firstName' | 'lastName' | 'username' | 'password' | ||
>; | ||
export interface SignUpResponse {} | ||
export interface SignUpResponse { | ||
jwt: string | ||
} | ||
|
||
export interface SignInRequest { | ||
login: string; // username or email | ||
password: string; | ||
} | ||
export type SignInResponse = Pick<User, 'email' | 'firstName' | 'lastName' | 'username' | 'id'>; | ||
|
||
export type SignInResponse = | ||
{ user: Pick<User, 'email' | 'firstName' | 'lastName' | 'username' | 'id'>; | ||
jwt: string; | ||
} |
This file contains hidden or 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,13 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import { JwtObject } from './types'; | ||
import {getJwtSecret} from './env'; | ||
|
||
export function signJwt(obj: JwtObject): string { | ||
return jwt.sign(obj, getJwtSecret(), { | ||
expiresIn: '7d', | ||
}); | ||
} | ||
|
||
export function verifyJwt(token: string): JwtObject { | ||
return jwt.verify(token, getJwtSecret()) as JwtObject; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,3 +15,5 @@ CREATE TABLE posts ( | |
postedAt INTEGER NOT NULL, | ||
FOREIGN KEY (userId) REFERENCES users (id) | ||
); | ||
|
||
|
This file contains hidden or 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 @@ | ||
CREATE Table comments ( | ||
yelsayd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id VARCHAR PRIMARY KEY, | ||
userId VARCHAR NOT NULL, | ||
postId VARCHAR NOT NULL, | ||
comment VARCHAR NOT NULL, | ||
postedAt INTEGER NOT NULL, | ||
FOREIGN KEY (userId) REFERENCES users (id), | ||
FOREIGN KEY (PostId) REFERENCES posts (id) | ||
); | ||
|
||
CREATE Table likes ( | ||
userId VARCHAR NOT NULL, | ||
postId VARCHAR NOT NULL, | ||
FOREIGN KEY (userId) REFERENCES users (id), | ||
FOREIGN KEY (postId) REFERENCES posts (id), | ||
PRIMARY KEY (userId, postId) | ||
); |
This file contains hidden or 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 @@ | ||
// Throws on bad tokens | ||
export function getJwtSecret(): string { | ||
yelsayd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const secret = process.env.JWT_SECRET; | ||
if (!secret) { | ||
console.error('Missing JWT secret'); | ||
process.exit(1); | ||
} | ||
return secret!; | ||
} | ||
|
||
|
||
export function getSalt(): string { | ||
const salt = process.env.PASSWORD_SALT; | ||
if (!salt) { | ||
console.error('Missing Password salt'); | ||
process.exit(1); | ||
} | ||
return salt!; | ||
} |
This file contains hidden or 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 hidden or 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,43 @@ | ||
import { CreateCommentRequest, CreateCommentResponse, DeleteCommentRequest, DeleteCommentResponse } from '../api'; | ||
import { db } from '../datastore'; | ||
import { ExpressHandler, Comment } from '../types'; | ||
import crypto from 'crypto'; | ||
import { getUserId } from '../localStorage'; | ||
|
||
//Create Comment Handler | ||
export const createCommentHandler | ||
:ExpressHandler<CreateCommentRequest,CreateCommentResponse> = async (req,res)=>{ | ||
|
||
if(!req.body.postId) | ||
return res.status(400).send({error:"No Post Id"}); | ||
|
||
if(!getUserId()) | ||
return res.status(400).send({error:"No User Id"}); | ||
|
||
if(!req.body.comment) | ||
return res.status(400).send({error:"No Comment"}); | ||
|
||
const commentForInsertion:Comment = { | ||
id:crypto.randomUUID(), | ||
postedAt: Date.now(), | ||
postId:req.body.postId, | ||
userId:getUserId(), | ||
yelsayd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
comment:req.body.comment | ||
} | ||
await db.createComment(commentForInsertion); | ||
return res.sendStatus(200); | ||
} | ||
|
||
//Delete Comment Handler | ||
export const deleteCommentHandler: ExpressHandler<DeleteCommentRequest, DeleteCommentResponse> = async ( | ||
req, | ||
res | ||
) => { | ||
if (!req.body.commentId) | ||
return res.status(404).send({error:"No Comment Id"}); | ||
await db.deleteComment(req.body.commentId); | ||
yelsayd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return res.sendStatus(200); | ||
}; | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.