Skip to content

Commit

Permalink
Datetime switched to LocalDateTime due to certain issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
FruTooTi committed Jan 1, 2024
1 parent 7f092e6 commit d26ba08
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.production.ehayvanbackendapi.DTO;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.Date;

public class AppointmentDTO {
private Integer appointmentID;
private Integer petOwnerID;
private Integer vetID;
private Integer petID;
private Date appointmentDate;
@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
@DateTimeFormat(pattern = "dd-MM-yyyy HH:mm")
private LocalDateTime appointmentDate;

public AppointmentDTO(){

}
public AppointmentDTO(Integer appointmentID, Integer petOwnerID, Integer vetID, Integer petID, Date appointmentDate) {
public AppointmentDTO(Integer appointmentID, Integer petOwnerID, Integer vetID, Integer petID, LocalDateTime appointmentDate) {
this.appointmentID = appointmentID;
this.petOwnerID = petOwnerID;
this.vetID = vetID;
Expand Down Expand Up @@ -52,11 +58,11 @@ public void setPetID(Integer petID) {
this.petID = petID;
}

public Date getAppointmentDate() {
public LocalDateTime getAppointmentDate() {
return appointmentDate;
}

public void setAppointmentDate(Date appointmentDate) {
public void setAppointmentDate(LocalDateTime appointmentDate) {
this.appointmentDate = appointmentDate;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.production.ehayvanbackendapi.DTO;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public class ScheduleDTO {
private Integer scheduleID;
private Date beginningDate;
private LocalDateTime beginningDate;
private Integer doseFrequency;
private Integer doseCount;
public ScheduleDTO(){

}
public ScheduleDTO(Integer scheduleID, List<MedicationDTO> medications,
Date beginningDate, Integer doseFrequency, Integer doseCount) {
LocalDateTime beginningDate, Integer doseFrequency, Integer doseCount) {
this.scheduleID = scheduleID;
this.beginningDate = beginningDate;
this.doseFrequency = doseFrequency;
Expand All @@ -27,11 +28,11 @@ public void setScheduleID(Integer scheduleID) {
this.scheduleID = scheduleID;
}

public Date getBeginningDate() {
public LocalDateTime getBeginningDate() {
return beginningDate;
}

public void setBeginningDate(Date beginningDate) {
public void setBeginningDate(LocalDateTime beginningDate) {
this.beginningDate = beginningDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.Date;

public class CreateOrUpdateAppointmentDTO {
@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
@DateTimeFormat(pattern = "dd-MM-yyyy HH:mm")
private Date appointmentDate;
private LocalDateTime appointmentDate;
private Integer petID;
private Integer vetID;
private Integer petOwnerID;

public Date getAppointmentDate() {
public LocalDateTime getAppointmentDate() {
return appointmentDate;
}

public void setAppointmentDate(Date appointmentDate) {
public void setAppointmentDate(LocalDateTime appointmentDate) {
this.appointmentDate = appointmentDate;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.production.ehayvanbackendapi.DTO.request;

import org.springframework.cglib.core.Local;

import java.time.LocalDateTime;
import java.util.Date;

public class CreateOrUpdateScheduleDTO {
private Date beginningDate;

private LocalDateTime beginningDate;
private Integer doseFrequency;
private Integer doseCount;

public Date getBeginningDate() {
public LocalDateTime getBeginningDate() {
return beginningDate;
}

public void setBeginningDate(Date beginningDate) {
public void setBeginningDate(LocalDateTime beginningDate) {
this.beginningDate = beginningDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.Date;

@Entity
Expand All @@ -25,7 +26,7 @@ public class Appointment {
@Column(nullable = false)
@DateTimeFormat(pattern = "dd-MM-yyyy HH:mm")
@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
private Date AppointmentDate;
private LocalDateTime AppointmentDate;
public int getAppointmentID() {
return AppointmentID;
}
Expand All @@ -50,10 +51,10 @@ public Pet getPetID() {
public void setPetID(Pet petID) {
PetID = petID;
}
public Date getAppointmentDate() {
public LocalDateTime getAppointmentDate() {
return AppointmentDate;
}
public void setAppointmentDate(Date appointmentDate) {
public void setAppointmentDate(LocalDateTime appointmentDate) {
AppointmentDate = appointmentDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import jakarta.persistence.*;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.cglib.core.Local;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

Expand All @@ -16,7 +18,7 @@ public class Schedule {
@OneToMany(mappedBy = "ScheduleID", cascade = CascadeType.ALL)
private List<Medication> medications;
@Column(nullable = false)
private Date beginningDate;
private LocalDateTime beginningDate;
@Column(nullable = false)
private Integer doseFrequency;
@Column(nullable = false)
Expand All @@ -28,10 +30,10 @@ public Integer getScheduleID() {
public void setScheduleID(Integer scheduleID) {
ScheduleID = scheduleID;
}
public Date getBeginningDate() {
public LocalDateTime getBeginningDate() {
return beginningDate;
}
public void setBeginningDate(Date beginningDate) {
public void setBeginningDate(LocalDateTime beginningDate) {
this.beginningDate = beginningDate;
}
public Integer getDoseFrequency() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public AppointmentService(AppointmentRepository appointmentRepository, Appointme
this.appointmentRepository = appointmentRepository;
this.appointmentMapper = appointmentMapper;
}

public AppointmentDTO getAppointmentById(Integer id) {
Appointment appointment = appointmentRepository.findById(id).orElse(null);
return appointment != null ? appointmentMapper.convertToDto(appointment) : null;
Expand Down Expand Up @@ -56,6 +57,7 @@ public List<AppointmentDTO> getAllAppointmentsForPetOwner(Integer petOwnerId) {
return null;
}
}

public List<AppointmentDTO> getAllAppointmentsForVeterinarian(Integer vetId) {
Optional<List<Appointment>> appointmentsOptional = appointmentRepository.getAppointmentsForVetID(vetId);

Expand Down Expand Up @@ -110,12 +112,5 @@ public AppointmentDTO deleteAppointment(Integer id) {
// Return null if the target entity does not exist.
return null;
}

// public AppointmentDTO createAppointment(AppointmentDTO appointmentDTO) {
// Appointment appointment = appointmentMapper.convertToEntity(appointmentDTO);
// Appointment savedAppointment = appointmentRepository.save(appointment);
// return appointmentMapper.convertToDto(savedAppointment);
// }
// Other service methods for creating, updating, and deleting appointments
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.boot.test.context.SpringBootTest;

import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@SpringBootTest
Expand All @@ -28,13 +30,13 @@ void createEntity() {

Appointment test_appointment = new Appointment();
test_appointment.setAppointmentID(1773);
test_appointment.setAppointmentDate(new Date(17731731));
test_appointment.setAppointmentDate(LocalDateTime.now());
test_appointment.setPetID(test_pet);
test_appointment.setVetID(test_veterinarian);
test_appointment.setPetOwnerID(test_pet_owner);

assertThat(test_appointment.getAppointmentID()).isEqualTo(1773);
assertThat(test_appointment.getAppointmentDate()).isEqualTo(new Date(17731731));
assertThat(test_appointment.getAppointmentDate()).isEqualTo(LocalDate.now());
assertThat(test_appointment.getPetID().getAppointments().size()).isEqualTo(4);
assertThat(test_appointment.getVetID().getAppointments().size()).isEqualTo(2);
assertThat(test_appointment.getPetOwnerID().getAppointments().size()).isEqualTo(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void createEntity() {
Schedule test_schedule = new Schedule();
test_schedule.setDoseCount(15);
test_schedule.setScheduleID(1915);
test_schedule.setBeginningDate(new Date(3451));
// test_schedule.setBeginningDate(new Date(3451));
test_schedule.setMedications(List.of(new Medication()));
test_schedule.setDoseFrequency(20);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -155,7 +157,7 @@ public void loadSeedToDatabase() {
//Create an Appointment
Appointment exampleAppointment = new Appointment();
Date date = new Date();
exampleAppointment.setAppointmentDate(date);
exampleAppointment.setAppointmentDate(LocalDateTime.now());
exampleAppointment.setVetID(exampleVeterinarian);
exampleAppointment.setPetID(examplePet);
exampleAppointment.setPetOwnerID(exampleOwner);
Expand All @@ -175,7 +177,7 @@ public void loadSeedToDatabase() {

//Create Schedule
Schedule exampleSchedule = new Schedule();
exampleSchedule.setBeginningDate(new Date());
exampleSchedule.setBeginningDate(LocalDateTime.now());
exampleSchedule.setDoseCount(1);
exampleSchedule.setDoseFrequency(1);

Expand Down

0 comments on commit d26ba08

Please sign in to comment.