SEEU - Programming In Java final project
Traveling is the most beautiful part of life, but very often we wonder which destination we would visit next. Therefore, with the help of TravelingIsFun, you will be able to see how the rest of you have fared on the trip that you may have planned to go on and start the adventures and share it with other users.
- First clone this repository using following commands:
cd/destination_folder (on your local machine)
git clone https://github.com/nikoladomazetovikj/traveling_is_fun.git
-
Make sure that you are using
JDK 17
-
You should build the
Gradle
-
Create a
MySQL
database -
Set your database properties in the
src/main/java/resources/aplication.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/your_db_name
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
- Note: Database data migration setup
- You can use
spring.jpa.hibernate.ddl-auto=create-drop
, in case you want every time to drop all tables and create them on start - Or you can use
spring.jpa.hibernate.ddl-auto=update
, in case you don't want to lose all tables and data every time you start the application
- This application is using
SpringBoot 2.7.6
- Necessary dependencies are :
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
- Note: you can find them in
build.gradle
- You must use
Hibernate
to work with the database and queries
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
- You can find this one in
src/main/java/resources/aplication.properties
, or you can modified if you want on your local machine
- Start the application:
-
You must have some server like
APACHE
,NGINX
-
You should have
MySQL
database server setup -
To test the application you can use every browser (only for the
GET
requests, or you can usePostman
orInsomnia
- Start your local server
- Start the database server
- Run the application
- The default port is
localhost:8080
Here you can look at the database DDL:
- Tables
create table categories
(
id bigint null,
name integer null
);
create table users
(
id bigint null,
country varchar(255) null,
email varchar(255) null,
is_admin tinyint null,
is_bloger tinyint null,
name varchar(255) null,
password varchar(255) null,
surname varchar(255) null,
user_name varchar(255) null
);
create table posts
(
id bigint null,
category varchar(255) null,
content longtext null,
title varchar(255) null,
author_id bigint null
);
create table comments
(
id bigint null,
text varchar(255) null,
post_id bigint null,
user_id bigint null
);
create table post_like
(
user_id bigint null,
post_id bigint null
);
create table post_rating
(
post_id bigint null,
user_id bigint null,
rating integer null
);
- ERD Diagram
HTTP Method | Endpoint | Description |
---|---|---|
GET | /api/posts/allPosts | Find All Posts |
POST | /api/posts/create | Create New Post |
PUT | /api/posts/edit/:postId | Edit Post |
DELETE | /api/posts/delete/:postId | Delete Post |
GET | /api/users | Find All Users |
POST | /api/users/create | Create New User |
DELETE | /api/users/1/delete/:userId | Delete User |
PUT | /api/users/:userId/like/:postId | Like Post |
POST | /api/users/:userId/comment/:postId | Add Comment |
- Usage and Examples
-
Users
Request:
GET http://localhost:8080/api/users
Response:
[ { "id": 1, "name": "User 1", "country": "Macedonia", "surname": "surname", "email": "em@em.com", "userName": "username", "password": "hidden", "ratings": [], "admin": true, "blogger": true }, { "id": 4, "name": "User 3", "country": "Mac3edonia", "surname": "surn3ame", "email": "em@em.c32om", "userName": "usern32ame", "password": "hidde23n", "ratings": [], "admin": true, "blogger": true }, { "id": 5, "name": "User 4", "country": "Mac43edonia", "surname": "surn43ame", "email": "em@em.c432om", "userName": "usern432ame", "password": "hidde243n", "ratings": [], "admin": true, "blogger": true } ]
Request:
POST http://localhost:8080/api/users/create
Body:
{ "name":"User 4", "country":"Mac43edonia", "surname":"surn43ame", "email":"em@em.c432om", "userName":"usern432ame", "password":"hidde243n", "isAdmin":true, "isBlogger":true }
Request:
DELETE http://localhost:8080/api/users/1/delete/3
Response: no content
Request:
PUT http://localhost:8080/api/users/1/like/1
Request:
POST http://localhost:8080/api/users/1/comment/1?comment=comment1
-
Posts
Request:
GET http://localhost:8080/api/posts/allPosts
Response:
[ { "id": 1, "title": "Hello world ", "content": "Content ", "author": { "id": 1, "name": "User 4", "country": "Mac43edonia", "surname": "surn43ame", "email": "em@em.c432om", "userName": "usern432ame", "password": "hidde243n", "ratings": [], "admin": true, "blogger": true }, "category": "LAK2ES", "comments": [], "likes": [], "ratings": [] } ]
Request:
POST http://localhost:8080/api/posts/create
Body:
{ "title":"Hello world ", "content":"Content ", "userId":1, "category":"LAK2ES" }
Request:
PUT http://localhost:8080/api/posts/edit/1
Body:
{ "title":"Edited title", "content":"Edited content", "category":"Edited category" }
Request:
DELETE http://localhost:8080/api/posts/delete/1
Response: no content