diff --git a/build.gradle b/build.gradle index 111bd56..f0dff52 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.5.0' id 'io.spring.dependency-management' version '1.1.7' + id 'org.flywaydb.flyway' version '10.4.1' } group = 'com.jambotronGroup' @@ -21,7 +22,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.projectlombok:lombok:1.18.26' - implementation 'org.projectlombok:lombok:1.18.26' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0' @@ -56,6 +56,16 @@ tasks.register('copyResources', Copy) { } processResources.dependsOn(copyResources) compileJava.dependsOn(copyResources) +//bootRun.dependsOn("flywayMigrate") + +//flyway { +// user='admin' +// password= 'postgrespw' +// url = 'jdbc:postgresql://localhost:5432/jambotronDB' +// driver = 'org.postgresql.Driver' +// baselineOnMigrate = true +// locations = ['filesystem:src/main/resources/db.migration/'] +//} sourceSets { main { diff --git a/jambotron-ui/src/app/components/article-comments/article-comments.html b/jambotron-ui/src/app/components/article-comments/article-comments.html new file mode 100644 index 0000000..dfba77e --- /dev/null +++ b/jambotron-ui/src/app/components/article-comments/article-comments.html @@ -0,0 +1,10 @@ +

Comments

+

+ Building for the web is fantastic! +

+

+ The new template syntax is great +

+

+ I agree with the other comments! +

diff --git a/jambotron-ui/src/app/components/article-comments/article-comments.scss b/jambotron-ui/src/app/components/article-comments/article-comments.scss new file mode 100644 index 0000000..efc2191 --- /dev/null +++ b/jambotron-ui/src/app/components/article-comments/article-comments.scss @@ -0,0 +1,6 @@ +.comment { + padding: 15px; + margin-left: 30px; + background-color: paleturquoise; + border-radius: 20px; +} diff --git a/jambotron-ui/src/app/components/article-comments/article-comments.spec.ts b/jambotron-ui/src/app/components/article-comments/article-comments.spec.ts new file mode 100644 index 0000000..35dbfc8 --- /dev/null +++ b/jambotron-ui/src/app/components/article-comments/article-comments.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ArticleComments } from './article-comments'; + +describe('ArticleComments', () => { + let component: ArticleComments; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ArticleComments] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ArticleComments); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/jambotron-ui/src/app/components/article-comments/article-comments.ts b/jambotron-ui/src/app/components/article-comments/article-comments.ts new file mode 100644 index 0000000..958bf9e --- /dev/null +++ b/jambotron-ui/src/app/components/article-comments/article-comments.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-article-comments', + imports: [], + templateUrl: './article-comments.html', + styleUrl: './article-comments.scss' +}) +export class ArticleComments { + +} diff --git a/src/Docker/docker-compose.yml b/src/Docker/docker-compose.yml index 76b9380..eb40984 100644 --- a/src/Docker/docker-compose.yml +++ b/src/Docker/docker-compose.yml @@ -13,11 +13,12 @@ services: SPRING_DATASOURCE_URL: jdbc:postgresql://postgres_jambotron:5432/jambotronDB SPRING_DATASOURCE_USERNAME: admin SPRING_DATASOURCE_PASSWORD: postgrespw - SPRING_FLYWAY_LOCATIONS: classpath:db.migration - FLYWAY_USER: admin - FLYWAY_PASSWORD: postgrespw - FLYWAY_SCHEMAS: jambotronDB - FLYWAY_URL: jdbc:postgresql://postgres_jambotron:5432/jambotronDB + SPRING_FLYWAY_BASELINE-ON-MIGRATE: true + SPRING_FLYWAY_VALIDATE-ON-MIGRATE: true + + SPRING_FLYWAY_USER: admin + SPRING_FLYWAY_PASSWORD: postgrespw + SPRING_FLYWAY_URL: jdbc:postgresql://postgres_jambotron:5432/jambotronDB # SPRING_DATASOURCE_PASSWORD: /run/secrets/db_password # secrets: diff --git a/src/main/java/com/jambotronGroup/jambotron/configuretions/FlyWayConfiguration.java b/src/main/java/com/jambotronGroup/jambotron/configuretions/FlyWayConfiguration.java deleted file mode 100644 index ee0d060..0000000 --- a/src/main/java/com/jambotronGroup/jambotron/configuretions/FlyWayConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.jambotronGroup.jambotron.configuretions; - -import lombok.RequiredArgsConstructor; -import org.flywaydb.core.Flyway; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -@Configuration -@RequiredArgsConstructor -public class FlyWayConfiguration { - - @Autowired - private Environment environment; - - @Bean(initMethod = "migrate") - public Flyway flyway() { - return new Flyway(Flyway.configure() - .baselineOnMigrate(true) - .dataSource( - environment.getRequiredProperty("flyway.url"), - environment.getRequiredProperty("flyway.user"), - environment.getRequiredProperty("flyway.password")) - ); - } -} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5407917..a91b317 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -9,11 +9,14 @@ spring.datasource.password= postgrespw #spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} -spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true +#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect # Hibernate ddl auto (create, create-drop, validate, update) -spring.jpa.hibernate.ddl-auto= update +#spring.jpa.hibernate.ddl-auto= update + +spring.jpa.show-sql=true + # App Properties app.jwtSecret= ======================spring=back==================== @@ -33,9 +36,9 @@ spa.default-file=classpath:/public/browser/index.html spring.docker.compose.file=../Docker/docker-compose.yml -spring.flyway.locations=classpath:db.migration +spring.flyway.baseline-on-migrate=true +spring.flyway.validate-on-migrate=true -flyway.user=admin -flyway.password=postgrespw -flyway.schemas=jambotronDB -flyway.url=jdbc:postgresql://localhost:5432/jambotronDB \ No newline at end of file +spring.flyway.user=admin +spring.flyway.password=postgrespw +spring.flyway.url=jdbc:postgresql://localhost:5432/jambotronDB \ No newline at end of file diff --git a/src/main/resources/db/migration/V1__Init.sql b/src/main/resources/db/migration/V1__Init.sql new file mode 100644 index 0000000..4480b4e --- /dev/null +++ b/src/main/resources/db/migration/V1__Init.sql @@ -0,0 +1,7 @@ + +CREATE TABLE IF NOT EXISTS roles +( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name character varying(20) COLLATE pg_catalog."default" + +); diff --git a/src/main/resources/db/migration/V1__create_table.sql b/src/main/resources/db/migration/V1__create_table.sql deleted file mode 100644 index bc61de3..0000000 --- a/src/main/resources/db/migration/V1__create_table.sql +++ /dev/null @@ -1,62 +0,0 @@ - - -CREATE TABLE IF NOT EXISTS public.roles -( - id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - name character varying(20) COLLATE pg_catalog."default" - -); - -CREATE TABLE IF NOT EXISTS public.users -( - id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - email character varying(50) COLLATE pg_catalog."default", - password character varying(120) COLLATE pg_catalog."default", - username character varying(20) COLLATE pg_catalog."default", - - CONSTRAINT uk6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email), - CONSTRAINT ukr43af9ap4edm43mmtq01oddj6 UNIQUE (username) -); - - -CREATE TABLE IF NOT EXISTS public.user_roles -( - user_id bigint NOT NULL, - role_id integer NOT NULL, - CONSTRAINT user_roles_pkey PRIMARY KEY (user_id, role_id), - CONSTRAINT fkh8ciramu9cc9q3qcqiv4ue8a6 FOREIGN KEY (role_id) - REFERENCES public.roles (id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT fkhfh9dx7w3ubf1co1vdev94g3f FOREIGN KEY (user_id) - REFERENCES public.users (id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -); - -CREATE TABLE IF NOT EXISTS public.tutorials -( - id bigint NOT NULL, - description character varying(255) COLLATE pg_catalog."default", - published boolean, - title character varying(255) COLLATE pg_catalog."default", - CONSTRAINT tutorials_pkey PRIMARY KEY (id) -); - - -INSERT INTO roles (id, name) VALUES (1, 'ROLE_USER'); -INSERT INTO roles (id, name) VALUES (2, 'ROLE_MODERATOR'); -INSERT INTO roles (id, name) VALUES (3, 'ROLE_ADMIN'); - -INSERT INTO users (id, email, password, username) -VALUES (1, 'liosha84@gmail.com', '$2a$10$qyoKXYSukha6XCjorTzoweF4Os1pwmwyzbaSsb3RCVB0LK6WLQKPC', 'Admin'); -INSERT INTO users (id, email, password, username) -VALUES (4, 'Moderator@gmail.com', '$2a$10$zLo5th8Xbfq.MM7y/dCRQu3Ud7HHyAwm.7.yS08ytJtkHMKrbOJlu', 'Moderator'); -INSERT INTO users (id, email, password, username) -VALUES (5, 'user@gmail.com', '$2a$10$2EcwYffteBF3GhVaf5qPB.I7XiHepDEauU5D4fx9fpBXMTZI/QnnC', 'User'); - - -INSERT INTO user_roles (user_id, role_id) VALUES (5, 1); -INSERT INTO user_roles (user_id, role_id) VALUES (1, 3); -INSERT INTO user_roles (user_id, role_id) VALUES (4, 2); - diff --git a/src/main/resources/db/migration/V2__init.sql b/src/main/resources/db/migration/V2__init.sql new file mode 100644 index 0000000..4a88861 --- /dev/null +++ b/src/main/resources/db/migration/V2__init.sql @@ -0,0 +1,14 @@ + + +CREATE TABLE IF NOT EXISTS users +( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + email character varying(50) COLLATE pg_catalog."default", + password character varying(120) COLLATE pg_catalog."default", + username character varying(20) COLLATE pg_catalog."default", + + CONSTRAINT uk6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email), + CONSTRAINT ukr43af9ap4edm43mmtq01oddj6 UNIQUE (username) +); + + diff --git a/src/main/resources/db/migration/V3__init.sql b/src/main/resources/db/migration/V3__init.sql new file mode 100644 index 0000000..a4adedb --- /dev/null +++ b/src/main/resources/db/migration/V3__init.sql @@ -0,0 +1,25 @@ + +CREATE TABLE IF NOT EXISTS public.user_roles +( + user_id bigint NOT NULL, + role_id integer NOT NULL, + CONSTRAINT user_roles_pkey PRIMARY KEY (user_id, role_id), + CONSTRAINT fkh8ciramu9cc9q3qcqiv4ue8a6 FOREIGN KEY (role_id) + REFERENCES public.roles (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION, + CONSTRAINT fkhfh9dx7w3ubf1co1vdev94g3f FOREIGN KEY (user_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + + +CREATE TABLE IF NOT EXISTS public.tutorials +( + id bigint NOT NULL, + description character varying(255) COLLATE pg_catalog."default", + published boolean, + title character varying(255) COLLATE pg_catalog."default", + CONSTRAINT tutorials_pkey PRIMARY KEY (id) +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__Init_data.sql b/src/main/resources/db/migration/V4__Init_data.sql new file mode 100644 index 0000000..b2f1629 --- /dev/null +++ b/src/main/resources/db/migration/V4__Init_data.sql @@ -0,0 +1,20 @@ + +INSERT INTO roles (id, name) OVERRIDING SYSTEM VALUE VALUES (1, 'ROLE_USER'); +INSERT INTO roles (id, name) OVERRIDING SYSTEM VALUE VALUES (2, 'ROLE_MODERATOR'); +INSERT INTO roles (id, name) OVERRIDING SYSTEM VALUE VALUES (3, 'ROLE_ADMIN'); + + +INSERT INTO users (id, email, password, username) +OVERRIDING SYSTEM VALUE +VALUES (1, 'liosha84@gmail.com', '$2a$10$qyoKXYSukha6XCjorTzoweF4Os1pwmwyzbaSsb3RCVB0LK6WLQKPC', 'Admin'); +INSERT INTO users (id, email, password, username) +OVERRIDING SYSTEM VALUE +VALUES (2, 'Moderator@gmail.com', '$2a$10$zLo5th8Xbfq.MM7y/dCRQu3Ud7HHyAwm.7.yS08ytJtkHMKrbOJlu', 'Moderator'); +INSERT INTO users (id, email, password, username) +OVERRIDING SYSTEM VALUE +VALUES (3, 'user@gmail.com', '$2a$10$2EcwYffteBF3GhVaf5qPB.I7XiHepDEauU5D4fx9fpBXMTZI/QnnC', 'User'); + + +INSERT INTO user_roles (user_id, role_id) OVERRIDING SYSTEM VALUE VALUES (3, 1); +INSERT INTO user_roles (user_id, role_id) OVERRIDING SYSTEM VALUE VALUES (1, 3); +INSERT INTO user_roles (user_id, role_id) OVERRIDING SYSTEM VALUE VALUES (2, 2); \ No newline at end of file diff --git a/src/test/java/com/jambotronGroup/jambotron/JambotronApplicationTests.java b/src/test/java/com/jambotronGroup/jambotron/JambotronApplicationTests.java index cc0ed4d..b50ea52 100644 --- a/src/test/java/com/jambotronGroup/jambotron/JambotronApplicationTests.java +++ b/src/test/java/com/jambotronGroup/jambotron/JambotronApplicationTests.java @@ -3,11 +3,11 @@ package com.jambotronGroup.jambotron; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest + class JambotronApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() { + // Test will pass if the application context loads successfully + } }