Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roar-skinderviken committed Jul 2, 2024
1 parent a928957 commit 90a746e
Show file tree
Hide file tree
Showing 29 changed files with 6,593 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
- package-ecosystem: gradle
directory: "/"
schedule:
interval: daily
time: "03:00"
timezone: Europe/Oslo
open-pull-requests-limit: 10

- package-ecosystem: npm
versioning-strategy: increase
directory: "/web-frontend"
schedule:
interval: daily
time: "03:00"
timezone: Europe/Oslo
open-pull-requests-limit: 10
groups:
npm-dependencies:
patterns:
- "*"
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node
node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# spring-react-calculator
# spring-react-calculator

Starte React/Vite utviklingsmiljø
```bash
cd ./frontend
npm install
npm run dev
```
Backend må være tilgjengelig på port 8080.
Frontend vil være tilgjengelig på http://localhost/8081.
29 changes: 29 additions & 0 deletions backend/src/main/java/no/javatec/calc/ApiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package no.javatec.calc;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApiController {

// URL for testing localhost: http://localhost:8080/api/5/10/plus
// URL for testing: https://vicx.no/sample/api/5/10/plus

private final CalculatorService calculatorService;

public ApiController(CalculatorService calculatorService) {
this.calculatorService = calculatorService;
}

@RequestMapping(
value = "/api/{firstValue}/{secondValue}/{operation}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public CalcVm index(
@PathVariable long firstValue,
@PathVariable long secondValue,
@PathVariable String operation) {

return calculatorService.calculate(firstValue, secondValue, operation);
}
}
9 changes: 9 additions & 0 deletions backend/src/main/java/no/javatec/calc/CalcVm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package no.javatec.calc;

public record CalcVm(
long firstValue,
long secondValue,
String operation,
Long result
) {
}
12 changes: 12 additions & 0 deletions backend/src/main/java/no/javatec/calc/CalculatorApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.javatec.calc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CalculatorApplication {

public static void main(String[] args) {
SpringApplication.run(CalculatorApplication.class, args);
}
}
17 changes: 17 additions & 0 deletions backend/src/main/java/no/javatec/calc/CalculatorService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package no.javatec.calc;

import org.springframework.stereotype.Service;

@Service
public class CalculatorService {

public CalcVm calculate(long firstValue, long secondValue, String operation) {
Long result = switch (operation) {
case "plus" -> firstValue + secondValue;
case "minus" -> firstValue - secondValue;
default -> null;
};

return new CalcVm(firstValue, secondValue, operation, result);
}
}
12 changes: 12 additions & 0 deletions backend/src/main/java/no/javatec/calc/ServletInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.javatec.calc;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(CalculatorApplication.class);
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.application.name=spring-react-calculator
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group = "no.javatec.calculator"
version = "0.0.1-SNAPSHOT"
10 changes: 10 additions & 0 deletions frontend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("org.siouan.frontend-jdk21") version "8.1.0"
}

frontend {
nodeVersion.set("20.14.0")
assembleScript.set("run build")
cleanScript.set("run clean")
checkScript.set("run clean") // Change this line when you add tests
}
13 changes: 13 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body class="bg-light">
<div id="root" class="container"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit 90a746e

Please sign in to comment.