-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ARUP-G/app-1
Application added to scm
- Loading branch information
Showing
65 changed files
with
2,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.5.6</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.javaproject</groupId> | ||
<artifactId>database_service_project</artifactId> | ||
<version>0.0.2</version> | ||
<name>database_service_project</name> | ||
<description>Project for Spring Boot</description> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<java.version>11</java.version> | ||
<jacoco.version>0.8.7</jacoco.version> | ||
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> | ||
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> | ||
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath> | ||
<sonar.language>java</sonar.language> | ||
|
||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.thymeleaf.extras</groupId> | ||
<artifactId>thymeleaf-extras-springsecurity5</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>0.8.7</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<excludes> | ||
<exclude> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>${jacoco.version}</version> | ||
<executions> | ||
<execution> | ||
<id>jacoco-initialize</id> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>jacoco-site</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
|
||
</project> |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/javaproject/DatabaseServiceProjectApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.javaproject; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DatabaseServiceProjectApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DatabaseServiceProjectApplication.class, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.javaproject.beans; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class BoardGame { | ||
|
||
private Long id; | ||
private String name; | ||
private int level; | ||
private int minPlayers; | ||
private String maxPlayers; | ||
private String gameType; | ||
|
||
private List<Review> reviews; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.javaproject.beans; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class ErrorMessage { | ||
private final String STATUS = "error"; | ||
|
||
private String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.javaproject.beans; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Review { | ||
|
||
private Long id; | ||
private Long gameId; | ||
private String text; | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/javaproject/controllers/BoardGameController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.javaproject.controllers; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
import org.apache.catalina.connector.Response; | ||
import org.hibernate.boot.model.relational.Database; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import com.javaproject.beans.BoardGame; | ||
import com.javaproject.beans.ErrorMessage; | ||
import com.javaproject.beans.Review; | ||
import com.javaproject.database.DatabaseAccess; | ||
|
||
// special type of controller that is specialized for REST purpose. It marshals our domain objects to and from json | ||
@RestController | ||
@RequestMapping("/boardgames") | ||
public class BoardGameController { | ||
|
||
private DatabaseAccess da; | ||
|
||
public BoardGameController(DatabaseAccess da) { | ||
this.da = da; | ||
} | ||
|
||
/** | ||
* Retrieve all boardgames | ||
* | ||
* @return | ||
*/ | ||
@GetMapping | ||
public List<BoardGame> getBoardGames() { | ||
return da.getBoardGames(); | ||
} | ||
|
||
/** | ||
* Handles requests for specific boardgame | ||
* | ||
* @param id | ||
* @return the ResponseEntity | ||
*/ | ||
@GetMapping("/{id}") | ||
public ResponseEntity<?> getBoardGame(@PathVariable Long id) { | ||
BoardGame boardGame = da.getBoardGame(id); | ||
if (boardGame != null) { | ||
return ResponseEntity.ok(boardGame); | ||
} else { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorMessage("No such record")); | ||
} | ||
} | ||
|
||
@PostMapping(consumes = "application/json") | ||
public ResponseEntity<?> postBoardGame(@RequestBody BoardGame boardGame) { | ||
try { | ||
Long id = da.addBoardGame(boardGame); | ||
boardGame.setId(id); | ||
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri(); | ||
return ResponseEntity.created(location).body(boardGame); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorMessage("Name already exists.")); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.