Poller Bear
Backend of a Polling app where a user can create poll, vote for polls, user can see his/her poll feed and user profile which provides history of the created polls and voted polls by that user.
Technology used
- Spring Boot
- MySQL
Table of Contents
Setup
-
Change properties in
appication.properties
spring.datasource.url=jdbc:mysql://localhost:3306/<database name> spring.datasource.username=<username> spring.datasource.password=<password>
-
Create the database
CREATE DATABASE <database name>;
-
Run the application to create the tables
mvn spring-boot:run
-
Insert two roles in the Role table
INSERT INTO roles(name) VALUES('ROLE_USER');
-
Rerun the app
mvn spring-boot:run
Api Documentation
Authentication
-
Signup
POST /api/signup
-
Request body
{ "name": <name String>, "username": <username String>, "email": <email String>, "password": <password String> }
-
-
Login
POST /api/login
-
Request body
{ "emailOrUsername": <email_or_username String>, "password": <password String> }
-
returns
Authentication Token
-
Poll
-
All Polls
GET /api/poll
-
Request params
page=<page_no Integer> size=<page_size Integer>
-
returns Paginated List of Polls
-
-
Create Poll
POST /api/poll
-
Request body
{ "topic": <topic_of_the_Poll String>, "choices": [ { "text": <choice1_text String> }, { "text": <choice2_text String> }, ... ], "duration": { "days": <days Integer>, "hours": <hours Integer> } }
-
-
Get Poll by id
GET /api/poll/{pollId}
- returns single Poll response of id: pollId
-
Cast vote for a Poll `POST /api/poll/{pollId}/vote
- Request body
{ "choiceId": <choice_id Long> }
- retuns updated Poll response
- Request body
User
-
Get User Profile
GET /api/user/{username}
- returns User Profile of user with given username
-
Get Polls created by User
GET /api/user/{username}/polls
-
Request params
page=<page_no Integer> size=<page_size Integer>
-
returns Paginated List of Polls
-
-
Get Polls voted by User
GET /api/user/{username}/votes
-
Request params
page=<page_no Integer> size=<page_size Integer>
-
returns Paginated List of Polls
-
Availability
-
Get Availability of username and email
GET /api/user/availability
- Request params
username=<username> email=<email>
- returns username or email already exists or not
- Request params