diff --git a/pom.xml b/pom.xml
index 54b8948..5574c11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,11 +25,6 @@
org.springframework.boot
spring-boot-starter-web
-
- org.springframework.boot
- spring-boot-starter-tomcat
- test
-
org.springframework.boot
spring-boot-starter-test
@@ -41,14 +36,9 @@
runtime
- io.springfox
- springfox-boot-starter
- 3.0.0
-
-
- io.springfox
- springfox-swagger-ui
- 3.0.0
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.0.2
diff --git a/src/main/java/com/example/prapro2spring/config/SwaggerConfig.java b/src/main/java/com/example/prapro2spring/config/SwaggerConfig.java
deleted file mode 100644
index 21dcab6..0000000
--- a/src/main/java/com/example/prapro2spring/config/SwaggerConfig.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.example.prapro2spring.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-@Configuration
-@EnableSwagger2
-public class SwaggerConfig {
- @Bean
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.example.prapro2spring.controller"))
- .paths(PathSelectors.any())
- .build();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/example/prapro2spring/controller/PersonController.java b/src/main/java/com/example/prapro2spring/controller/PersonController.java
index 07f702f..99099b8 100644
--- a/src/main/java/com/example/prapro2spring/controller/PersonController.java
+++ b/src/main/java/com/example/prapro2spring/controller/PersonController.java
@@ -1,7 +1,9 @@
package com.example.prapro2spring.controller;
import com.example.prapro2spring.model.Person;
+import com.example.prapro2spring.dto.PersonDTO;
import com.example.prapro2spring.service.PersonService;
+import com.example.prapro2spring.repository.PeopleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -11,38 +13,44 @@ import java.util.List;
@RequestMapping("/api/persons")
public class PersonController {
+ @Autowired
+ private PeopleRepository peopleRepository;
@Autowired
private PersonService personService;
+
@GetMapping
public List getAllPersons() {
- return personService.findAll();
+ return peopleRepository.findAll();
}
@GetMapping("/{id}")
public Person getPersonById(@PathVariable Long id) {
- return personService.findById(id).orElse(null);
+ return peopleRepository.findById(id).orElse(null);
}
@PostMapping
- public Person createPerson(@RequestBody Person person) {
+ public PersonDTO createPerson(@RequestBody PersonDTO person) {
+ person.setId(null);
+// print person.parent1
+ System.out.println(person.getParent1());
return personService.save(person);
}
@PutMapping("/{id}")
public Person updatePerson(@PathVariable Long id, @RequestBody Person personDetails) {
- Person person = personService.findById(id).orElse(null);
+ Person person = peopleRepository.findById(id).orElse(null);
if (person != null) {
person.setParent1(personDetails.getParent1());
person.setParent2(personDetails.getParent2());
person.setBirthTimestamp(personDetails.getBirthTimestamp());
- return personService.save(person);
+ return peopleRepository.save(person);
}
return null;
}
@DeleteMapping("/{id}")
public void deletePerson(@PathVariable Long id) {
- personService.deleteById(id);
+ peopleRepository.deleteById(id);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/example/prapro2spring/dto/PersonDTO.java b/src/main/java/com/example/prapro2spring/dto/PersonDTO.java
new file mode 100644
index 0000000..cd11990
--- /dev/null
+++ b/src/main/java/com/example/prapro2spring/dto/PersonDTO.java
@@ -0,0 +1,57 @@
+package com.example.prapro2spring.dto;
+
+import jakarta.persistence.*;
+
+import java.time.LocalDateTime;
+
+@Entity
+@Table(name = "people")
+public class PersonDTO {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(name = "parent1Id")
+ private Long parent1;
+
+ @Column(name = "parent2Id")
+ private Long parent2;
+
+ @Column(name = "birth_timestamp")
+ private java.time.LocalDateTime birthTimestamp;
+
+ // getters and setters
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getParent1() {
+ return parent1;
+ }
+
+ public void setParent1(Long parent1) {
+ this.parent1 = parent1;
+ }
+
+ public Long getParent2() {
+ return parent2;
+ }
+
+ public void setParent2(Long parent2) {
+ this.parent2 = parent2;
+ }
+
+ public LocalDateTime getBirthTimestamp() {
+ return birthTimestamp;
+ }
+
+ public void setBirthTimestamp(LocalDateTime birthTimestamp) {
+ this.birthTimestamp = birthTimestamp;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/prapro2spring/model/Person.java b/src/main/java/com/example/prapro2spring/model/Person.java
index 2ce5c29..de6c6f5 100644
--- a/src/main/java/com/example/prapro2spring/model/Person.java
+++ b/src/main/java/com/example/prapro2spring/model/Person.java
@@ -20,7 +20,7 @@ public class Person {
@JoinColumn(name = "parent2Id")
private Person parent2;
- @Column(name = "birthTimestamp")
+ @Column(name = "birth_timestamp")
private java.time.LocalDateTime birthTimestamp;
// getters and setters
diff --git a/src/main/java/com/example/prapro2spring/service/PersonService.java b/src/main/java/com/example/prapro2spring/service/PersonService.java
index 6dd0c3b..124347a 100644
--- a/src/main/java/com/example/prapro2spring/service/PersonService.java
+++ b/src/main/java/com/example/prapro2spring/service/PersonService.java
@@ -1,9 +1,12 @@
package com.example.prapro2spring.service;
+import com.example.prapro2spring.dto.PersonDTO;
import com.example.prapro2spring.model.Person;
+import com.example.prapro2spring.repository.PeopleRepository;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
+import org.springframework.stereotype.Service;
-@Repository
-public interface PersonService extends JpaRepository {
+@Service
+public interface PersonService extends JpaRepository {
}
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index dfb3efc..4d147ac 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -2,6 +2,7 @@ spring.datasource.url=jdbc:postgresql://db.twawwfuogpwjclumcsdl.supabase.co:5432
spring.datasource.username=postgres
spring.datasource.password=uyi3SpF2Hodw78UJ
spring.datasource.driver-class-name=org.postgresql.Driver
+spring.jpa.properties.hibernate.default_schema=people_scoreboard
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
\ No newline at end of file