Skip to content

AditiJain2826/socialmedia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Social Media App

Rest API's in Nodejs for social media app are created for the following modules:

  • Profile
  • Add Friend
  • Post status (Text only)
  • View Status of Self + Friend (Use Filter)
  • Like and Comment on status

A combination of PostgreSQL and MongoDB is used.

User authentication is done via Passport jwt.

The Api's created are as follows

  1. Add Profile To add a new user profile Sample url – POST - http://localhost:3000/profile Sample Body – { "name":"Aditi", "bio":"", "gender":"F", "phoneno":9999999999, "password":"aditi" }

The api would return userid which we can further use for signin.

  1. Signin To login with userid and password Sample url – POST - http://localhost:3000/signin Sample Body – { "userid":1, "password":"aditii" } Upon successful signup a jwt token would be returned. We will have to use this token in headers. Name of the key will be ‘auth_token’ and value would be the token returned by the api. Sample Header – auth_token -eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImlhdCI6MTU4NzgwMDIwMX0.BTHgBGUGSrn5LoJRvUqvT_DhLk32gHUpZzO2G7mpb4E

  2. Get Profile To retrieve the user details Sample url – GET - http://localhost:3000/profile Add auth_token generated by signin api

  3. Update Profile To update user profile Sample url – PUT - http://localhost:3000/profile Sample Body – { "name":"Aditi", "bio":"", "gender":"F", "phoneno":8888888888, "password":"aditi" } Add auth_token generated by signin api

  4. Delete Profile To delete the user profile Sample url – DELETE - http://localhost:3000/profile Sample Body – { "name":"Aditi", "bio":"", "gender":"F", "phoneno":8888888888, "password":"aditi" } Add auth_token generated by signin api

  5. Get Friends To get list of all the friends of the user Sample url – GET - http://localhost:3000/friend Add auth_token generated by signin api

  6. Add Friends To add a new friend Sample url –POST - http://localhost:3000/friend Sample Body – { "friendid":8 } Add auth_token generated by signin api

  7. Delete Friends To delete friend Sample url – DELETE - http://localhost:3000/friend Sample Body – { "friendid":8 } Add auth_token generated by signin api

  8. Add Posts To add a post Sample url – POST - http://localhost:3000/posts Sample Body – { "txt":"New Post Added" } Add auth_token generated by signin api

  9. Update Posts To update a post Sample url – PUT - http://localhost:3000/posts Sample Body – { "txt":"Post Updated" } Add auth_token generated by signin api

  10. Delete Posts To delete the posts Sample url – DELETE - http://localhost:3000/posts Sample Body – { "id":"5ea311ca0a644e4bb0017d7a" } Add auth_token generated by signin api

  11. View Post of self+ friends To view status based on filter. Filtered value will be passed in body as array. If empty, only status posted by logged in user would be visible. Sample url – POST - http://localhost:3000/posts Sample Body – { "id":"5ea311ca0a644e4bb0017d7a" } Add auth_token generated by signin api

  12. Like Posts To like the post Sample url – POST - http://localhost:3000/posts/likepost { "id":"5ea3f59801e97850106d7ab5" } Add auth_token generated by signin api

  13. Comment on Posts To comment on the post Sample url – POST - http://localhost:3000/posts/commentonpost { "id":"5ea3f59801e97850106d7ab5", "comment":"Great" } Add auth_token generated by signin api

Database

Postgresql

  1. Create Profile Table –

CREATE TABLE profile ( userid integer NOT NULL DEFAULT nextval('your_seq'::regclass), name character varying(30) COLLATE pg_catalog."default" NOT NULL, bio text COLLATE pg_catalog."default", gender "char", phoneno numeric, password character varying(30) COLLATE pg_catalog."default" NOT NULL, CONSTRAINT profile_pkey PRIMARY KEY (userid) )

  1. Create Friends table - CREATE TABLE friends ( userid integer NOT NULL, friendid integer NOT NULL, CONSTRAINT friend_pkey PRIMARY KEY (userid, friendid), CONSTRAINT friends_friendid_fkey FOREIGN KEY (friendid) REFERENCES profile (userid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT friends_userid_fkey FOREIGN KEY (userid) REFERENCES profile (userid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION )

  2. Insert Data in Profile table-

INSERT INTO profile(name, bio, gender, phoneno, password) VALUES ('Aditi', '', 'F', 9999999999, 'adi'); INSERT INTO profile(name, bio, gender, phoneno, password) VALUES ('Arti', '', 'F', 9999999999, 'xyz'); INSERT INTO profile(name, bio, gender, phoneno, password) VALUES ('Ashu', '', 'M', 9999999999, 'yzxx');

  1. Insert data query for Friends table –

INSERT INTO friends(userid, friendid) VALUES (1,2)

Mongodb

Use test db Insert query for collection posts – db.posts.insert({userid:1,post_text:”New Post”,like:[],comment:[]}) db.posts.insert({userid:1,post_text:”Another Post”,like:[],comment:[]})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published