diff --git a/data/blogapi.sql b/data/blogapi.sql index 5cc9ced8..56622203 100644 --- a/data/blogapi.sql +++ b/data/blogapi.sql @@ -132,6 +132,7 @@ CREATE TABLE `posts` ( `title` varchar(255) NOT NULL, `body` text NOT NULL, `user_id` bigint(19) unsigned DEFAULT NULL, + `category_id` bigint(19) unsigned DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_by` bigint(19) unsigned DEFAULT NULL, @@ -141,6 +142,17 @@ CREATE TABLE `posts` ( CONSTRAINT `fk_user_post` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +CREATE TABLE `categories` ( + `id` bigint(19) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created_by` bigint(19) unsigned DEFAULT NULL, + `updated_by` bigint(19) unsigned DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + CREATE TABLE `post_tag` ( `id` bigint(19) unsigned NOT NULL AUTO_INCREMENT, `post_id` bigint(19) unsigned NOT NULL, @@ -190,3 +202,5 @@ CREATE TABLE `user_role` ( LOCK TABLES `roles` WRITE; INSERT INTO `roles` VALUES (1,'ROLE_ADMIN'),(2,'ROLE_USER'); UNLOCK TABLES; + +INSERT INTO `categories` (name) VALUES (1, 'Category 1'); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9bd9053e..4fb8de8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,14 +6,14 @@ services: restart: always environment: MYSQL_DATABASE: 'blogapi' - MYSQL_PASSWORD: 'root' - MYSQL_ROOT_PASSWORD: 'root' + MYSQL_PASSWORD: 'user1' + MYSQL_ROOT_PASSWORD: 'mypa55' ports: - '3306:3306' networks: - blogapi-network healthcheck: - test: "/usr/bin/mysql --user=root --password=root --execute \"SHOW DATABASES;\"" + test: "/usr/bin/mysql --user=user1 --password=mypa55 --execute \"SHOW DATABASES;\"" interval: 2s timeout: 20s retries: 10 diff --git a/pom.xml b/pom.xml index 1a2dfb50..22f80600 100644 --- a/pom.xml +++ b/pom.xml @@ -139,6 +139,14 @@ commons-lang3 + + org.projectlombok + lombok + 1.18.24 + provided + + + diff --git a/src/main/java/com/sopromadze/blogapi/model/Post.java b/src/main/java/com/sopromadze/blogapi/model/Post.java index 6b97dbcf..12e1e3c7 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Post.java +++ b/src/main/java/com/sopromadze/blogapi/model/Post.java @@ -69,6 +69,15 @@ public void setUser(User user) { this.user = user; } + @JsonIgnore + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + public List getComments() { return comments == null ? null : new ArrayList<>(comments); } diff --git a/src/main/resources/_application.properties b/src/main/resources/_application.properties index d7d7b14c..6c57ad71 100644 --- a/src/main/resources/_application.properties +++ b/src/main/resources/_application.properties @@ -1,7 +1,7 @@ spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:mysql://localhost:3306/blogapi?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true -spring.datasource.username=root -spring.datasource.password=root +spring.datasource.username=user1 +spring.datasource.password=mypa55 spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect app.jwtSecret=secret diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ef6d7e3d..b735f3d6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,8 +1,8 @@ spring: datasource: url: jdbc:mysql://blogapi-db:3306/blogapi?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true - username: root - password: root + username: user1 + password: mypa55 jpa: hibernate: ddl-auto: none diff --git a/src/main/resources/blogapi.sql b/src/main/resources/blogapi.sql index 3a85baec..56622203 100644 --- a/src/main/resources/blogapi.sql +++ b/src/main/resources/blogapi.sql @@ -1,3 +1,5 @@ +USE blogapi; + UNLOCK TABLES; DROP TABLE IF EXISTS `post_tag`; @@ -130,6 +132,7 @@ CREATE TABLE `posts` ( `title` varchar(255) NOT NULL, `body` text NOT NULL, `user_id` bigint(19) unsigned DEFAULT NULL, + `category_id` bigint(19) unsigned DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created_by` bigint(19) unsigned DEFAULT NULL, @@ -139,6 +142,17 @@ CREATE TABLE `posts` ( CONSTRAINT `fk_user_post` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + +CREATE TABLE `categories` ( + `id` bigint(19) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created_by` bigint(19) unsigned DEFAULT NULL, + `updated_by` bigint(19) unsigned DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + CREATE TABLE `post_tag` ( `id` bigint(19) unsigned NOT NULL AUTO_INCREMENT, `post_id` bigint(19) unsigned NOT NULL, @@ -188,3 +202,5 @@ CREATE TABLE `user_role` ( LOCK TABLES `roles` WRITE; INSERT INTO `roles` VALUES (1,'ROLE_ADMIN'),(2,'ROLE_USER'); UNLOCK TABLES; + +INSERT INTO `categories` (name) VALUES (1, 'Category 1'); \ No newline at end of file