feat: added occupationLog stack

This commit is contained in:
Marcin Alchimowicz 2024-01-17 20:20:44 +01:00
parent 9b5304ae3c
commit 570dc024b5
4 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,55 @@
package com.example.prapro2spring.controller;
import com.example.prapro2spring.dto.OccupationLogDTO;
import com.example.prapro2spring.model.OccupationLog;
import com.example.prapro2spring.service.OccupationLogDTOService;
import com.example.prapro2spring.service.OccupationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/occupationLogs")
public class OccupationLogController {
@Autowired
private OccupationLogService occupationLogService;
@Autowired
private OccupationLogDTOService occupationLogDTOService;
@GetMapping
public List<OccupationLog> getAllOccupationLogs() {
return occupationLogService.findAll();
}
@GetMapping("/{id}")
public OccupationLog getOccupationLogById(@PathVariable Long id) {
return occupationLogService.findById(id).orElse(null);
}
@PostMapping
public OccupationLogDTO createOccupationLog(@RequestBody OccupationLogDTO occupationLog) {
occupationLog.setId(null);
return occupationLogDTOService.save(occupationLog);
}
@PutMapping("/{id}")
public OccupationLogDTO updateOccupationLog(@PathVariable Long id, @RequestBody OccupationLogDTO occupationLogDetails) {
OccupationLogDTO occupationLog = occupationLogDTOService.findById(id).orElse(null);
if (occupationLog != null) {
occupationLog.setOccupationId(occupationLogDetails.getOccupationId());
occupationLog.setPersonId(occupationLogDetails.getPersonId());
occupationLog.setStartTimestamp(occupationLogDetails.getStartTimestamp());
occupationLog.setEndTimestamp(occupationLogDetails.getEndTimestamp());
occupationLog.setGrade(occupationLogDetails.getGrade());
return occupationLogDTOService.save(occupationLog);
}
return null;
}
@DeleteMapping("/{id}")
public void deleteOccupationLog(@PathVariable Long id) {
occupationLogService.deleteById(id);
}
}

View File

@ -0,0 +1,81 @@
package com.example.prapro2spring.dto;
import com.example.prapro2spring.model.Occupation;
import com.example.prapro2spring.model.Person;
import jakarta.persistence.*;
import java.time.LocalDateTime;
@Entity
@Table(name = "occupation_log")
public class OccupationLogDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "occupationId")
private Long occupationId;
@Column(name = "humanId")
private Long personId;
@Column(name = "start_timestamp")
private LocalDateTime startTimestamp;
@Column(name = "end_timestamp")
private 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 Long getOccupationId() {
return occupationId;
}
public void setOccupationId(Long occupationId) {
this.occupationId = occupationId;
}
public Long getPersonId() {
return personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
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;
}
}

View File

@ -0,0 +1,9 @@
package com.example.prapro2spring.service;
import com.example.prapro2spring.dto.OccupationLogDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface OccupationLogDTOService extends JpaRepository<OccupationLogDTO, Long> {
}

View File

@ -0,0 +1,9 @@
package com.example.prapro2spring.service;
import com.example.prapro2spring.model.OccupationLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Service
public interface OccupationLogService extends JpaRepository<OccupationLog, Long> {
}