Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 186 additions & 72 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.aquent</groupId>
<artifactId>crud-app</artifactId>
<packaging>war</packaging>
<version>1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<scm>
<url>https://github.com/aquent/crud-app</url>
<connection>scm:git:git://github.com/aquent/crud-app.git</connection>
<developerConnection>scm:git:git@github.com:aquent/crud-app.git</developerConnection>
</scm>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.1.Final</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.aquent</groupId>
<artifactId>crud-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>crudapi</name>
<description>Aquent CRUD APP</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<org.mapstruct.version>1.5.2.Final</org.mapstruct.version>
</properties>

<!-- <scm>-->
<!-- <url>https://github.com/aquent/crud-app</url>-->
<!-- <connection>scm:git:git://github.com/aquent/crud-app.git</connection>-->
<!-- <developerConnection>scm:git:git@github.com:aquent/crud-app.git</developerConnection>-->
<!-- </scm>-->

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-web</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.1.Final</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<!-- <dependency>-->
<!-- <groupId>jakarta.validation</groupId>-->
<!-- <artifactId>jakarta.validation-api</artifactId>-->
<!-- </dependency>-->

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.5.1.Final</version>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.5.1.Final</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>commons-io</groupId>-->
<!-- <artifactId>commons-io</artifactId>-->
<!-- <version>2.6</version>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-collections4</artifactId>-->
<!-- <version>4.0</version>-->
<!-- </dependency>-->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mockserver</artifactId>
<version>1.17.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>false</fork>
<addResources>true</addResources>
</configuration>
<version>2.5.1</version>
</plugin>
</plugins>
</build>

</project>
6 changes: 5 additions & 1 deletion src/main/java/com/aquent/crudapp/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.aquent.crudapp"})
@EnableJpaRepositories("com.aquent.crudapp")
@Configuration
public class Application {

public static void main(String[] args) {
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/aquent/crudapp/controllers/BaseController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.aquent.crudapp.controllers;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.util.List;

/**
* This class acts as base class for all the controllers
* @param <T>
* */
public abstract class BaseController<T> {

/**
* This method generates the no content response for read by id operation
* @param entity
* */
protected ResponseEntity<T> generateResourceGetByIdNoContentResponse(T entity) {
return new ResponseEntity<>(entity, HttpStatus.NO_CONTENT);
}

/**
* This method generates the no content response for read all operation
* @param entities
* */
protected ResponseEntity<List<T>> generateResourceGetAllNoContentResponse(List<T> entities) {
return new ResponseEntity<>(entities, HttpStatus.NO_CONTENT);
}

/**
* This method generates the required response for read by id operation
* @param entity
* */
protected ResponseEntity<T> generateResourceGetByIdResponseOk(T entity) {
return new ResponseEntity<>(entity, HttpStatus.OK);
}

/**
* This method generates the required response for read all operation
* @param entities
* */
protected ResponseEntity<List<T>> generateResourceGetAllResponseOk(List<T> entities) {
return new ResponseEntity<>(entities, HttpStatus.OK);
}

/**
* This method generates the required response for create operation
* @param id
* */
protected ResponseEntity generateResourceCreatedResponse(Integer id) {
URI location = ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(id).toUri();

return ResponseEntity.created(location).build();
}

protected ResponseEntity<T> generateResourceCreatedResponse() {
return new ResponseEntity<>(HttpStatus.REQUEST_TIMEOUT);
}

/**
* This method generates the errors response for create operation
* @param errors
* */
protected ResponseEntity<List<T>> generateResourceCreatedResponse(List<T> errors) {
return new ResponseEntity<>(errors, HttpStatus.OK);
}

/**
* This method generates the required response for delete operation
* @param message
* */
protected ResponseEntity<T> generateStringResponse(T message) {
return new ResponseEntity<>(message, HttpStatus.OK);
}
}
Loading