Giter Site home page Giter Site logo

npe's Introduction

NullPointerException (NPE) : a programming forum

By Oleksiy Grechnyev, Dec 2016- Jan 2017

Version 1.0

A gradle project. Requires JDK 8 and an external database server (preferably MySQL or MariaDB). With default settings it runs an embedded Tomcat web server on localhost:8080

How to Run?

1. Download:

git clone https://github.com/agrechnev/npe.git
cd npe

2. Edit file "src/main/resources/application.properties":

Set up the database settings (at least login+password) in the file "application.properties". If you want to use something different from MySQL or MariaDB, change "build.gradle" as well to include the proper JDBC driver for your database.

3. Build and run. In the project root directory (npe) type:

gradlew build
gradlew bootRun

Alternatively, if you are using an IDE, e.g. IntelliJ Idea, just run src/main/java/agrechnev/Application.java

Note that a fat JAR named npe-<version>.jar is created in the build/libs directory. It can be run with

java -jar build/libs/npe-<version>.jar

Note how Spring Boot plugin creates a fat jar with main class specified automatically. Cool!

4. Open localhost:8080 in your browser. It is better to use a Private (Anonymous) browser window. Enjoy!

For a quick start, log in with admin:admin (it works with an empty database), then create a sample database (Sample DB).
All users in the sample DB have their login names as passwords, e.g. admin:admin, brianna:brianna.

---------
More info:

This is a Rest Resource Server written on Java+Spring Boot+Hibernate.

Front End: A simple single-page AngularJS front end (directory src/main/resources/static).
Nothing fancy, simple bootstrappish look.

Unit Tests: Contains unit tests for classes UserController (very extensive) and UserService, as examples.
This is a demonstration of unit testing with Spring Boot and Spring Security. Uses Mockito+Hamcrest, of course.

Spring Security: I opted to use a simple ("Basic") password-based approach, outlined here

https://spring.io/guides/tutorials/spring-security-and-angular-js/

I didn't use oauth because I wanted to learn simpler things first. For the same reason: no hateoas in my rest.

Logging: Uses log file npe.log by default.

------------------
Rest API:

Authentication:

GET("/userauth") = Get current user principal (current user)
GET("/userid") = Get current user id (current user)
POST("/logout", {}) = Log out (current user)

User acccounts:

GET("/rest/user") =  Get all users as list of UserDto (admin only)
POST("/rest/user", UserDto userDto) = Create a new user (open)

GET("/rest/user/{id}") =  Get user (UserDto) by id (current user or admin)
PUT("/rest/user/{id}", UserDto userDto) =  Update user account (current user or admin)
DELETE("/rest/user/{id}") =  Delete user account (admin only)
POST("/rest/user/{id}/change_password", PasswordChanger passwordChanger) = Change password (current user or admin)
POST("/rest/user/{id}/delete_account", String passw) = Delete my account (current user)

Posts:

GET("/rest/post") =  Get all posts as a list of PostDto (open)
POST("/rest/post", PostDto postDto) =  Create a new post (current user)
GET("/rest/post/{id}") =  Get a post (PostDto) by id (open)
DELETE("/rest/post/{id}") =  Delete a post (post owner or admin)
PUT("/rest/post/{id}", PostDto postDto) =  Update a post (post owner)

Comments:

GET("/rest/post/{postId}/comment") =  Get all comments as a list of CommentDto (open)
POST("/rest/post/{postId}/comment", CommentDto commentDto) =  Create a new comment (current user)
GET("/rest/post/{postId}/comment/{id}") =  Get a comment (CommentDto) by id (open)
DELETE("/rest/post/{postId}/comment/{id}") = Delete a comment (admin, post owner, comment owner)
PUT("/rest/post/{postId}/comment/{id}", CommentDto commentDto) = Update a comment (comment owner)

Categories:

GET("/rest/category") =  Get all categories as a list of CategoryDto (open)
POST("/rest/category", CategoryDto categoryDto) =  Create a new category (expert or admin)
GET("/rest/category/{id}") =  Get one category (open)
DELETE("/rest/category/{id}") =  Delete a category (admin)
PUT("/rest/category/{id}", CategoryDto categoryDto) =  Update a category (admin)


Sample DB:

POST("/rest/sample/create", String passw) = Create sample database (Admin Only)
POST("/rest/sample/delete", String passw) = Delete everything (Admin Only)

----
Things I didn't do due to limited time:

This project is a demonstartion of technology. For a real site I would do many other things, such as:

Search and paginaltion of posts
Likes and user rating
Marking question (post) as answered
User home page with photo, CV etc.
Category page with list of books/tutorials/sites

npe's People

Contributors

agrechnev avatar

Watchers

James Cloos avatar

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.