diff --git a/main/api-swagger/positions.yml b/main/api-swagger/positions.yml new file mode 100644 index 0000000..56f661d --- /dev/null +++ b/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 diff --git a/main/pom.xml b/main/pom.xml index 04b7338..55037da 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -40,6 +40,7 @@ org.springframework.boot spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-starter-web @@ -50,6 +51,18 @@ lombok true + + + org.postgresql + postgresql + runtime + + + + org.springframework.boot + spring-boot-starter-data-jpa + + org.springframework.boot spring-boot-starter-test diff --git a/main/src/main/java/gsp/technologies/main/api/position/PositionController.java b/main/src/main/java/gsp/technologies/main/api/position/PositionController.java new file mode 100644 index 0000000..0b51600 --- /dev/null +++ b/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); + } +} diff --git a/main/src/main/java/gsp/technologies/main/api/position/PositionEntity.java b/main/src/main/java/gsp/technologies/main/api/position/PositionEntity.java new file mode 100644 index 0000000..da8d568 --- /dev/null +++ b/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; //наименование должности работника + +} diff --git a/main/src/main/java/gsp/technologies/main/api/position/PositionRepository.java b/main/src/main/java/gsp/technologies/main/api/position/PositionRepository.java new file mode 100644 index 0000000..ee019f7 --- /dev/null +++ b/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 { + +} diff --git a/main/src/main/java/gsp/technologies/main/api/position/PositionService.java b/main/src/main/java/gsp/technologies/main/api/position/PositionService.java new file mode 100644 index 0000000..8a31ccb --- /dev/null +++ b/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; + } +} diff --git a/main/src/main/java/gsp/technologies/main/hello/HelloController.java b/main/src/main/java/gsp/technologies/main/hello/HelloController.java new file mode 100644 index 0000000..26070f2 --- /dev/null +++ b/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"; + } +} \ No newline at end of file diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml index 7772aba..4b89cc8 100644 --- a/main/src/main/resources/application.yaml +++ b/main/src/main/resources/application.yaml @@ -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 diff --git a/main/src/main/resources/static/hello/main.md b/main/src/main/resources/static/hello/main.md new file mode 100644 index 0000000..3b43971 --- /dev/null +++ b/main/src/main/resources/static/hello/main.md @@ -0,0 +1 @@ +# hello \ No newline at end of file diff --git a/main/src/main/resources/templates/hello.html b/main/src/main/resources/templates/hello.html new file mode 100644 index 0000000..f0c8672 --- /dev/null +++ b/main/src/main/resources/templates/hello.html @@ -0,0 +1,14 @@ + + + + + + exam-hello + + + + + + + \ No newline at end of file