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
|
||||
public PersonDTO createPerson(@RequestBody PersonDTO person) {
|
||||
person.setId(null);
|
||||
// print person.parent1
|
||||
System.out.println(person.getParent1());
|
||||
if(person.getBirthTimestamp() == null) {
|
||||
person.setBirthTimestamp(java.time.LocalDateTime.now());
|
||||
}
|
||||
return personService.save(person);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Person updatePerson(@PathVariable Long id, @RequestBody Person personDetails) {
|
||||
Person person = peopleRepository.findById(id).orElse(null);
|
||||
public PersonDTO updatePerson(@PathVariable Long id, @RequestBody PersonDTO personDetails) {
|
||||
PersonDTO person = personService.findById(id).orElse(null);
|
||||
if (person != null) {
|
||||
person.setParent1(personDetails.getParent1());
|
||||
person.setParent2(personDetails.getParent2());
|
||||
person.setBirthTimestamp(personDetails.getBirthTimestamp());
|
||||
return peopleRepository.save(person);
|
||||
return personService.save(person);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -17,4 +17,28 @@ public class Activity {
|
||||
private Integer value;
|
||||
|
||||
// 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 java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "activity_log")
|
||||
public class ActivityLog {
|
||||
@ -18,11 +20,51 @@ public class ActivityLog {
|
||||
@JoinColumn(name = "humanId")
|
||||
private Person person;
|
||||
|
||||
@Column(name = "startTimestamp")
|
||||
@Column(name = "start_timestamp")
|
||||
private java.time.LocalDateTime startTimestamp;
|
||||
|
||||
@Column(name = "endTimestamp")
|
||||
@Column(name = "end_timestamp")
|
||||
private java.time.LocalDateTime endTimestamp;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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 java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "occupation_log")
|
||||
public class OccupationLog {
|
||||
@ -18,14 +20,62 @@ public class OccupationLog {
|
||||
@JoinColumn(name = "humanId")
|
||||
private Person person;
|
||||
|
||||
@Column(name = "startTimestamp")
|
||||
@Column(name = "start_timestamp")
|
||||
private java.time.LocalDateTime startTimestamp;
|
||||
|
||||
@Column(name = "endTimestamp")
|
||||
@Column(name = "end_timestamp")
|
||||
private java.time.LocalDateTime endTimestamp;
|
||||
|
||||
@Column(name = "grade")
|
||||
private Integer grade;
|
||||
|
||||
// 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;
|
||||
|
||||
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.Service;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user