Browse Source

swagger

master
esoe 2 weeks ago
parent
commit
bac8daaf6a
  1. 55
      main/api-swagger/positions.yml
  2. 13
      main/pom.xml
  3. 39
      main/src/main/java/gsp/technologies/main/api/position/PositionController.java
  4. 24
      main/src/main/java/gsp/technologies/main/api/position/PositionEntity.java
  5. 9
      main/src/main/java/gsp/technologies/main/api/position/PositionRepository.java
  6. 12
      main/src/main/java/gsp/technologies/main/api/position/PositionService.java
  7. 18
      main/src/main/java/gsp/technologies/main/hello/HelloController.java
  8. 8
      main/src/main/resources/application.yaml
  9. 1
      main/src/main/resources/static/hello/main.md
  10. 14
      main/src/main/resources/templates/hello.html

55
main/api-swagger/positions.yml

@ -0,0 +1,55 @@
openapi: '3.0.3'
info:
title: exam-api
description: API for exam
termsOfService: 'http://localhost:100/hello'
version: '1.0'
servers:
- url: http://localhost:100
paths:
/hello:
get:
responses:
'200':
description: OK
/api/v1/positions:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/position"
description: Get all positions
post:
description: Создание новой должности
requestBody:
content:
application/json:
schema:
type: object
required:
- name
properties:
name:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/position"
components:
schemas:
position:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string

13
main/pom.xml

@ -40,6 +40,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@ -50,6 +51,18 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

39
main/src/main/java/gsp/technologies/main/api/position/PositionController.java

@ -0,0 +1,39 @@
package gsp.technologies.main.api.position;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
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;
@RestController
@RequestMapping(path = "/api/v1/positions")
public class PositionController {
private static final Logger log = LoggerFactory.getLogger(PositionController.class);
@Autowired
private PositionRepository positionRepo;
@CrossOrigin
@GetMapping("")
public ResponseEntity<?> getPositions() {
log.info("GET /positions");
return new ResponseEntity<>(positionRepo.findAll(), HttpStatus.OK);
}
@CrossOrigin
@PostMapping(path = "",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> savePost(@RequestBody PositionEntity position) {
log.info("POST /position, position: {}", position);
positionRepo.save(position);
return new ResponseEntity<>(position, HttpStatus.CREATED);
}
}

24
main/src/main/java/gsp/technologies/main/api/position/PositionEntity.java

@ -0,0 +1,24 @@
package gsp.technologies.main.api.position;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
public class PositionEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name; //наименование должности работника
}

9
main/src/main/java/gsp/technologies/main/api/position/PositionRepository.java

@ -0,0 +1,9 @@
package gsp.technologies.main.api.position;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PositionRepository extends JpaRepository<PositionEntity, Long> {
}

12
main/src/main/java/gsp/technologies/main/api/position/PositionService.java

@ -0,0 +1,12 @@
package gsp.technologies.main.api.position;
import org.springframework.stereotype.Service;
@Service
public class PositionService {
private final PositionRepository repo;
public PositionService(PositionRepository repo) {
this.repo = repo;
}
}

18
main/src/main/java/gsp/technologies/main/hello/HelloController.java

@ -0,0 +1,18 @@
package gsp.technologies.main.hello;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
private static final Logger console = LoggerFactory.getLogger(HelloController.class);
@CrossOrigin
@GetMapping("/hello")
public String hello(){
return "hello";
}
}

8
main/src/main/resources/application.yaml

@ -1,6 +1,14 @@
spring: spring:
application: application:
name: main name: main
jpa:
hibernate:
ddl-auto: update
# database-platform: org.hibernate.dialect.PostgreSQLDialect
datasource:
url: "jdbc:postgresql://localhost:5430/exam"
username: exam
password: exam
server: server:
port: 100 port: 100

1
main/src/main/resources/static/hello/main.md

@ -0,0 +1 @@
# hello

14
main/src/main/resources/templates/hello.html

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>exam-hello</title>
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script>
</head>
<body>
<zero-md th:src="@{/hello/main.md}"></zero-md>
</body>
</html>
Loading…
Cancel
Save