esoe
2 weeks ago
10 changed files with 193 additions and 0 deletions
@ -0,0 +1,55 @@
@@ -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 |
@ -0,0 +1,39 @@
@@ -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); |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -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; //наименование должности работника
|
||||
|
||||
} |
@ -0,0 +1,9 @@
@@ -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> { |
||||
|
||||
} |
@ -0,0 +1,12 @@
@@ -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; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -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"; |
||||
} |
||||
} |
@ -1,6 +1,14 @@
@@ -1,6 +1,14 @@
|
||||
spring: |
||||
application: |
||||
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: |
||||
port: 100 |
||||
|
||||
|
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
# hello |
@ -0,0 +1,14 @@
@@ -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…
Reference in new issue