From 225ec0687a5b3ed5a0e1dd2a54906ddd54445591 Mon Sep 17 00:00:00 2001 From: Omari Sopromadze Date: Mon, 12 Feb 2024 01:36:39 +0100 Subject: [PATCH] feat: add cucumber --- .github/ISSUE_TEMPLATE/feature_request.md | 4 +- .github/pull_request_template.md | 4 +- Dockerfile | 5 -- LICENSE | 2 +- docker-compose.yml | 35 +++------- pom.xml | 66 +++++++++++++++++-- .../blogapi/BlogApiApplication.java | 18 +---- .../blogapi/config/ConfigBeans.java | 19 ++++++ .../blogapi/config/SecurityConfig.java | 14 ++-- .../blogapi/config/WebMvcConfig.java | 22 ++++--- .../blogapi/controller/AuthController.java | 4 +- .../adapter/TagPersistenceMysqlAdapter.java | 7 +- .../persistence/mysql/entity/TagEntity.java | 19 +++--- .../mysql/repository/TagMysqlRepository.java | 19 ++++-- .../com/sopromadze/blogapi/model/Album.java | 7 +- .../sopromadze/blogapi/model/Category.java | 14 ++-- .../com/sopromadze/blogapi/model/Comment.java | 10 ++- .../com/sopromadze/blogapi/model/Photo.java | 10 ++- .../com/sopromadze/blogapi/model/Post.java | 11 ++-- .../com/sopromadze/blogapi/model/Todo.java | 7 +- .../blogapi/model/audit/DateAudit.java | 16 ++--- .../blogapi/model/audit/UserDateAudit.java | 15 ++--- .../sopromadze/blogapi/model/role/Role.java | 7 +- .../blogapi/model/user/Address.java | 4 +- .../blogapi/model/user/Company.java | 4 +- .../sopromadze/blogapi/model/user/Geo.java | 13 ++-- .../sopromadze/blogapi/model/user/User.java | 12 ++-- .../blogapi/repository/AlbumRepository.java | 17 +++-- .../repository/CategoryRepository.java | 18 +++-- .../blogapi/repository/CommentRepository.java | 15 +++-- .../blogapi/repository/PhotoRepository.java | 17 +++-- .../blogapi/repository/PostRepository.java | 16 +++-- .../blogapi/repository/RoleRepository.java | 3 +- .../blogapi/repository/TodoRepository.java | 15 +++-- .../blogapi/repository/UserRepository.java | 15 +++-- .../service/impl/AlbumServiceImpl.java | 4 +- .../service/impl/CategoryServiceImpl.java | 3 +- .../service/impl/CommentServiceImpl.java | 7 +- .../impl/CustomUserDetailsServiceImpl.java | 3 +- .../service/impl/PhotoServiceImpl.java | 10 +-- .../blogapi/service/impl/PostServiceImpl.java | 9 ++- .../blogapi/service/impl/TagServiceImpl.java | 3 +- .../blogapi/service/impl/TodoServiceImpl.java | 10 +-- .../blogapi/service/impl/UserServiceImpl.java | 18 ++--- src/main/resources/application.yml | 6 +- .../cucumber/CucumberSpringConfiguration.java | 24 +++++++ src/test/java/cucumber/RunCucumberIT.java | 18 +++++ src/test/java/cucumber/TestConfig.java | 15 +++++ src/test/java/cucumber/helper/RestClient.java | 24 +++++++ src/test/java/cucumber/steps/TestStep.java | 21 ++++++ src/test/resources/cucumber/test.feature | 7 ++ src/test/resources/junit-platform.properties | 3 + 52 files changed, 419 insertions(+), 250 deletions(-) delete mode 100644 Dockerfile create mode 100644 src/main/java/com/sopromadze/blogapi/config/ConfigBeans.java create mode 100644 src/test/java/cucumber/CucumberSpringConfiguration.java create mode 100644 src/test/java/cucumber/RunCucumberIT.java create mode 100644 src/test/java/cucumber/TestConfig.java create mode 100644 src/test/java/cucumber/helper/RestClient.java create mode 100644 src/test/java/cucumber/steps/TestStep.java create mode 100644 src/test/resources/cucumber/test.feature create mode 100644 src/test/resources/junit-platform.properties diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7d..168584ca 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,7 +7,7 @@ assignees: '' --- -**Is your feature request related to a problem? Please describe.** +**Is your karate request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** @@ -17,4 +17,4 @@ A clear and concise description of what you want to happen. A clear and concise description of any alternative solutions or features you've considered. **Additional context** -Add any other context or screenshots about the feature request here. +Add any other context or screenshots about the karate request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 61e19e15..cf3db639 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -9,8 +9,8 @@ Fixes # (issue) Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] New karate (non-breaking change which adds functionality) +- [ ] Breaking change (fix or karate that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update #### How Has This Been Tested? diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e7d65cce..00000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM adoptopenjdk/openjdk11:alpine-jre -VOLUME /tmp -ARG JAR_FILE=target/*.jar -COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/LICENSE b/LICENSE index 0ad25db4..0acd057a 100644 --- a/LICENSE +++ b/LICENSE @@ -90,7 +90,7 @@ a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) +karate that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If diff --git a/docker-compose.yml b/docker-compose.yml index 9bd9053e..55064739 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,35 +1,18 @@ version: '3.8' services: - db: - image: mysql - container_name: blogapi-db - restart: always - environment: - MYSQL_DATABASE: 'blogapi' - MYSQL_PASSWORD: 'root' - MYSQL_ROOT_PASSWORD: 'root' + postgres: + image: postgres:14-alpine + container_name: blogapi-postgres ports: - - '3306:3306' - networks: - - blogapi-network - healthcheck: - test: "/usr/bin/mysql --user=root --password=root --execute \"SHOW DATABASES;\"" - interval: 2s - timeout: 20s - retries: 10 + - "5432:5432" volumes: - - ./data:/docker-entrypoint-initdb.d - application: - container_name: blogapi-application - build: - context: ./ - dockerfile: Dockerfile - ports: - - "8080:8080" + - ~/apps/postgres:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=root + - POSTGRES_USER=root + - POSTGRES_DB=blogapi networks: - blogapi-network - depends_on: - - "db" networks: blogapi-network: name: blogapi-network diff --git a/pom.xml b/pom.xml index 545d3838..e26614b6 100644 --- a/pom.xml +++ b/pom.xml @@ -22,9 +22,11 @@ UTF-8 UTF-8 - 17 + 21 1.5.5.Final - 1.18.28 + 1.18.30 + 7.15.0 + 1.19.5 0.8.10 coma123 https://sonarcloud.io @@ -43,9 +45,8 @@ - com.mysql - mysql-connector-j - 8.1.0 + org.postgresql + postgresql @@ -156,6 +157,57 @@ jacoco-maven-plugin ${jacoco.version} + + + io.cucumber + cucumber-java + ${cucumber.version} + test + + + + io.cucumber + cucumber-junit-platform-engine + ${cucumber.version} + test + + + + io.cucumber + cucumber-spring + ${cucumber.version} + test + + + + org.junit.platform + junit-platform-suite + 1.10.2 + test + + + + org.testcontainers + testcontainers + ${testcontainers.version} + test + + + + org.testcontainers + postgresql + ${testcontainers.version} + test + + + + io.rest-assured + rest-assured + 5.4.0 + test + + + @@ -165,8 +217,8 @@ maven-compiler-plugin 3.8.1 - 17 - 17 + 21 + 21 org.mapstruct diff --git a/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java b/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java index 6931bd3d..a00659c6 100644 --- a/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java +++ b/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java @@ -1,19 +1,13 @@ package com.sopromadze.blogapi; -import com.sopromadze.blogapi.security.JwtAuthenticationFilter; import jakarta.annotation.PostConstruct; -import org.modelmapper.ModelMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.data.convert.Jsr310Converters; import java.util.TimeZone; @SpringBootApplication -@EntityScan(basePackageClasses = {BlogApiApplication.class, Jsr310Converters.class}) - +//@EntityScan(basePackageClasses = {BlogApiApplication.class, Jsr310Converters.class}) public class BlogApiApplication { public static void main(String[] args) { @@ -25,14 +19,4 @@ void init() { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); } - @Bean - public JwtAuthenticationFilter jwtAuthenticationFilter() { - return new JwtAuthenticationFilter(); - } - - @Bean - public ModelMapper modelMapper() { - return new ModelMapper(); - } - } diff --git a/src/main/java/com/sopromadze/blogapi/config/ConfigBeans.java b/src/main/java/com/sopromadze/blogapi/config/ConfigBeans.java new file mode 100644 index 00000000..e537f2b2 --- /dev/null +++ b/src/main/java/com/sopromadze/blogapi/config/ConfigBeans.java @@ -0,0 +1,19 @@ +package com.sopromadze.blogapi.config; + +import com.sopromadze.blogapi.security.JwtAuthenticationFilter; +import org.modelmapper.ModelMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ConfigBeans { + @Bean + public JwtAuthenticationFilter jwtAuthenticationFilter() { + return new JwtAuthenticationFilter(); + } + + @Bean + public ModelMapper modelMapper() { + return new ModelMapper(); + } +} diff --git a/src/main/java/com/sopromadze/blogapi/config/SecurityConfig.java b/src/main/java/com/sopromadze/blogapi/config/SecurityConfig.java index 59a07171..02cdf405 100644 --- a/src/main/java/com/sopromadze/blogapi/config/SecurityConfig.java +++ b/src/main/java/com/sopromadze/blogapi/config/SecurityConfig.java @@ -8,12 +8,12 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.authentication.AuthenticationManagerFactoryBean; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; @@ -51,9 +51,15 @@ public SecurityFilterChain configure(HttpSecurity http) throws Exception { return http.build(); } - @Bean(BeanIds.AUTHENTICATION_MANAGER) + @Bean() public AuthenticationManager authenticationManagerBean() throws Exception { - return new AuthenticationManagerFactoryBean().getObject(); + return new AuthenticationManager() { + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + return null; + } + }; +// return new AuthenticationManagerFactoryBean().getObject(); } @Bean diff --git a/src/main/java/com/sopromadze/blogapi/config/WebMvcConfig.java b/src/main/java/com/sopromadze/blogapi/config/WebMvcConfig.java index 301ecb17..ec56ab30 100644 --- a/src/main/java/com/sopromadze/blogapi/config/WebMvcConfig.java +++ b/src/main/java/com/sopromadze/blogapi/config/WebMvcConfig.java @@ -8,16 +8,18 @@ @Configuration public class WebMvcConfig implements WebMvcConfigurer { - @Value("cors.allowedOrings") - private String allowedOrigins; + @Value("${cors.allowed_origins:}") + private String allowedOrigins; - public void addCorsMappings(CorsRegistry registry) { - final long MAX_AGE_SECS = 3600; + @Override + public void addCorsMappings(CorsRegistry registry) { + final long MAX_AGE_SECS = 3600; + + registry.addMapping("/**") + .allowedOrigins(allowedOrigins) + .allowedMethods("GET", "POST", "PUT", "DELETE") + .allowedHeaders("*") + .maxAge(MAX_AGE_SECS); + } - registry.addMapping("/**") - .allowedOrigins(allowedOrigins) - .allowedMethods("GET", "POST", "PUT", "DELETE") - .allowedHeaders("*") - .maxAge(MAX_AGE_SECS); - } } diff --git a/src/main/java/com/sopromadze/blogapi/controller/AuthController.java b/src/main/java/com/sopromadze/blogapi/controller/AuthController.java index f60c7431..1d49402f 100644 --- a/src/main/java/com/sopromadze/blogapi/controller/AuthController.java +++ b/src/main/java/com/sopromadze/blogapi/controller/AuthController.java @@ -39,10 +39,10 @@ public class AuthController { @Autowired private AuthenticationManager authenticationManager; - @Autowired +// @Autowired private UserRepository userRepository; - @Autowired +// @Autowired private RoleRepository roleRepository; @Autowired diff --git a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/adapter/TagPersistenceMysqlAdapter.java b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/adapter/TagPersistenceMysqlAdapter.java index 3e437f05..7d979ab8 100644 --- a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/adapter/TagPersistenceMysqlAdapter.java +++ b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/adapter/TagPersistenceMysqlAdapter.java @@ -5,15 +5,14 @@ import com.sopromadze.blogapi.infrastructure.persistence.mysql.entity.TagEntity; import com.sopromadze.blogapi.infrastructure.persistence.mysql.mapper.TagEntityMapper; import com.sopromadze.blogapi.infrastructure.persistence.mysql.repository.TagMysqlRepository; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -@RequiredArgsConstructor +//@RequiredArgsConstructor @Service public class TagPersistenceMysqlAdapter implements TagPersistencePort { - private final TagMysqlRepository tagMysqlRepository; - private final TagEntityMapper tagEntityMapper; + private TagMysqlRepository tagMysqlRepository; + private TagEntityMapper tagEntityMapper; @Override public Tag createTag(Tag tag) { diff --git a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/entity/TagEntity.java b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/entity/TagEntity.java index e8a43789..9fb2d943 100644 --- a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/entity/TagEntity.java +++ b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/entity/TagEntity.java @@ -1,11 +1,8 @@ package com.sopromadze.blogapi.infrastructure.persistence.mysql.entity; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.sopromadze.blogapi.model.Post; import com.sopromadze.blogapi.model.audit.UserDateAudit; -import jakarta.persistence.*; import lombok.*; import java.util.List; @@ -15,21 +12,21 @@ @NoArgsConstructor @AllArgsConstructor @Builder -@Entity -@Table(name = "tags") -@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +//@Entity +//@Table(name = "tags") +//@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public class TagEntity extends UserDateAudit { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Id +// @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(name = "name") +// @Column(name = "name") private String name; @JsonIgnore - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "post_tag", joinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "post_id", referencedColumnName = "id")) +// @ManyToMany(fetch = FetchType.EAGER) +// @JoinTable(name = "post_tag", joinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "post_id", referencedColumnName = "id")) private List posts; } diff --git a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/repository/TagMysqlRepository.java b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/repository/TagMysqlRepository.java index 3ec0a30b..6637743c 100644 --- a/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/repository/TagMysqlRepository.java +++ b/src/main/java/com/sopromadze/blogapi/infrastructure/persistence/mysql/repository/TagMysqlRepository.java @@ -1,10 +1,21 @@ package com.sopromadze.blogapi.infrastructure.persistence.mysql.repository; import com.sopromadze.blogapi.infrastructure.persistence.mysql.entity.TagEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; -@Repository -public interface TagMysqlRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface TagMysqlRepository { TagEntity findByName(String name); + + TagEntity save(TagEntity entity); + + Page findAll(Pageable pageable); + + Optional findById(Long id); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/model/Album.java b/src/main/java/com/sopromadze/blogapi/model/Album.java index 8bcdd9bb..2aa18eea 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Album.java +++ b/src/main/java/com/sopromadze/blogapi/model/Album.java @@ -6,16 +6,15 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import lombok.Data; -import lombok.EqualsAndHashCode; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@Table(name = "albums", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) +//@Table(name = "albums", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) public class Album extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/Category.java b/src/main/java/com/sopromadze/blogapi/model/Category.java index 73af868f..a89a92d3 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Category.java +++ b/src/main/java/com/sopromadze/blogapi/model/Category.java @@ -1,23 +1,19 @@ package com.sopromadze.blogapi.model; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.sopromadze.blogapi.model.audit.UserDateAudit; import jakarta.persistence.*; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@NoArgsConstructor -@Table(name = "categories") -@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +//@NoArgsConstructor +//@Table(name = "categories") +//@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public class Category extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/Comment.java b/src/main/java/com/sopromadze/blogapi/model/Comment.java index e70bb360..8bbbf4cf 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Comment.java +++ b/src/main/java/com/sopromadze/blogapi/model/Comment.java @@ -8,14 +8,12 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@NoArgsConstructor -@Table(name = "comments") +//@NoArgsConstructor +//@Table(name = "comments") public class Comment extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/Photo.java b/src/main/java/com/sopromadze/blogapi/model/Photo.java index 399251cf..159e5f2e 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Photo.java +++ b/src/main/java/com/sopromadze/blogapi/model/Photo.java @@ -5,14 +5,12 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@NoArgsConstructor -@Table(name = "photos", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) +//@NoArgsConstructor +//@Table(name = "photos", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) public class Photo extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/Post.java b/src/main/java/com/sopromadze/blogapi/model/Post.java index 2a8f754f..31cfec8b 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Post.java +++ b/src/main/java/com/sopromadze/blogapi/model/Post.java @@ -1,24 +1,21 @@ package com.sopromadze.blogapi.model; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.sopromadze.blogapi.infrastructure.persistence.mysql.entity.TagEntity; import com.sopromadze.blogapi.model.audit.UserDateAudit; import com.sopromadze.blogapi.model.user.User; import jakarta.persistence.*; import lombok.Data; -import lombok.EqualsAndHashCode; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@Table(name = "posts", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) -@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +//@Table(name = "posts", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) +//@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public class Post extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/Todo.java b/src/main/java/com/sopromadze/blogapi/model/Todo.java index 63abadc7..275daa81 100644 --- a/src/main/java/com/sopromadze/blogapi/model/Todo.java +++ b/src/main/java/com/sopromadze/blogapi/model/Todo.java @@ -6,12 +6,11 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import lombok.Data; -import lombok.EqualsAndHashCode; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@Table(name = "todos", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) +//@Table(name = "todos", uniqueConstraints = {@UniqueConstraint(columnNames = {"title"})}) public class Todo extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/audit/DateAudit.java b/src/main/java/com/sopromadze/blogapi/model/audit/DateAudit.java index f27d0efe..f223b9d1 100644 --- a/src/main/java/com/sopromadze/blogapi/model/audit/DateAudit.java +++ b/src/main/java/com/sopromadze/blogapi/model/audit/DateAudit.java @@ -1,24 +1,20 @@ package com.sopromadze.blogapi.model.audit; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.MappedSuperclass; import lombok.Data; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.io.Serializable; import java.time.Instant; -@MappedSuperclass +//@MappedSuperclass @Data -@EntityListeners(AuditingEntityListener.class) -@JsonIgnoreProperties( - value = {"createdAt", "updatedAt"}, - allowGetters = true -) +//@EntityListeners(AuditingEntityListener.class) +//@JsonIgnoreProperties( +// value = {"createdAt", "updatedAt"}, +// allowGetters = true +//) public abstract class DateAudit implements Serializable { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/audit/UserDateAudit.java b/src/main/java/com/sopromadze/blogapi/model/audit/UserDateAudit.java index 859d257b..a21ae371 100644 --- a/src/main/java/com/sopromadze/blogapi/model/audit/UserDateAudit.java +++ b/src/main/java/com/sopromadze/blogapi/model/audit/UserDateAudit.java @@ -1,20 +1,17 @@ package com.sopromadze.blogapi.model.audit; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.Column; -import jakarta.persistence.MappedSuperclass; import lombok.Data; -import lombok.EqualsAndHashCode; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.LastModifiedBy; -@EqualsAndHashCode(callSuper = true) -@MappedSuperclass +//@EqualsAndHashCode(callSuper = true) +//@MappedSuperclass @Data -@JsonIgnoreProperties( - value = {"createdBY", "updatedBy"}, - allowGetters = true -) +//@JsonIgnoreProperties( +// value = {"createdBY", "updatedBy"}, +// allowGetters = true +//) public abstract class UserDateAudit extends DateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/role/Role.java b/src/main/java/com/sopromadze/blogapi/model/role/Role.java index ef752352..750ba50c 100644 --- a/src/main/java/com/sopromadze/blogapi/model/role/Role.java +++ b/src/main/java/com/sopromadze/blogapi/model/role/Role.java @@ -2,13 +2,12 @@ import jakarta.persistence.*; import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.NaturalId; -@Entity +//@Entity @Data -@NoArgsConstructor -@Table(name = "roles") +//@NoArgsConstructor +//@Table(name = "roles") public class Role { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/sopromadze/blogapi/model/user/Address.java b/src/main/java/com/sopromadze/blogapi/model/user/Address.java index ef028ca9..e197cb57 100644 --- a/src/main/java/com/sopromadze/blogapi/model/user/Address.java +++ b/src/main/java/com/sopromadze/blogapi/model/user/Address.java @@ -10,10 +10,10 @@ import java.time.Instant; @EqualsAndHashCode(callSuper = true) -@Entity +//@Entity @Data @NoArgsConstructor -@Table(name = "address") +//@Table(name = "address") public class Address extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/user/Company.java b/src/main/java/com/sopromadze/blogapi/model/user/Company.java index 3624e3ce..95e2660c 100644 --- a/src/main/java/com/sopromadze/blogapi/model/user/Company.java +++ b/src/main/java/com/sopromadze/blogapi/model/user/Company.java @@ -10,10 +10,10 @@ import java.time.Instant; @EqualsAndHashCode(callSuper = true) -@Entity +//@Entity @Data @NoArgsConstructor -@Table(name = "company") +//@Table(name = "company") public class Company extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/user/Geo.java b/src/main/java/com/sopromadze/blogapi/model/user/Geo.java index 28ccaa9f..eb7e0c09 100644 --- a/src/main/java/com/sopromadze/blogapi/model/user/Geo.java +++ b/src/main/java/com/sopromadze/blogapi/model/user/Geo.java @@ -3,17 +3,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.sopromadze.blogapi.model.audit.UserDateAudit; import jakarta.persistence.*; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import java.time.Instant; -@EqualsAndHashCode(callSuper = true) -@Entity -@Data -@NoArgsConstructor -@Table(name = "geo") +//@EqualsAndHashCode(callSuper = true) +//@Entity +//@Data +//@NoArgsConstructor +//@Table(name = "geo") public class Geo extends UserDateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/model/user/User.java b/src/main/java/com/sopromadze/blogapi/model/user/User.java index 3833f928..a4a9bafd 100644 --- a/src/main/java/com/sopromadze/blogapi/model/user/User.java +++ b/src/main/java/com/sopromadze/blogapi/model/user/User.java @@ -13,20 +13,18 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import org.hibernate.annotations.NaturalId; import java.util.ArrayList; import java.util.Collections; import java.util.List; -@EqualsAndHashCode(callSuper = true) -@Entity +//@EqualsAndHashCode(callSuper = true) +//@Entity @Data -@NoArgsConstructor -@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"username"}), - @UniqueConstraint(columnNames = {"email"})}) +//@NoArgsConstructor +//@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"username"}), +// @UniqueConstraint(columnNames = {"email"})}) public class User extends DateAudit { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/sopromadze/blogapi/repository/AlbumRepository.java b/src/main/java/com/sopromadze/blogapi/repository/AlbumRepository.java index 12d6837f..e73f777e 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/AlbumRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/AlbumRepository.java @@ -3,10 +3,19 @@ import com.sopromadze.blogapi.model.Album; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository -public interface AlbumRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface AlbumRepository { Page findByCreatedBy(Long userId, Pageable pageable); + + Optional findById(Long albumId); + + Page findAll(Pageable pageable); + + Album save(Album album); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/repository/CategoryRepository.java b/src/main/java/com/sopromadze/blogapi/repository/CategoryRepository.java index 55c00914..10ddd39e 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/CategoryRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/CategoryRepository.java @@ -1,10 +1,20 @@ package com.sopromadze.blogapi.repository; import com.sopromadze.blogapi.model.Category; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; -@Repository -public interface CategoryRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface CategoryRepository { + + Page findAll(Pageable pageable); + + Optional findById(Long id); + + Category save(Category category); + + void deleteById(Long id); } diff --git a/src/main/java/com/sopromadze/blogapi/repository/CommentRepository.java b/src/main/java/com/sopromadze/blogapi/repository/CommentRepository.java index b4fb3be3..6171a1ad 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/CommentRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/CommentRepository.java @@ -3,10 +3,17 @@ import com.sopromadze.blogapi.model.Comment; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository -public interface CommentRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface CommentRepository { Page findByPostId(Long postId, Pageable pageable); + + Comment save(Comment comment); + + Optional findById(Long id); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/repository/PhotoRepository.java b/src/main/java/com/sopromadze/blogapi/repository/PhotoRepository.java index a6f52698..568ab151 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/PhotoRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/PhotoRepository.java @@ -3,10 +3,19 @@ import com.sopromadze.blogapi.model.Photo; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository -public interface PhotoRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface PhotoRepository { Page findByAlbumId(Long albumId, Pageable pageable); + + Page findAll(Pageable pageable); + + Optional findById(Long id); + + Photo save(Photo photo); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/repository/PostRepository.java b/src/main/java/com/sopromadze/blogapi/repository/PostRepository.java index 79dd792e..a6f2b5c3 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/PostRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/PostRepository.java @@ -4,13 +4,12 @@ import com.sopromadze.blogapi.model.Post; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; -@Repository -public interface PostRepository extends JpaRepository { +//@Repository +public interface PostRepository { Page findByCreatedBy(Long userId, Pageable pageable); Page findByCategory(Long categoryId, Pageable pageable); @@ -18,4 +17,13 @@ public interface PostRepository extends JpaRepository { Page findByTags(List tags, Pageable pageable); Long countByCreatedBy(Long userId); + + Optional findById(Long postId); + + Page findAll(Pageable pageable); + + Post save(Post post); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/repository/RoleRepository.java b/src/main/java/com/sopromadze/blogapi/repository/RoleRepository.java index 067294c6..485c535d 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/RoleRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/RoleRepository.java @@ -2,10 +2,9 @@ import com.sopromadze.blogapi.model.role.Role; import com.sopromadze.blogapi.model.role.RoleName; -import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; -public interface RoleRepository extends JpaRepository { +public interface RoleRepository { Optional findByName(RoleName name); } diff --git a/src/main/java/com/sopromadze/blogapi/repository/TodoRepository.java b/src/main/java/com/sopromadze/blogapi/repository/TodoRepository.java index 3cb55e71..e19c150f 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/TodoRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/TodoRepository.java @@ -3,10 +3,17 @@ import com.sopromadze.blogapi.model.Todo; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository -public interface TodoRepository extends JpaRepository { +import java.util.Optional; + +//@Repository +public interface TodoRepository { Page findByCreatedBy(Long userId, Pageable pageable); + + Optional findById(Long id); + + Todo save(Todo todo); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/repository/UserRepository.java b/src/main/java/com/sopromadze/blogapi/repository/UserRepository.java index 846595d7..d549bcde 100644 --- a/src/main/java/com/sopromadze/blogapi/repository/UserRepository.java +++ b/src/main/java/com/sopromadze/blogapi/repository/UserRepository.java @@ -4,13 +4,11 @@ import com.sopromadze.blogapi.model.user.User; import com.sopromadze.blogapi.security.UserPrincipal; import jakarta.validation.constraints.NotBlank; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; import java.util.Optional; -@Repository -public interface UserRepository extends JpaRepository { +//@Repository +public interface UserRepository { Optional findByUsername(@NotBlank String username); Optional findByEmail(@NotBlank String email); @@ -29,4 +27,13 @@ default User getUserByName(String username) { return findByUsername(username) .orElseThrow(() -> new ResourceNotFoundException("User", "username", username)); } + + int count(); + + User save(User user); + + Optional findById(Long id); + + void deleteById(Long id); + } diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/AlbumServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/AlbumServiceImpl.java index 6964008e..07f0e01a 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/AlbumServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/AlbumServiceImpl.java @@ -39,10 +39,10 @@ public class AlbumServiceImpl implements AlbumService { private static final String YOU_DON_T_HAVE_PERMISSION_TO_MAKE_THIS_OPERATION = "You don't have permission to make this operation"; - @Autowired +// @Autowired private AlbumRepository albumRepository; - @Autowired +// @Autowired private UserRepository userRepository; @Autowired diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/CategoryServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/CategoryServiceImpl.java index a98064b3..6cb32cfb 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/CategoryServiceImpl.java @@ -10,7 +10,6 @@ import com.sopromadze.blogapi.security.UserPrincipal; import com.sopromadze.blogapi.service.CategoryService; import com.sopromadze.blogapi.utils.AppUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -26,7 +25,7 @@ @Service public class CategoryServiceImpl implements CategoryService { - @Autowired +// @Autowired private CategoryRepository categoryRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/CommentServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/CommentServiceImpl.java index 00258de7..08d34b6d 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/CommentServiceImpl.java @@ -15,7 +15,6 @@ import com.sopromadze.blogapi.security.UserPrincipal; import com.sopromadze.blogapi.service.CommentService; import com.sopromadze.blogapi.utils.AppUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -38,13 +37,13 @@ public class CommentServiceImpl implements CommentService { private static final String COMMENT_DOES_NOT_BELONG_TO_POST = "Comment does not belong to post"; - @Autowired +// @Autowired private CommentRepository commentRepository; - @Autowired +// @Autowired private PostRepository postRepository; - @Autowired +// @Autowired private UserRepository userRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/CustomUserDetailsServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/CustomUserDetailsServiceImpl.java index f00dfa3a..b8015ef2 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/CustomUserDetailsServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/CustomUserDetailsServiceImpl.java @@ -5,7 +5,6 @@ import com.sopromadze.blogapi.security.UserPrincipal; import com.sopromadze.blogapi.service.CustomUserDetailsService; import jakarta.transaction.Transactional; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -13,7 +12,7 @@ @Service public class CustomUserDetailsServiceImpl implements UserDetailsService, CustomUserDetailsService { - @Autowired +// @Autowired private UserRepository userRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/PhotoServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/PhotoServiceImpl.java index dfa90b86..fff90441 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/PhotoServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/PhotoServiceImpl.java @@ -15,7 +15,6 @@ import com.sopromadze.blogapi.service.PhotoService; import com.sopromadze.blogapi.utils.AppConstants; import com.sopromadze.blogapi.utils.AppUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -27,18 +26,15 @@ import java.util.Collections; import java.util.List; -import static com.sopromadze.blogapi.utils.AppConstants.ALBUM; -import static com.sopromadze.blogapi.utils.AppConstants.CREATED_AT; -import static com.sopromadze.blogapi.utils.AppConstants.ID; -import static com.sopromadze.blogapi.utils.AppConstants.PHOTO; +import static com.sopromadze.blogapi.utils.AppConstants.*; @Service public class PhotoServiceImpl implements PhotoService { - @Autowired +// @Autowired private PhotoRepository photoRepository; - @Autowired +// @Autowired private AlbumRepository albumRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/PostServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/PostServiceImpl.java index 4c71ddec..088da2b1 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/PostServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/PostServiceImpl.java @@ -20,7 +20,6 @@ import com.sopromadze.blogapi.service.PostService; import com.sopromadze.blogapi.utils.AppConstants; import com.sopromadze.blogapi.utils.AppUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -36,16 +35,16 @@ @Service public class PostServiceImpl implements PostService { - @Autowired +// @Autowired private PostRepository postRepository; - @Autowired +// @Autowired private UserRepository userRepository; - @Autowired +// @Autowired private CategoryRepository categoryRepository; - @Autowired +// @Autowired private TagMysqlRepository tagMysqlRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/TagServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/TagServiceImpl.java index ce2fbcbf..d4ba32ea 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/TagServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/TagServiceImpl.java @@ -10,7 +10,6 @@ import com.sopromadze.blogapi.security.UserPrincipal; import com.sopromadze.blogapi.service.TagService; import com.sopromadze.blogapi.utils.AppUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -24,7 +23,7 @@ @Service public class TagServiceImpl implements TagService { - @Autowired +// @Autowired private TagMysqlRepository tagMysqlRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/TodoServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/TodoServiceImpl.java index 9ef3b2e8..4aeb7470 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/TodoServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/TodoServiceImpl.java @@ -12,7 +12,6 @@ import com.sopromadze.blogapi.security.UserPrincipal; import com.sopromadze.blogapi.service.TodoService; import com.sopromadze.blogapi.utils.AppConstants; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -22,18 +21,15 @@ import java.util.Collections; import java.util.List; -import static com.sopromadze.blogapi.utils.AppConstants.CREATED_AT; -import static com.sopromadze.blogapi.utils.AppConstants.ID; -import static com.sopromadze.blogapi.utils.AppConstants.TODO; -import static com.sopromadze.blogapi.utils.AppConstants.YOU_DON_T_HAVE_PERMISSION_TO_MAKE_THIS_OPERATION; +import static com.sopromadze.blogapi.utils.AppConstants.*; @Service public class TodoServiceImpl implements TodoService { - @Autowired +// @Autowired private TodoRepository todoRepository; - @Autowired +// @Autowired private UserRepository userRepository; @Override diff --git a/src/main/java/com/sopromadze/blogapi/service/impl/UserServiceImpl.java b/src/main/java/com/sopromadze/blogapi/service/impl/UserServiceImpl.java index d740f27b..07ad35ce 100644 --- a/src/main/java/com/sopromadze/blogapi/service/impl/UserServiceImpl.java +++ b/src/main/java/com/sopromadze/blogapi/service/impl/UserServiceImpl.java @@ -1,21 +1,13 @@ package com.sopromadze.blogapi.service.impl; -import com.sopromadze.blogapi.exception.AccessDeniedException; -import com.sopromadze.blogapi.exception.AppException; -import com.sopromadze.blogapi.exception.BadRequestException; -import com.sopromadze.blogapi.exception.ResourceNotFoundException; -import com.sopromadze.blogapi.exception.UnauthorizedException; +import com.sopromadze.blogapi.exception.*; import com.sopromadze.blogapi.model.role.Role; import com.sopromadze.blogapi.model.role.RoleName; import com.sopromadze.blogapi.model.user.Address; import com.sopromadze.blogapi.model.user.Company; import com.sopromadze.blogapi.model.user.Geo; import com.sopromadze.blogapi.model.user.User; -import com.sopromadze.blogapi.payload.ApiResponse; -import com.sopromadze.blogapi.payload.InfoRequest; -import com.sopromadze.blogapi.payload.UserIdentityAvailability; -import com.sopromadze.blogapi.payload.UserProfile; -import com.sopromadze.blogapi.payload.UserSummary; +import com.sopromadze.blogapi.payload.*; import com.sopromadze.blogapi.repository.PostRepository; import com.sopromadze.blogapi.repository.RoleRepository; import com.sopromadze.blogapi.repository.UserRepository; @@ -32,13 +24,13 @@ @Service public class UserServiceImpl implements UserService { - @Autowired +// @Autowired private UserRepository userRepository; - @Autowired +// @Autowired private PostRepository postRepository; - @Autowired +// @Autowired private RoleRepository roleRepository; @Autowired diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ef6d7e3d..b32cf06e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:mysql://blogapi-db:3306/blogapi?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true + url: jdbc:postgresql://localhost:5432/blogapi?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true username: root password: root jpa: @@ -9,7 +9,7 @@ spring: show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.MySQL5Dialect + dialect: org.hibernate.dialect.PostgreSQLDialect jackson: serialization: WRITE_DATES_AS_TIMESTAMPS: false @@ -20,4 +20,4 @@ app: jwtExpirationInMs: 3600000 cors: - allowedOrings: '*' + allowed_origins: '*' diff --git a/src/test/java/cucumber/CucumberSpringConfiguration.java b/src/test/java/cucumber/CucumberSpringConfiguration.java new file mode 100644 index 00000000..90bffdf5 --- /dev/null +++ b/src/test/java/cucumber/CucumberSpringConfiguration.java @@ -0,0 +1,24 @@ +package cucumber; + +import io.cucumber.spring.CucumberContextConfiguration; +import jakarta.annotation.PostConstruct; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; + +//@ActiveProfiles("dev") +@CucumberContextConfiguration +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = TestConfig.class +) +public class CucumberSpringConfiguration { + + @LocalServerPort + private int port; + + @PostConstruct + public void setup() { + System.setProperty("port", String.valueOf(port)); + } + +} \ No newline at end of file diff --git a/src/test/java/cucumber/RunCucumberIT.java b/src/test/java/cucumber/RunCucumberIT.java new file mode 100644 index 00000000..6cf8aac8 --- /dev/null +++ b/src/test/java/cucumber/RunCucumberIT.java @@ -0,0 +1,18 @@ +package cucumber; + +import io.cucumber.core.options.Constants; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectClasspathResource; +import org.junit.platform.suite.api.Suite; + +import static io.cucumber.core.options.Constants.GLUE_PROPERTY_NAME; + +@Suite +@IncludeEngines("cucumber") +@SelectClasspathResource("cucumber") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "cucumber") +@ConfigurationParameter(key = Constants.EXECUTION_DRY_RUN_PROPERTY_NAME,value = "false") +public class RunCucumberIT { + +} diff --git a/src/test/java/cucumber/TestConfig.java b/src/test/java/cucumber/TestConfig.java new file mode 100644 index 00000000..2de0e795 --- /dev/null +++ b/src/test/java/cucumber/TestConfig.java @@ -0,0 +1,15 @@ +package cucumber; + +import com.sopromadze.blogapi.BlogApiApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan(basePackages = "com.sopromadze.blogapi") +@EnableAutoConfiguration +@EntityScan(basePackageClasses = {BlogApiApplication.class}) +public class TestConfig { + +} diff --git a/src/test/java/cucumber/helper/RestClient.java b/src/test/java/cucumber/helper/RestClient.java new file mode 100644 index 00000000..f6508724 --- /dev/null +++ b/src/test/java/cucumber/helper/RestClient.java @@ -0,0 +1,24 @@ +package cucumber.helper; + +import io.restassured.http.ContentType; +import io.restassured.specification.RequestSpecification; +import org.springframework.stereotype.Component; + +import static io.restassured.RestAssured.given; + +@Component +public class RestClient { + + public RequestSpecification getRequestSpecification() { + int port = Integer.parseInt(System.getProperty("port")); + + return given() + .port(port) + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .urlEncodingEnabled(false) + .when() + .log() + .everything(); + } +} diff --git a/src/test/java/cucumber/steps/TestStep.java b/src/test/java/cucumber/steps/TestStep.java new file mode 100644 index 00000000..056fa5b3 --- /dev/null +++ b/src/test/java/cucumber/steps/TestStep.java @@ -0,0 +1,21 @@ +package cucumber.steps; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TestStep { + + private String test; + + @Given("make request") + public void makeRequest() { + test = "test"; + } + + @Then("response is") + public void responseIs() { + assertThat(test).isEqualTo("test"); + } +} diff --git a/src/test/resources/cucumber/test.feature b/src/test/resources/cucumber/test.feature new file mode 100644 index 00000000..397cdfce --- /dev/null +++ b/src/test/resources/cucumber/test.feature @@ -0,0 +1,7 @@ +Feature: test + Scenario: test + When make request + Then response is + + Example: + |test| \ No newline at end of file diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties new file mode 100644 index 00000000..69ef4436 --- /dev/null +++ b/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +cucumber.publish.quiet=true +cucumber.publish.enabled=false +cucumber.plugin=pretty, html:target/cucumber-reports/Cucumber.html \ No newline at end of file