Git Product home page Git Product logo

spring-quora-api's Introduction

Course 5 Project - Quora Backend API

Instructions to Contribute

  1. Fork the repository.
  2. Download the clone of this fork on your local machine.
  3. Check all the issues on the original repository.
  4. Work through the requirements in the issue

Config changes

You will need to change the password and username as per your database configuration in these places -

  1. quora-api/src/main/resources/application.yaml
  2. quora-db/src/main/resources/config/localhost.properties

(...more to come 🤡)

Project Structure

The project must follow a definite structure in order to help the co-developers and reviewers for easy understanding. Also, the better project structure makes your code modular and it becomes easier to implement any new features on the existing application. Follow the directory structure given in the project stub file. The main module is divided into three sub-modules — quora-api, quora-db, and quora-service.

1. quora-api

config - This directory must consist of all the required configuration files of the project (if any). We have already provided swagger config file in the stub. controller - This directory must consist of all the controller classes required for the project (the list of required controllers along with the API endpoints are listed in the next segment).

exception - This directory must consist of the exception handlers for all the exceptions. You have to implement the code for exception handler for all the exceptions to be implemented in the project.

endpoints - This directory consists of the JSON files which are used to generate the Request and Response models.

test - This directory consists of tests for all the controller classes. You need to uncomment all the given test cases to run these test cases after implementing the project.

2. quora-db

config - This directory consists of the database properties and environment properties for local development. sql - This directory consists of all the SQL queries to create database schema tables.

3. quora-service

business - This directory must consist of all the implementations of the business logic of the application. dao - This directory allows us to isolate the application/business layer from the persistence layer and must consist of the implementation of all the data access object classes.

entity - This directory must consist of all the entity classes related to the project to map these class objects with the database. You need to observe the database schema and all the constraints given in SQL files carefully to map Java objects with the database.

exception - This directory consists of all the exceptions related to the project. All the exceptions required for the project have been implemented in the stub file.

spring-quora-api's People

Contributors

ansarkmemon avatar dushyanthshenoyr avatar ratanraj1088 avatar rdushyanthshenoy avatar

Watchers

 avatar  avatar  avatar

spring-quora-api's Issues

Build CommonController with the endpoints listed

CommonController

The following API endpoints must be implemented in 'CommonController' class:

1. userProfile - "/userprofile/{userId}"

This endpoint is used to get the details of any user in the Quora Application. This endpoint can be accessed by any user in the application.It should be a GET request

  • This endpoint must request the path variable 'userId' as a string for the corresponding user profile to be retrieved and access token of the signed in user as a string in authorization Request Header.

  • If the access token provided by the user does not exist in the database throw 'AuthorizationFailedException' with the message code - 'ATHR-001' and message - 'User has not signed in'.

  • If the user has signed out, throw "AuthorizationFailedException" with the message code -'ATHR-002' and message - 'User is signed out.Sign in first to get user details' .

  • If the user with uuid whose profile is to be retrieved does not exist in the database, throw 'UserNotFoundException' with the message code -'USR-001' and message - 'User with entered uuid does not exist'.

  • Else, return all the details of the user from the database in the JSON response with the corresponding HTTP status.

QuestionController - Create an endpoint to create new question

createQuestion endpoint

createQuestion - "/question/create"

This endpoint is used to create a question in the Quora Application which will be shown to all the users. Any user can access this endpoint.

It should be a POST request.

  • This endpoint requests for all the attributes in 'QuestionRequest' about the question and access token of the signed in user as a string in the authorization field of the Request Header.
    If the access token provided by the user does not exist in the database throw AuthorizationFailedException with the message code - 'ATHR-001' and message - 'User has not signed in'.

  • If the user has signed out, throw 'AuthorizationFailedException' with the message code- 'ATHR-002' and message - 'User is signed out.Sign in first to post a question'.

  • Else, save the question information in the database and return the 'uuid' of the question and message 'QUESTION CREATED' in the JSON response with the corresponding HTTP status.

Build UserController with the endPoints listed below

1. signup - "/user/signup"

This endpoint is used to register a new user in the Quora Application. It should be a POST request.

  • This endpoint requests for all the attributes in 'SignupUserRequest' about the user.
    If the username provided already exists in the current database, throw ‘SignUpRestrictedException’ with the message code - 'SGR-001' and message - 'Try any other Username, this Username has already been taken'.

  • If the email Id provided by the user already exists in the current database, throw ‘SignUpRestrictedException’ with the message code -'SGR-002' and message -'This user has already been registered, try with any other emailId'.

  • If the information is provided by a non-existing user, then save the user information in the database and return the 'uuid' of the registered user and message 'USER SUCCESSFULLY REGISTERED' in the JSON response with the corresponding HTTP status.

  • Also, make sure to save the password after encrypting it using 'PasswordCryptographyProvider' class given in the stub file.

  • when a user signs up using this endpoint then the role of the person will be 'nonadmin' by default. You can add users with 'admin' role only by executing database queries or with pgAdmin.

2. signin - "/user/signin"

This endpoint is used for user authentication. The user authenticates in the application and after successful authentication, JWT token is given to a user.It should be a POST request.

  • This endpoint requests for the User credentials to be passed in the authorization field of header as part of Basic authentication. You need to pass "Basic username:password" (where username:password of the String is encoded to Base64 format) in the authorization header.

  • If the username provided by the user does not exist, throw "AuthenticationFailedException" with the message code -'ATH-001' and message-'This username does not exist'.

  • If the password provided by the user does not match the password in the existing database, throw 'AuthenticationFailedException' with the message code -'ATH-002' and message -'Password failed'.

  • If the credentials provided by the user match the details in the database, save the user login information in the database and return the 'uuid' of the authenticated user from 'users' table and message 'SIGNED IN SUCCESSFULLY' in the JSON response with the corresponding HTTP status. Note that 'JwtAccessToken' class has been given in the stub file to generate an access token.

  • Also, return the access token in the access_token field of the Response Header, which will be used by the user for any further operation in the Quora Application.

3. signout - "/user/signout"

This endpoint is used to sign out from the Quora Application. The user cannot access any other
endpoint once he is signed out of the application.It should be a POST request.

  • This endpoint must request the access token of the signed in user in the authorization field of the Request Header.

  • If the access token provided by the user does not exist in the database, throw 'SignOutRestrictedException' with the message code -'SGR-001' and message - 'User is not Signed in'.

  • If the access token provided by the user is valid, update the LogoutAt time of the user in the database and return the 'uuid' of the signed out user from 'users' table and message 'SIGNED OUT SUCCESSFULLY' in the JSON response with the corresponding HTTP status.

Build AdminController using the following endpoints

AdminController

The following API endpoints must be implemented in 'AdminController' class:

1. userDelete - "/admin/user/{userId}"

This endpoint is used to delete a user from the Quora Application. Only an admin is authorized to access this endpoint. It should be a DELETE request.

  • This endpoint requests the path variable 'userId' as a string for the corresponding user which is to be deleted from the database and access token of the signed in user as a string in authorization Request Header.

  • If the access token provided by the user does not exist in the database throw 'AuthorizationFailedException' with the message code-'ATHR-001' and message -'User has not signed in'.

  • If the user has signed out, throw 'AuthorizationFailedException' with the message code- 'ATHR-002' and message - 'User is signed out'.

  • If the role of the user is 'nonadmin', throw 'AuthorizationFailedException' with the message code-'ATHR-003' and message - 'Unauthorized Access, Entered user is not an admin'.

  • If the user with uuid whose profile is to be deleted does not exist in the database, throw 'UserNotFoundException' with the message code -'USR-001' and message - 'User with entered uuid to be deleted does not exist'.

  • Else, delete the records from all the tables related to that user and return 'uuid' of the deleted user from 'users' table and message 'USER SUCCESSFULLY DELETED' in the JSON response with the corresponding HTTP status.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.