diff --git a/src/main/java/com/maires/wnet/entity/Customer.java b/src/main/java/com/maires/wnet/entity/Customer.java index 5a73020..53b3ae4 100644 --- a/src/main/java/com/maires/wnet/entity/Customer.java +++ b/src/main/java/com/maires/wnet/entity/Customer.java @@ -1,5 +1,6 @@ package com.maires.wnet.entity; +import com.maires.wnet.utils.DateUtil; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -8,8 +9,6 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; @@ -54,9 +53,7 @@ public Customer(String name, String cpf, String phone, String email) { this.cpf = cpf; this.phone = phone; this.email = email; - LocalDateTime now = LocalDateTime.now().minusHours(3); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy'T'HH:mm:ss"); - this.registrationDate = now.format(formatter); + this.registrationDate = DateUtil.formatCurrentDate(); } /** diff --git a/src/main/java/com/maires/wnet/entity/Equipment.java b/src/main/java/com/maires/wnet/entity/Equipment.java index f6f7d61..7024fff 100644 --- a/src/main/java/com/maires/wnet/entity/Equipment.java +++ b/src/main/java/com/maires/wnet/entity/Equipment.java @@ -4,7 +4,8 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import java.util.Date; @@ -30,11 +31,9 @@ public class Equipment { private Date provisionDate; - @OneToOne - private Installation installationFirst; - - @OneToOne - private Installation installationSecond; + @ManyToOne + @JoinColumn(name = "installation_id") + private Installation installation; /** * Instantiates a new Equipment. @@ -77,18 +76,18 @@ public void setId(Long id) { } /** - * Gets addressType. + * Gets type. * - * @return the addressType + * @return the type */ public String getType() { return type; } /** - * Sets addressType. + * Sets type. * - * @param type the addressType + * @param type the type */ public void setType(String type) { this.type = type; @@ -165,4 +164,22 @@ public Date getProvisionDate() { public void setProvisionDate(Date provisionDate) { this.provisionDate = provisionDate; } + + /** + * Gets installation. + * + * @return the installation + */ + public Installation getInstallation() { + return installation; + } + + /** + * Sets installation. + * + * @param installation the installation + */ + public void setInstallation(Installation installation) { + this.installation = installation; + } } \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/entity/Installation.java b/src/main/java/com/maires/wnet/entity/Installation.java index cd4b611..7350556 100644 --- a/src/main/java/com/maires/wnet/entity/Installation.java +++ b/src/main/java/com/maires/wnet/entity/Installation.java @@ -1,14 +1,16 @@ package com.maires.wnet.entity; +import com.maires.wnet.utils.DateUtil; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import java.util.Date; +import java.util.List; /** * The type Installation. @@ -25,11 +27,8 @@ public class Installation { @JoinColumn(name = "address_id") private Address address; - @OneToOne(mappedBy = "installationFirst", cascade = CascadeType.ALL) - private Equipment equipmentFirst; - - @OneToOne(mappedBy = "installationSecond", cascade = CascadeType.ALL) - private Equipment equipmentSecond; + @OneToMany(mappedBy = "installation", cascade = CascadeType.ALL) + private List equipments; @OneToOne @JoinColumn(name = "plan_id") @@ -38,7 +37,7 @@ public class Installation { @OneToOne(mappedBy = "installation", cascade = CascadeType.ALL) private Technician technician; - private Date installationDate; + private String installationDate; /** * Instantiates a new Installation. @@ -57,7 +56,7 @@ public Installation(Address address, Plan plan, Technician technician) { this.address = address; this.plan = plan; this.technician = technician; - this.installationDate = new Date(); + this.installationDate = DateUtil.formatCurrentDate(); } /** @@ -79,57 +78,39 @@ public void setId(Long id) { } /** - * Gets address id. + * Gets address. * - * @return the address id + * @return the address */ public Address getAddress() { return address; } /** - * Sets address id. + * Sets address. * - * @param address the address id + * @param address the address */ public void setAddress(Address address) { this.address = address; } /** - * Gets equipment first. - * - * @return the equipment first - */ - public Equipment getEquipmentFirst() { - return equipmentFirst; - } - - /** - * Sets equipment first. + * Gets equipments. * - * @param equipmentFirst the equipment first + * @return the equipments */ - public void setEquipmentFirst(Equipment equipmentFirst) { - this.equipmentFirst = equipmentFirst; + public List getEquipments() { + return equipments; } /** - * Gets equipment second. + * Sets equipments. * - * @return the equipment second + * @param equipments the equipments */ - public Equipment getEquipmentSecond() { - return equipmentSecond; - } - - /** - * Sets equipment second. - * - * @param equipmentSecond the equipment second - */ - public void setEquipmentSecond(Equipment equipmentSecond) { - this.equipmentSecond = equipmentSecond; + public void setEquipments(List equipments) { + this.equipments = equipments; } /** @@ -151,36 +132,18 @@ public void setPlan(Plan plan) { } /** - * Gets plan id. - * - * @return the plan id - */ - public Plan getPlanId() { - return plan; - } - - /** - * Sets plan id. - * - * @param plan the plan id - */ - public void setPlanId(Plan plan) { - this.plan = plan; - } - - /** - * Gets technician id. + * Gets technician. * - * @return the technician id + * @return the technician */ public Technician getTechnician() { return technician; } /** - * Sets technician id. + * Sets technician. * - * @param technician the technician id + * @param technician the technician */ public void setTechnician(Technician technician) { this.technician = technician; @@ -191,7 +154,7 @@ public void setTechnician(Technician technician) { * * @return the installation date */ - public Date getInstallationDate() { + public String getInstallationDate() { return installationDate; } @@ -200,7 +163,7 @@ public Date getInstallationDate() { * * @param installationDate the installation date */ - public void setInstallationDate(Date installationDate) { + public void setInstallationDate(String installationDate) { this.installationDate = installationDate; } } \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/AddressRepository.java b/src/main/java/com/maires/wnet/repository/AddressRepository.java new file mode 100644 index 0000000..e9161e6 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/AddressRepository.java @@ -0,0 +1,13 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Address; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * The interface Address repository. + */ +@Repository +public interface AddressRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/CustomerRepository.java b/src/main/java/com/maires/wnet/repository/CustomerRepository.java new file mode 100644 index 0000000..7b92e24 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/CustomerRepository.java @@ -0,0 +1,13 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Customer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * The interface Customer repository. + */ +@Repository +public interface CustomerRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/EquipmentRepository.java b/src/main/java/com/maires/wnet/repository/EquipmentRepository.java new file mode 100644 index 0000000..a4eff28 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/EquipmentRepository.java @@ -0,0 +1,11 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Equipment; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * The interface Equipment repository. + */ +public interface EquipmentRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/InstallationRepository.java b/src/main/java/com/maires/wnet/repository/InstallationRepository.java new file mode 100644 index 0000000..fd704e2 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/InstallationRepository.java @@ -0,0 +1,13 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Installation; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * The interface Installation repository. + */ +@Repository +public interface InstallationRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/PlanRepository.java b/src/main/java/com/maires/wnet/repository/PlanRepository.java new file mode 100644 index 0000000..1e34c13 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/PlanRepository.java @@ -0,0 +1,11 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Plan; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * The interface Plan repository. + */ +public interface PlanRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/repository/TechnicianRepository.java b/src/main/java/com/maires/wnet/repository/TechnicianRepository.java new file mode 100644 index 0000000..7b0efc4 --- /dev/null +++ b/src/main/java/com/maires/wnet/repository/TechnicianRepository.java @@ -0,0 +1,11 @@ +package com.maires.wnet.repository; + +import com.maires.wnet.entity.Technician; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * The interface Technician repository. + */ +public interface TechnicianRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/maires/wnet/utils/DateUtil.java b/src/main/java/com/maires/wnet/utils/DateUtil.java new file mode 100644 index 0000000..a1ffffb --- /dev/null +++ b/src/main/java/com/maires/wnet/utils/DateUtil.java @@ -0,0 +1,24 @@ +package com.maires.wnet.utils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + + +/** + * The type Date util. + */ +public class DateUtil { + + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern( + "dd-MM-yyyy'T'HH:mm:ss"); + + /** + * Date util string. + * + * @return the string + */ + public static String formatCurrentDate() { + LocalDateTime now = LocalDateTime.now().minusHours(3); + return now.format(formatter); + } +} \ No newline at end of file