Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d507bd26

Přidáno uživatelem Václav Honzík před více než 2 roky(ů)

Java backend API init re #9106

Zobrazit rozdíly:

backend/HELP.md
1
# Read Me First
2
The following was discovered as part of building this project:
3

  
4
* The original package name 'cz.zcu.kiv.backend-api' is invalid and this project uses 'cz.zcu.kiv.backendapi' instead.
5

  
1 6
# Getting Started
2 7

  
3 8
### Reference Documentation
4

  
5 9
For further reference, please consider the following sections:
6 10

  
7 11
* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
8 12
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/)
9 13
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/#build-image)
10
* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/2.6.4/reference/htmlsingle/#boot-features-jpa-and-spring-data)
14
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.6.4/reference/htmlsingle/#boot-features-developing-web-applications)
11 15

  
12 16
### Guides
13

  
14 17
The following guides illustrate how to use some features concretely:
15 18

  
16
* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
19
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
20
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
21
* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)
17 22

  
backend/pom.xml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 3
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4
    <modelVersion>4.0.0</modelVersion>
5 5
    <parent>
6 6
        <groupId>org.springframework.boot</groupId>
7 7
        <artifactId>spring-boot-starter-parent</artifactId>
8 8
        <version>2.6.4</version>
9
        <relativePath/> <!-- lookup parent from repository -->
9
        <relativePath/>
10 10
    </parent>
11 11
    <groupId>cz.zcu.kiv</groupId>
12
    <artifactId>backend</artifactId>
12
    <artifactId>backend-api</artifactId>
13 13
    <version>0.0.1-SNAPSHOT</version>
14
    <name>backend</name>
15
    <description>Java API Backend</description>
14
    <name>backend-api</name>
15
    <description>Backend API for Neo-assyrian web application</description>
16 16
    <properties>
17 17
        <java.version>17</java.version>
18 18
    </properties>
......
21 21
            <groupId>org.springframework.boot</groupId>
22 22
            <artifactId>spring-boot-starter-web</artifactId>
23 23
        </dependency>
24

  
24 25
        <dependency>
25 26
            <groupId>org.projectlombok</groupId>
26 27
            <artifactId>lombok</artifactId>
27 28
            <optional>true</optional>
28 29
        </dependency>
29 30
        <dependency>
30
            <groupId>org.apache.logging.log4j</groupId>
31
            <artifactId>log4j-api</artifactId>
32
            <version>2.17.2</version>
33
        </dependency>
34
        <dependency>
35
            <groupId>org.apache.logging.log4j</groupId>
36
            <artifactId>log4j-core</artifactId>
37
            <version>2.17.2</version>
38
        </dependency>
39
        <dependency>
40
            <groupId>org.springframework</groupId>
41
            <artifactId>spring-webmvc</artifactId>
42
            <version>5.0.6.RELEASE</version>
31
            <groupId>org.springframework.boot</groupId>
32
            <artifactId>spring-boot-starter-test</artifactId>
33
            <scope>test</scope>
43 34
        </dependency>
44 35
    </dependencies>
45 36

  
backend/src/main/java/cz/zcu/kiv/backend/BackendApplication.java
1
package cz.zcu.kiv.backend;
2
//
3

  
4
import org.slf4j.Logger;
5
import org.slf4j.LoggerFactory;
6
import org.springframework.boot.SpringApplication;
7
import org.springframework.boot.autoconfigure.SpringBootApplication;
8

  
9
@SpringBootApplication
10
public class BackendApplication {
11

  
12
    public static final Logger LOGGER = LoggerFactory.getLogger(BackendApplication.class);
13

  
14
    public static void main(String[] args) {
15
        SpringApplication.run(BackendApplication.class, args);
16
        LOGGER.info("HELLO");
17

  
18

  
19
    }
20

  
21
}
backend/src/main/java/cz/zcu/kiv/backend/controller/StubController.java
1
package cz.zcu.kiv.backend.controller;
2

  
3
import lombok.AllArgsConstructor;
4
import org.slf4j.Logger;
5
import org.slf4j.LoggerFactory;
6
import org.springframework.stereotype.Controller;
7
import org.springframework.web.bind.annotation.GetMapping;
8

  
9
@Controller
10
public class StubController {
11

  
12
    public static final Logger LOGGER = LoggerFactory.getLogger(StubController.class);
13

  
14
    @GetMapping("/stub")
15
    public Response stub() {
16
        LOGGER.debug("Stub");
17
        return new Response(0, "Stub response");
18
    }
19

  
20
    @AllArgsConstructor
21
    class Response {
22
        int resCode;
23
        String text;
24
    }
25
}
backend/src/main/java/cz/zcu/kiv/backendapi/BackendApiApplication.java
1
package cz.zcu.kiv.backendapi;
2

  
3
import java.util.logging.Logger;
4
import org.springframework.boot.SpringApplication;
5
import org.springframework.boot.autoconfigure.SpringBootApplication;
6

  
7
@SpringBootApplication
8
public class BackendApiApplication {
9

  
10
	// TODO replace with log4j?
11
	public static final Logger LOGGER = Logger.getLogger(BackendApiApplication.class.getName());
12

  
13
	public static void main(String[] args) {
14
		LOGGER.info("Starting ...");
15
		SpringApplication.run(BackendApiApplication.class, args);
16
	}
17

  
18
}
backend/src/main/java/cz/zcu/kiv/backendapi/StubController.java
1
package cz.zcu.kiv.backendapi;
2

  
3
import java.util.logging.Logger;
4
import org.springframework.stereotype.Controller;
5
import org.springframework.web.bind.annotation.GetMapping;
6
import org.springframework.web.bind.annotation.RestController;
7

  
8
@RestController()
9
public class StubController {
10

  
11
    public static final Logger LOGGER = Logger.getLogger(StubController.class.getName());
12

  
13

  
14
    static {
15
        LOGGER.info("StubController initialized!");
16
    }
17

  
18
    @GetMapping("/stub")
19
    public StubDto getStubDto() {
20
        return new StubDto("Hello API", true);
21
    }
22
}
backend/src/main/java/cz/zcu/kiv/backendapi/StubDto.java
1
package cz.zcu.kiv.backendapi;
2

  
3

  
4
import lombok.AllArgsConstructor;
5
public record StubDto(String message, Boolean success) {}
map_frameworks/.gitignore
1
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2

  
3
# dependencies
4
/node_modules
5
/.pnp
6
.pnp.js
7

  
8
# testing
9
/coverage
10

  
11
# production
12
/build
13

  
14
# misc
15
.DS_Store
16
.env.local
17
.env.development.local
18
.env.test.local
19
.env.production.local
20

  
21
npm-debug.log*
22
yarn-debug.log*
23
yarn-error.log*
map_frameworks/README.md
1
# Getting Started with Create React App
2

  
3
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4

  
5
## Available Scripts
6

  
7
In the project directory, you can run:
8

  
9
### `yarn start`
10

  
11
Runs the app in the development mode.\
12
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13

  
14
The page will reload if you make edits.\
15
You will also see any lint errors in the console.
16

  
17
### `yarn test`
18

  
19
Launches the test runner in the interactive watch mode.\
20
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21

  
22
### `yarn build`
23

  
24
Builds the app for production to the `build` folder.\
25
It correctly bundles React in production mode and optimizes the build for the best performance.
26

  
27
The build is minified and the filenames include the hashes.\
28
Your app is ready to be deployed!
29

  
30
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31

  
32
### `yarn eject`
33

  
34
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35

  
36
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37

  
38
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39

  
40
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41

  
42
## Learn More
43

  
44
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45

  
46
To learn React, check out the [React documentation](https://reactjs.org/).
map_frameworks/package.json
1
{
2
  "name": "map_frameworks",
3
  "version": "0.1.0",
4
  "private": true,
5
  "dependencies": {
6
    "@testing-library/jest-dom": "^5.14.1",
7
    "@testing-library/react": "^12.0.0",
8
    "@testing-library/user-event": "^13.2.1",
9
    "@types/": "urbica/react-map-gl",
10
    "@types/dotenv": "^8.2.0",
11
    "@types/jest": "^27.0.1",
12
    "@types/leaflet": "^1.7.9",
13
    "@types/mapbox-gl": "^2.6.2",
14
    "@types/node": "^16.7.13",
15
    "@types/react": "^17.0.20",
16
    "@types/react-dom": "^17.0.9",
17
    "@types/react-leaflet": "^2.8.2",
18
    "@urbica/react-map-gl": "^1.14.4",
19
    "leaflet": "^1.7.1",
20
    "mapbox-gl": "^2.7.0",
21
    "pigeon-maps": "^0.20.0",
22
    "react": "^17.0.2",
23
    "react-dom": "^17.0.2",
24
    "react-leaflet": "^3.2.5",
25
    "react-router-dom": "^6.2.2",
26
    "react-scripts": "5.0.0",
27
    "typescript": "^4.4.2",
28
    "web-vitals": "^2.1.0"
29
  },
30
  "scripts": {
31
    "start": "react-scripts start",
32
    "build": "react-scripts build",
33
    "test": "react-scripts test",
34
    "eject": "react-scripts eject"
35
  },
36
  "eslintConfig": {
37
    "extends": [
38
      "react-app",
39
      "react-app/jest"
40
    ]
41
  },
42
  "browserslist": {
43
    "production": [
44
      ">0.2%",
45
      "not dead",
46
      "not op_mini all"
47
    ],
48
    "development": [
49
      "last 1 chrome version",
50
      "last 1 firefox version",
51
      "last 1 safari version"
52
    ]
53
  }
54
}
map_frameworks/public/index.html
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
    <meta charset="utf-8"/>
5
    <link href="https://api.mapbox.com/mapbox-gl-js/v2.7.0/mapbox-gl.css" rel="stylesheet">
6
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico"/>
7
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
8
    <meta name="theme-color" content="#000000"/>
9
    <meta
10
            name="description"
11
            content="Web site created using create-react-app"
12
    />
13
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png"/>
14
    <!--
15
      manifest.json provides metadata used when your web app is installed on a
16
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
17
    -->
18
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json"/>
19
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
20
          integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
21
          crossorigin=""/>
22
    <!--
23
      Notice the use of %PUBLIC_URL% in the tags above.
24
      It will be replaced with the URL of the `public` folder during the build.
25
      Only files inside the `public` folder can be referenced from the HTML.
26

  
27
      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
28
      work correctly both with client-side routing and a non-root public URL.
29
      Learn how to configure a non-root public URL by running `npm run build`.
30
    -->
31
    <title>React App</title>
32
</head>
33
<body>
34
<noscript>You need to enable JavaScript to run this app.</noscript>
35
<div id="root"></div>
36
<!--
37
  This HTML file is a template.
38
  If you open it directly in the browser, you will see an empty page.
39

  
40
  You can add webfonts, meta tags, or analytics to this file.
41
  The build step will place the bundled scripts into the <body> tag.
42

  
43
  To begin the development, run `npm start` or `yarn start`.
44
  To create a production bundle, use `npm run build` or `yarn build`.
45
-->
46
</body>
47
</html>
map_frameworks/public/manifest.json
1
{
2
  "short_name": "React App",
3
  "name": "Create React App Sample",
4
  "icons": [
5
    {
6
      "src": "favicon.ico",
7
      "sizes": "64x64 32x32 24x24 16x16",
8
      "type": "image/x-icon"
9
    },
10
    {
11
      "src": "logo192.png",
12
      "type": "image/png",
13
      "sizes": "192x192"
14
    },
15
    {
16
      "src": "logo512.png",
17
      "type": "image/png",
18
      "sizes": "512x512"
19
    }
20
  ],
21
  "start_url": ".",
22
  "display": "standalone",
23
  "theme_color": "#000000",
24
  "background_color": "#ffffff"
25
}
map_frameworks/public/robots.txt
1
# https://www.robotstxt.org/robotstxt.html
2
User-agent: *
3
Disallow:
map_frameworks/src/App.css
1
.App {
2
  text-align: center;
3
}
4

  
5
.App-logo {
6
  height: 40vmin;
7
  pointer-events: none;
8
}
9

  
10
@media (prefers-reduced-motion: no-preference) {
11
  .App-logo {
12
    animation: App-logo-spin infinite 20s linear;
13
  }
14
}
15

  
16
.App-header {
17
  background-color: #282c34;
18
  min-height: 100vh;
19
  display: flex;
20
  flex-direction: column;
21
  align-items: center;
22
  justify-content: center;
23
  font-size: calc(10px + 2vmin);
24
  color: white;
25
}
26

  
27
.App-link {
28
  color: #61dafb;
29
}
30

  
31
@keyframes App-logo-spin {
32
  from {
33
    transform: rotate(0deg);
34
  }
35
  to {
36
    transform: rotate(360deg);
37
  }
38
}
map_frameworks/src/App.tsx
1
import React from 'react'
2
import './App.css'
3
import MapBoxExample from './component/MapBoxExample'
4
import PigeonMapsExample from './component/PigeonMapsExample'
5
import LeafletExample from './component/LeafletExample'
6

  
7
const App = () => (
8
    <div className="App">
9
        <MapBoxExample/>
10
        <PigeonMapsExample/>
11
        <LeafletExample />
12
    </div>
13
)
14

  
15
export default App
map_frameworks/src/component/LeafletExample.tsx
1
// Wrapper around leaflet -> https://react-leaflet.js.org/docs/start-setup/
2
import { MapContainer, Marker, Popup, SVGOverlay, TileLayer } from 'react-leaflet'
3
import MapBoxExample from './MapBoxExample'
4

  
5
const LeafletExample = () => {
6

  
7
    return (
8
        <>
9
            <h1>Leaflet Example</h1>
10
            <MapContainer style={ { height: 450 } } center={ [51.505, -0.09] } zoom={ 13 }>
11
                <TileLayer
12
                    attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
13
                    url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
14
                />
15
                <Marker position={ [51.505, -0.09] }>
16
                    <Popup>
17
                        <MapBoxExample />
18
                    </Popup>
19
                </Marker>
20
            </MapContainer>
21
        </>
22
    )
23
}
24

  
25
export default LeafletExample
map_frameworks/src/component/MapBoxExample.tsx
1
import React, { useEffect, useRef, useState } from 'react'
2
import mapboxgl, { LngLatLike, Popup } from 'mapbox-gl'
3

  
4

  
5
const coords = {
6
    lng: 7.3700,
7
    lat: 60.0400
8
}
9

  
10
// Adapted from
11
// https://docs.mapbox.com/help/tutorials/use-mapbox-gl-js-with-react/
12

  
13
// Potential wrapper could be: https://github.com/alex3165/react-mapbox-gl
14
// https://docs.mapbox.com/mapbox-gl-js/example/geojson-line/
15

  
16
// But has only 50k uses PER MONTH lol
17
const MapBoxExample = () => {
18

  
19
    const [lng, setLng] = useState(coords.lng)
20
    const [lat, setLat] = useState(coords.lat)
21
    const [zoom, setZoom] = useState(1)
22

  
23
    // TODO type
24
    const map = useRef<any>(null)
25
    const mapContainer = useRef<any>(null)
26

  
27
    // Function to add markers to the map
28
    const addMarkers = () => {
29
        for (let i = 1; i <= 10; i += 1) { //
30
            new mapboxgl.Marker()
31
                .setLngLat([i * .5 + coords.lng, i * .5 + coords.lat])
32
                .setPopup(new Popup().setHTML(`<h3>HELLO POPUP ${ i } ☀️🍕😂😅</h3>`))
33
                .addTo(map.current as mapboxgl.Map)
34
        }
35
    }
36

  
37
    useEffect(() => {
38
        if (map.current) {
39
            return
40
        }
41

  
42
        map.current = new mapboxgl.Map({
43
            container: mapContainer.current,
44
            center: [lng, lat],
45
            accessToken: process.env.REACT_APP_MAPS_API_KEY,
46
            style: 'mapbox://styles/mapbox/streets-v11',
47
            zoom: zoom
48
        })
49

  
50
        map.current.addControl(new mapboxgl.NavigationControl())
51

  
52
        addMarkers()
53
    })
54

  
55
    return (
56
        <>
57
            <h1>MapBox Example</h1>
58
            <div ref={ mapContainer } style={ { height: '400px' } }/>
59
        </>
60
    )
61
}
62

  
63
export default MapBoxExample
map_frameworks/src/component/PigeonMapsExample.tsx
1
import { Map, Marker } from 'pigeon-maps'
2
import { useState } from 'react'
3

  
4
// This would be also a great library but did not find any official way to draw path
5
const PigeonMapsExample = () => {
6
    return (
7
        <>
8
            <h1>PigeonMaps Example</h1>
9
            <Map height={ 400 } defaultCenter={ [50.879, 4.6997] } defaultZoom={ 11 }>
10
                <Marker width={ 50 } anchor={ [50.879, 4.6997] }/>
11
            </Map>
12
        </>
13
    )
14
}
15

  
16
export default PigeonMapsExample
map_frameworks/src/index.css
1
body {
2
  margin: 0;
3
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
    sans-serif;
6
  -webkit-font-smoothing: antialiased;
7
  -moz-osx-font-smoothing: grayscale;
8
}
9

  
10
code {
11
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
    monospace;
13
}
map_frameworks/src/index.tsx
1
import React from 'react'
2
import ReactDOM from 'react-dom'
3
import './index.css'
4
import App from './App'
5

  
6
ReactDOM.render(
7
    <React.StrictMode>
8
        <App/>
9
    </React.StrictMode>,
10
    document.getElementById('root')
11
)
12

  
map_frameworks/src/react-app-env.d.ts
1
/// <reference types="react-scripts" />
map_frameworks/src/setupTests.ts
1
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2
// allows you to do things like:
3
// expect(element).toHaveTextContent(/react/i)
4
// learn more: https://github.com/testing-library/jest-dom
5
import '@testing-library/jest-dom';
map_frameworks/tsconfig.json
1
{
2
  "compilerOptions": {
3
    "target": "es5",
4
    "lib": [
5
      "dom",
6
      "dom.iterable",
7
      "esnext"
8
    ],
9
    "allowJs": true,
10
    "skipLibCheck": true,
11
    "esModuleInterop": true,
12
    "allowSyntheticDefaultImports": true,
13
    "strict": true,
14
    "forceConsistentCasingInFileNames": true,
15
    "noFallthroughCasesInSwitch": true,
16
    "module": "esnext",
17
    "moduleResolution": "node",
18
    "resolveJsonModule": true,
19
    "isolatedModules": true,
20
    "noEmit": true,
21
    "jsx": "react-jsx"
22
  },
23
  "include": [
24
    "src"
25
  ]
26
}

Také k dispozici: Unified diff