Compare commits

...

2 Commits

Author SHA1 Message Date
Marcin Alchimowicz c01e29d6d2 feat: added paginated request 2024-01-17 23:11:39 +01:00
Marcin Alchimowicz 4f630016ca NO MORE LONGS THAT ARE CHANGING THE SCHEMA OF MY DATABASE also added main controller for special requests 2024-01-17 22:30:21 +01:00
28 changed files with 257 additions and 66 deletions

View File

@ -28,7 +28,7 @@ public class ActivityController {
}
@GetMapping("/{id}")
public ResponseEntity<Activity> getActivityById(@PathVariable Long id) {
public ResponseEntity<Activity> getActivityById(@PathVariable Integer id) {
Activity activity = activityService.findById(id).orElse(null);
if (activity != null) {
return ResponseEntity.ok(activity);
@ -38,7 +38,7 @@ public class ActivityController {
}
@PutMapping("/{id}")
public ResponseEntity<Activity> updateActivity(@PathVariable Long id, @RequestBody Activity activityDetails) {
public ResponseEntity<Activity> updateActivity(@PathVariable Integer id, @RequestBody Activity activityDetails) {
Activity activity = activityService.findById(id).orElse(null);
if (activity != null) {
activity.setName(activityDetails.getName());
@ -50,7 +50,7 @@ public class ActivityController {
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteActivity(@PathVariable Long id) {
public ResponseEntity<Void> deleteActivity(@PathVariable Integer id) {
Activity activity = activityService.findById(id).orElse(null);
if (activity != null) {
activityService.delete(activity);

View File

@ -24,7 +24,7 @@ public class ActivityLogController {
}
@GetMapping("/{id}")
public ActivityLog getActivityLogById(@PathVariable Long id) {
public ActivityLog getActivityLogById(@PathVariable Integer id) {
return activityLogService.findById(id).orElse(null);
}
@ -35,7 +35,7 @@ public class ActivityLogController {
}
@PutMapping("/{id}")
public ActivityLogDTO updateActivityLog(@PathVariable Long id, @RequestBody ActivityLogDTO activityLogDetails) {
public ActivityLogDTO updateActivityLog(@PathVariable Integer id, @RequestBody ActivityLogDTO activityLogDetails) {
ActivityLogDTO activityLog = activityLogDTOService.findById(id).orElse(null);
if (activityLog != null) {
activityLog.setActivityId(activityLogDetails.getActivityId());
@ -48,7 +48,7 @@ public class ActivityLogController {
}
@DeleteMapping("/{id}")
public void deleteActivityLog(@PathVariable Long id) {
public void deleteActivityLog(@PathVariable Integer id) {
activityLogService.deleteById(id);
}
}

View File

@ -0,0 +1,28 @@
package com.example.prapro2spring.controller;
import com.example.prapro2spring.dto.AllPeopleValues;
import com.example.prapro2spring.repository.PeopleRepository;
import com.example.prapro2spring.service.PersonValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/main")
public class MainController {
@Autowired
private PeopleRepository peopleRepository;
@Autowired
private PersonValueService PersonValueService;
@GetMapping("/")
public AllPeopleValues getAllPeopleValues(@RequestParam(value = "startIndex", defaultValue = "0") Integer startIndex) {
return PersonValueService.getAllPersonValues(startIndex);
}
@GetMapping("/{id}")
public Integer getPersonValuesById(@PathVariable Integer id){
return PersonValueService.getPersonValuesById(id);
}
}

View File

@ -28,7 +28,7 @@ public class OccupationController {
}
@GetMapping("/{id}")
public ResponseEntity<Occupation> getOccupationById(@PathVariable Long id) {
public ResponseEntity<Occupation> getOccupationById(@PathVariable Integer id) {
Occupation occupation = occupationService.findById(id).orElse(null);
if (occupation != null) {
return ResponseEntity.ok(occupation);
@ -38,7 +38,7 @@ public class OccupationController {
}
@PutMapping("/{id}")
public ResponseEntity<Occupation> updateOccupation(@PathVariable Long id, @RequestBody Occupation occupationDetails) {
public ResponseEntity<Occupation> updateOccupation(@PathVariable Integer id, @RequestBody Occupation occupationDetails) {
Occupation occupation = occupationService.findById(id).orElse(null);
if (occupation != null) {
occupation.setName(occupationDetails.getName());
@ -50,7 +50,7 @@ public class OccupationController {
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteOccupation(@PathVariable Long id) {
public ResponseEntity<Void> deleteOccupation(@PathVariable Integer id) {
Occupation occupation = occupationService.findById(id).orElse(null);
if (occupation != null) {
occupationService.delete(occupation);

View File

@ -24,7 +24,7 @@ public class OccupationLogController {
}
@GetMapping("/{id}")
public OccupationLog getOccupationLogById(@PathVariable Long id) {
public OccupationLog getOccupationLogById(@PathVariable Integer id) {
return occupationLogService.findById(id).orElse(null);
}
@ -35,7 +35,7 @@ public class OccupationLogController {
}
@PutMapping("/{id}")
public OccupationLogDTO updateOccupationLog(@PathVariable Long id, @RequestBody OccupationLogDTO occupationLogDetails) {
public OccupationLogDTO updateOccupationLog(@PathVariable Integer id, @RequestBody OccupationLogDTO occupationLogDetails) {
OccupationLogDTO occupationLog = occupationLogDTOService.findById(id).orElse(null);
if (occupationLog != null) {
occupationLog.setOccupationId(occupationLogDetails.getOccupationId());
@ -49,7 +49,7 @@ public class OccupationLogController {
}
@DeleteMapping("/{id}")
public void deleteOccupationLog(@PathVariable Long id) {
public void deleteOccupationLog(@PathVariable Integer id) {
occupationLogService.deleteById(id);
}
}

View File

@ -25,7 +25,7 @@ public class PersonController {
}
@GetMapping("/{id}")
public Person getPersonById(@PathVariable Long id) {
public Person getPersonById(@PathVariable Integer id) {
return peopleRepository.findById(id).orElse(null);
}
@ -39,7 +39,7 @@ public class PersonController {
}
@PutMapping("/{id}")
public PersonDTO updatePerson(@PathVariable Long id, @RequestBody PersonDTO personDetails) {
public PersonDTO updatePerson(@PathVariable Integer id, @RequestBody PersonDTO personDetails) {
PersonDTO person = personService.findById(id).orElse(null);
if (person != null) {
person.setParent1(personDetails.getParent1());
@ -51,7 +51,7 @@ public class PersonController {
}
@DeleteMapping("/{id}")
public void deletePerson(@PathVariable Long id) {
public void deletePerson(@PathVariable Integer id) {
peopleRepository.deleteById(id);
}
}

View File

@ -12,13 +12,13 @@ public class ActivityLogDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@Column(name = "activityId")
private Long activityId;
private Integer activityId;
@Column(name = "humanId")
private Long personId;
private Integer personId;
@Column(name = "start_timestamp")
private LocalDateTime startTimestamp;
@ -28,27 +28,27 @@ public class ActivityLogDTO {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}
public Long getActivityId() {
public Integer getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
public void setActivityId(Integer activityId) {
this.activityId = activityId;
}
public Long getPersonId() {
public Integer getPersonId() {
return personId;
}
public void setPersonId(Long person) {
public void setPersonId(Integer person) {
this.personId = person;
}

View File

@ -0,0 +1,24 @@
package com.example.prapro2spring.dto;
import java.util.List;
public class AllPeopleValues {
private List<PersonValue> peopleValues;
private Integer lastIndex;
public AllPeopleValues(List<PersonValue> peopleValues, Integer lastIndex) {
this.peopleValues = peopleValues;
this.lastIndex = lastIndex;
}
public AllPeopleValues() {
}
public List<PersonValue> getPeopleValues() {
return peopleValues;
}
public Integer getLastIndex() {
return lastIndex;
}
}

View File

@ -12,13 +12,13 @@ public class OccupationLogDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@Column(name = "occupationId")
private Long occupationId;
private Integer occupationId;
@Column(name = "humanId")
private Long personId;
private Integer personId;
@Column(name = "start_timestamp")
private LocalDateTime startTimestamp;
@ -31,27 +31,27 @@ public class OccupationLogDTO {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}
public Long getOccupationId() {
public Integer getOccupationId() {
return occupationId;
}
public void setOccupationId(Long occupationId) {
public void setOccupationId(Integer occupationId) {
this.occupationId = occupationId;
}
public Long getPersonId() {
public Integer getPersonId() {
return personId;
}
public void setPersonId(Long personId) {
public void setPersonId(Integer personId) {
this.personId = personId;
}

View File

@ -10,40 +10,40 @@ public class PersonDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@Column(name = "parent1Id")
private Long parent1;
private Integer parent1;
@Column(name = "parent2Id")
private Long parent2;
private Integer parent2;
@Column(name = "birth_timestamp")
private java.time.LocalDateTime birthTimestamp;
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}
public Long getParent1() {
public Integer getParent1() {
return parent1;
}
public void setParent1(Long parent1) {
public void setParent1(Integer parent1) {
this.parent1 = parent1;
}
public Long getParent2() {
public Integer getParent2() {
return parent2;
}
public void setParent2(Long parent2) {
public void setParent2(Integer parent2) {
this.parent2 = parent2;
}

View File

@ -0,0 +1,22 @@
package com.example.prapro2spring.dto;
public class PersonValue {
private Integer id;
private Integer value;
public PersonValue(Integer id, Integer value) {
this.id = id;
this.value = value;
}
public PersonValue() {
}
public Integer getId() {
return id;
}
public Integer getValue() {
return value;
}
}

View File

@ -8,7 +8,7 @@ public class Activity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@Column(name = "name")
private String name;
@ -18,11 +18,11 @@ public class Activity {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -10,7 +10,7 @@ public class ActivityLog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@ManyToOne
@JoinColumn(name = "activityId")
@ -28,11 +28,11 @@ public class ActivityLog {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -0,0 +1,69 @@
package com.example.prapro2spring.model;
import java.time.LocalDateTime;
public class FullPerson {
private Integer id;
private Person parent1;
private Person parent2;
private java.time.LocalDateTime birthTimestamp;
private ActivityLog[] activityLog;
private OccupationLog[] occupationLog;
public FullPerson(Integer id, Person parent1, Person parent2, java.time.LocalDateTime birthTimestamp, ActivityLog[] activityLog, OccupationLog[] occupationLog) {
this.id = id;
this.parent1 = parent1;
this.parent2 = parent2;
this.birthTimestamp = birthTimestamp;
this.activityLog = activityLog;
this.occupationLog = occupationLog;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Person getParent1() {
return parent1;
}
public void setParent1(Person parent1) {
this.parent1 = parent1;
}
public Person getParent2() {
return parent2;
}
public void setParent2(Person parent2) {
this.parent2 = parent2;
}
public LocalDateTime getBirthTimestamp() {
return birthTimestamp;
}
public void setBirthTimestamp(LocalDateTime birthTimestamp) {
this.birthTimestamp = birthTimestamp;
}
public ActivityLog[] getActivityLog() {
return activityLog;
}
public void setActivityLog(ActivityLog[] activityLog) {
this.activityLog = activityLog;
}
public OccupationLog[] getOccupationLog() {
return occupationLog;
}
public void setOccupationLog(OccupationLog[] occupationLog) {
this.occupationLog = occupationLog;
}
}

View File

@ -8,7 +8,7 @@ public class Occupation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@Column(name = "name")
private String name;
@ -18,11 +18,11 @@ public class Occupation {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -10,7 +10,7 @@ public class OccupationLog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@ManyToOne
@JoinColumn(name = "occupationId")
@ -31,11 +31,11 @@ public class OccupationLog {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -10,7 +10,7 @@ public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;
@ManyToOne
@JoinColumn(name = "parent1Id")
@ -25,11 +25,11 @@ public class Person {
// getters and setters
public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}

View File

@ -3,5 +3,5 @@ package com.example.prapro2spring.repository;
import com.example.prapro2spring.model.Activity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ActivityRepository extends JpaRepository<Activity, Long> {
public interface ActivityRepository extends JpaRepository<Activity, Integer> {
}

View File

@ -3,5 +3,5 @@ package com.example.prapro2spring.repository;
import com.example.prapro2spring.model.Person;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PeopleRepository extends JpaRepository<Person, Long> {
public interface PeopleRepository extends JpaRepository<Person, Integer> {
}

View File

@ -0,0 +1,16 @@
package com.example.prapro2spring.repository;
import com.example.prapro2spring.dto.PersonValue;
import com.example.prapro2spring.dto.PersonDTO;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface PersonValueRepository extends CrudRepository<PersonDTO, Integer> {
@Query(value = "SELECT people_scoreboard.get_human_value(?1)", nativeQuery = true)
Integer queryPersonValuesById(Integer id);
@Query(value = "SELECT * FROM people_scoreboard.get_all_people_values(?1, 3)", nativeQuery = true)
List<Object[]> queryAllPersonValues(Integer startIndex);
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface ActivityLogDTOService extends JpaRepository<ActivityLogDTO, Long> {
public interface ActivityLogDTOService extends JpaRepository<ActivityLogDTO, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface ActivityLogService extends JpaRepository<ActivityLog, Long> {
public interface ActivityLogService extends JpaRepository<ActivityLog, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface ActivityService extends JpaRepository<Activity, Long> {
public interface ActivityService extends JpaRepository<Activity, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface OccupationLogDTOService extends JpaRepository<OccupationLogDTO, Long> {
public interface OccupationLogDTOService extends JpaRepository<OccupationLogDTO, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface OccupationLogService extends JpaRepository<OccupationLog, Long> {
public interface OccupationLogService extends JpaRepository<OccupationLog, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface OccupationService extends JpaRepository<Occupation, Long> {
public interface OccupationService extends JpaRepository<Occupation, Integer> {
}

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface PersonService extends JpaRepository<PersonDTO, Long> {
public interface PersonService extends JpaRepository<PersonDTO, Integer> {
}

View File

@ -0,0 +1,32 @@
package com.example.prapro2spring.service;
import com.example.prapro2spring.dto.AllPeopleValues;
import com.example.prapro2spring.dto.PersonValue;
import com.example.prapro2spring.repository.PersonValueRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class PersonValueService {
@Autowired
PersonValueRepository personValueRepository;
public AllPeopleValues getAllPersonValues(Integer lastIndex) {
List<Object[]> results = personValueRepository.queryAllPersonValues(lastIndex);
List<PersonValue> personValues = new ArrayList<>();
for (Object[] result : results) {
PersonValue personValue = new PersonValue((Integer) result[0], (Integer) result[1]);
personValues.add(personValue);
}
return new AllPeopleValues(personValues, personValues.size());
}
public Integer getPersonValuesById(Integer id) {
return personValueRepository.queryPersonValuesById(id);
}
}