forked from s485936/PRAPRO2
feat: added getters and setters for all models, and whole stack for activity
This commit is contained in:
parent
2cf9d05cec
commit
72a5d8c593
@ -0,0 +1,62 @@
|
|||||||
|
package com.example.prapro2spring.controller;
|
||||||
|
|
||||||
|
import com.example.prapro2spring.model.Activity;
|
||||||
|
import com.example.prapro2spring.service.ActivityService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/activities")
|
||||||
|
public class ActivityController {
|
||||||
|
|
||||||
|
private final ActivityService activityService;
|
||||||
|
|
||||||
|
public ActivityController(ActivityService activityService) {
|
||||||
|
this.activityService = activityService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Activity createActivity(@RequestBody Activity activity) {
|
||||||
|
return activityService.save(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<Activity> getAllActivities() {
|
||||||
|
return activityService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<Activity> getActivityById(@PathVariable Long id) {
|
||||||
|
Activity activity = activityService.findById(id).orElse(null);
|
||||||
|
if (activity != null) {
|
||||||
|
return ResponseEntity.ok(activity);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<Activity> updateActivity(@PathVariable Long id, @RequestBody Activity activityDetails) {
|
||||||
|
Activity activity = activityService.findById(id).orElse(null);
|
||||||
|
if (activity != null) {
|
||||||
|
activity.setName(activityDetails.getName());
|
||||||
|
activity.setValue(activityDetails.getValue());
|
||||||
|
return ResponseEntity.ok(activityService.save(activity));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Void> deleteActivity(@PathVariable Long id) {
|
||||||
|
Activity activity = activityService.findById(id).orElse(null);
|
||||||
|
if (activity != null) {
|
||||||
|
activityService.delete(activity);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,19 +32,20 @@ public class PersonController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public PersonDTO createPerson(@RequestBody PersonDTO person) {
|
public PersonDTO createPerson(@RequestBody PersonDTO person) {
|
||||||
person.setId(null);
|
person.setId(null);
|
||||||
// print person.parent1
|
if(person.getBirthTimestamp() == null) {
|
||||||
System.out.println(person.getParent1());
|
person.setBirthTimestamp(java.time.LocalDateTime.now());
|
||||||
|
}
|
||||||
return personService.save(person);
|
return personService.save(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public Person updatePerson(@PathVariable Long id, @RequestBody Person personDetails) {
|
public PersonDTO updatePerson(@PathVariable Long id, @RequestBody PersonDTO personDetails) {
|
||||||
Person person = peopleRepository.findById(id).orElse(null);
|
PersonDTO person = personService.findById(id).orElse(null);
|
||||||
if (person != null) {
|
if (person != null) {
|
||||||
person.setParent1(personDetails.getParent1());
|
person.setParent1(personDetails.getParent1());
|
||||||
person.setParent2(personDetails.getParent2());
|
person.setParent2(personDetails.getParent2());
|
||||||
person.setBirthTimestamp(personDetails.getBirthTimestamp());
|
person.setBirthTimestamp(personDetails.getBirthTimestamp());
|
||||||
return peopleRepository.save(person);
|
return personService.save(person);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,28 @@ public class Activity {
|
|||||||
private Integer value;
|
private Integer value;
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.example.prapro2spring.model;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "activity_log")
|
@Table(name = "activity_log")
|
||||||
public class ActivityLog {
|
public class ActivityLog {
|
||||||
@ -18,11 +20,51 @@ public class ActivityLog {
|
|||||||
@JoinColumn(name = "humanId")
|
@JoinColumn(name = "humanId")
|
||||||
private Person person;
|
private Person person;
|
||||||
|
|
||||||
@Column(name = "startTimestamp")
|
@Column(name = "start_timestamp")
|
||||||
private java.time.LocalDateTime startTimestamp;
|
private java.time.LocalDateTime startTimestamp;
|
||||||
|
|
||||||
@Column(name = "endTimestamp")
|
@Column(name = "end_timestamp")
|
||||||
private java.time.LocalDateTime endTimestamp;
|
private java.time.LocalDateTime endTimestamp;
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Activity getActivity() {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivity(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person getPerson() {
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerson(Person person) {
|
||||||
|
this.person = person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTimestamp() {
|
||||||
|
return startTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTimestamp(LocalDateTime startTimestamp) {
|
||||||
|
this.startTimestamp = startTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTimestamp() {
|
||||||
|
return endTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTimestamp(LocalDateTime endTimestamp) {
|
||||||
|
this.endTimestamp = endTimestamp;
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,4 +17,28 @@ public class Occupation {
|
|||||||
private Integer value;
|
private Integer value;
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.example.prapro2spring.model;
|
|||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "occupation_log")
|
@Table(name = "occupation_log")
|
||||||
public class OccupationLog {
|
public class OccupationLog {
|
||||||
@ -18,14 +20,62 @@ public class OccupationLog {
|
|||||||
@JoinColumn(name = "humanId")
|
@JoinColumn(name = "humanId")
|
||||||
private Person person;
|
private Person person;
|
||||||
|
|
||||||
@Column(name = "startTimestamp")
|
@Column(name = "start_timestamp")
|
||||||
private java.time.LocalDateTime startTimestamp;
|
private java.time.LocalDateTime startTimestamp;
|
||||||
|
|
||||||
@Column(name = "endTimestamp")
|
@Column(name = "end_timestamp")
|
||||||
private java.time.LocalDateTime endTimestamp;
|
private java.time.LocalDateTime endTimestamp;
|
||||||
|
|
||||||
@Column(name = "grade")
|
@Column(name = "grade")
|
||||||
private Integer grade;
|
private Integer grade;
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Occupation getOccupation() {
|
||||||
|
return occupation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOccupation(Occupation occupation) {
|
||||||
|
this.occupation = occupation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person getPerson() {
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerson(Person person) {
|
||||||
|
this.person = person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTimestamp() {
|
||||||
|
return startTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTimestamp(LocalDateTime startTimestamp) {
|
||||||
|
this.startTimestamp = startTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTimestamp() {
|
||||||
|
return endTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTimestamp(LocalDateTime endTimestamp) {
|
||||||
|
this.endTimestamp = endTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getGrade() {
|
||||||
|
return grade;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrade(Integer grade) {
|
||||||
|
this.grade = grade;
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
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> {
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.example.prapro2spring.service;
|
||||||
|
|
||||||
|
import com.example.prapro2spring.model.Activity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface ActivityService extends JpaRepository<Activity, Long> {
|
||||||
|
}
|
@ -1,9 +1,6 @@
|
|||||||
package com.example.prapro2spring.service;
|
package com.example.prapro2spring.service;
|
||||||
|
|
||||||
import com.example.prapro2spring.dto.PersonDTO;
|
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.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user