feat: added ActivityLog stack

This commit is contained in:
Marcin Alchimowicz 2024-01-17 20:16:29 +01:00
parent 1ec5555423
commit 9b5304ae3c
4 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,54 @@
package com.example.prapro2spring.controller;
import com.example.prapro2spring.dto.ActivityLogDTO;
import com.example.prapro2spring.model.ActivityLog;
import com.example.prapro2spring.service.ActivityLogService;
import com.example.prapro2spring.service.ActivityLogDTOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/activityLogs")
public class ActivityLogController {
@Autowired
private ActivityLogService activityLogService;
@Autowired
private ActivityLogDTOService activityLogDTOService;
@GetMapping
public List<ActivityLog> getAllActivityLogs() {
return activityLogService.findAll();
}
@GetMapping("/{id}")
public ActivityLog getActivityLogById(@PathVariable Long id) {
return activityLogService.findById(id).orElse(null);
}
@PostMapping
public ActivityLogDTO createActivityLog(@RequestBody ActivityLogDTO activityLog) {
activityLog.setId(null);
return activityLogDTOService.save(activityLog);
}
@PutMapping("/{id}")
public ActivityLogDTO updateActivityLog(@PathVariable Long id, @RequestBody ActivityLogDTO activityLogDetails) {
ActivityLogDTO activityLog = activityLogDTOService.findById(id).orElse(null);
if (activityLog != null) {
activityLog.setActivityId(activityLogDetails.getActivityId());
activityLog.setPersonId(activityLogDetails.getPersonId());
activityLog.setStartTimestamp(activityLogDetails.getStartTimestamp());
activityLog.setEndTimestamp(activityLogDetails.getEndTimestamp());
return activityLogDTOService.save(activityLog);
}
return null;
}
@DeleteMapping("/{id}")
public void deleteActivityLog(@PathVariable Long id) {
activityLogService.deleteById(id);
}
}

View File

@ -0,0 +1,70 @@
package com.example.prapro2spring.dto;
import com.example.prapro2spring.model.Activity;
import com.example.prapro2spring.model.Person;
import jakarta.persistence.*;
import java.time.LocalDateTime;
@Entity
@Table(name = "activity_log")
public class ActivityLogDTO {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "activityId")
private Long activityId;
@Column(name = "humanId")
private Long personId;
@Column(name = "start_timestamp")
private LocalDateTime startTimestamp;
@Column(name = "end_timestamp")
private LocalDateTime endTimestamp;
// getters and setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
public Long getPersonId() {
return personId;
}
public void setPersonId(Long person) {
this.personId = 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;
}
}

View File

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

View File

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