Skip to content

Commit

Permalink
Merge pull request #2 from navreddy23/springboot_setup
Browse files Browse the repository at this point in the history
api contract specification setup
  • Loading branch information
navreddy23 authored Aug 28, 2021
2 parents 0d6a8ed + 97d544e commit e62d226
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ mvnw.cmd
target/
HELP.md
.idea/
*.iws
*.iml
*.ipr
/out/
/src/generated/
102 changes: 98 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
<logstash.logback.encoder.version>6.6</logstash.logback.encoder.version>
<puppycrawl.tools.version>8.11</puppycrawl.tools.version>
<maven.checkstyle.plugin.version>3.0.0</maven.checkstyle.plugin.version>
<jsonschema2pojo.plugin.version>1.0.0</jsonschema2pojo.plugin.version>
<mvn.pmd.verion>3.14.0</mvn.pmd.verion>
<javax.validation.verion>1.1.0.Final</javax.validation.verion>


<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
Expand All @@ -33,10 +35,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency> -->
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -53,10 +55,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -115,6 +117,10 @@
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -159,6 +165,11 @@
<artifactId>checkstyle</artifactId>
<version>${puppycrawl.tools.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.verion}</version>
</dependency>
</dependencies>
</dependencyManagement>
<reporting>
Expand All @@ -177,6 +188,11 @@
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>com.groupon.maven.plugin.json</groupId>
<artifactId>json-schema-validator</artifactId>
<version>VERSION</version>
</plugin>
</plugins>
</reporting>
<build>
Expand Down Expand Up @@ -239,6 +255,84 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/generated/models/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>${jsonschema2pojo.plugin.version}</version>
<executions>
<execution>
<id>generate-schemas</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/api_contract_schema_specs/</sourceDirectory>
<targetPackage>com.manager.takehome.challenge</targetPackage>
<outputDirectory>${project.basedir}/src/generated/models/</outputDirectory>
<generateBuilders>true</generateBuilders>
<annotationStyle>jackson2</annotationStyle>
<includeJsr303Annotations>true</includeJsr303Annotations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<!-- clean generated every time-->
<directory>src/generated/</directory>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<phase>validate</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>json-schema-validator</artifactId>
<groupId>com.groupon.maven.plugin.json</groupId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
<configuration>
<validations>
<validation>
<directory>${basedir}/src/main/resources/api_contract_schema_specs/</directory>
<includes>
<include>**/*.json</include>
</includes>
</validation>
</validations>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
package com.manager.takehome.challenge;

import com.manager.takehome.challenge.config.AppConfigurations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpotHeroApplication {

@Autowired
private AppConfigurations appConfig;

public static void main(String[] args) {
SpringApplication.run(SpotHeroApplication.class, args);
SpringApplication.run(SpotHeroApplication.class);
}

/**
* method to display app configs.
*/
public void run(String... args) throws Exception {
System.out.println("using environment:" + appConfig.getEnvironment());
System.out.println("using server port:" + appConfig.getServerPort());
System.out.println("using management port:" + appConfig.getManagementServerPort());
System.out.println("using management server address:" + appConfig.getManagementServerAddress());
System.out.println("using spring profile:" + appConfig.getSpringProfile());
System.out.println("using context path port: " + appConfig.getContextPath());
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.manager.takehome.challenge.controller;

import com.manager.takehome.challenge.config.AppConfigurations;
import com.manager.takehome.challenge.model.BaseModel;
import com.manager.takehome.challenge.models.BaseModel;

import com.manager.takehome.challenge.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.manager.takehome.challenge.model;
package com.manager.takehome.challenge.models;

public class BaseModel {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "object",
"description": "Response Schema for returning all ACTIVE users",
"title": "ActiveUsersResponse",
"additionalProperties": false,
"properties": {
"activeUsers": {
"type": "array",
"items": {
"$ref": "user.json"
}
},
"error": {
"type": "object",
"$ref": "error.json"
}
},
"required": [],
"$schema": "http://json-schema.org/draft-06/schema#"
}
18 changes: 18 additions & 0 deletions src/main/resources/api_contract_schema_specs/v1/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "object",
"description": "Schema for Errors",
"title": "Error",
"additionalProperties": false,
"properties": {
"errorCode": {
"type": "integer",
"description": "Error Code"
},
"errorMessage": {
"type": "string",
"description": "Error Message"
}
},
"required": [],
"$schema": "http://json-schema.org/draft-06/schema#"
}
31 changes: 31 additions & 0 deletions src/main/resources/api_contract_schema_specs/v1/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "object",
"description": "Schema describing user properties",
"title": "User",
"additionalProperties": false,
"properties": {
"managerId": {
"type": "integer",
"description": "Id number of the"
},
"firstName": {
"type": "string",
"description": "first name of the user"
},
"lastName": {
"type": "string",
"description": "last name of the user"
},
"email": {
"type": "string",
"description": "email address of the user"
}
},
"required": [
"firstName",
"lastName",
"email",
"isActive"
],
"$schema": "http://json-schema.org/draft-06/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"description": "Request schema to post new worked hours",
"title": "WorkedHoursRequest",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"description": "Id number of the"
},
"date": {
"type": "string",
"format": "date-time",
"description": "date on which hours were recorded"
},
"hours": {
"type": "number",
"description": "first name of the user"
}
},
"required": ["id", "date", "hours"],
"$schema": "http://json-schema.org/draft-06/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "object",
"description": "Response schema after posting new worked hours",
"title": "WorkedHoursPostageResponse",
"additionalProperties": false,
"properties": {
"postageSuccess": {
"type": "boolean",
"description": "were the hours posted successfully? true or false"
},
"message": {
"type": "string",
"description": "verbose message"
},
"error": {
"type": "object",
"$ref": "error.json"
}
},
"required": [],
"$schema": "http://json-schema.org/draft-06/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "object",
"description": "Response schema for returning details about all the hours worked by a user",
"title": "WorkedHoursResponse",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"description": "Id number of the"
},
"date": {
"type": "string",
"format": "date-time",
"description": "date on which hours were recorded"
},
"hours": {
"type": "number",
"description": "first name of the user"
},
"error": {
"type": "object",
"$ref": "error.json"
}
},
"required": [],
"$schema": "http://json-schema.org/draft-06/schema#"
}
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
spring:
profiles: default
datasource:
url: "jdbc:postgresql://localhost:5432/userhours_dev"
username: userhours_user
password: Super-e3cret

server:
port: 8080
Expand All @@ -11,4 +15,4 @@ management:
address: 127.0.0.1
port: 9090
security:
enabled: false
enabled: true
Loading

0 comments on commit e62d226

Please sign in to comment.