Skip to content

Commit

Permalink
Merge pull request #2 from mairess/creates-repository
Browse files Browse the repository at this point in the history
Creates repositories
  • Loading branch information
mairess authored Jun 29, 2024
2 parents 08958ab + 9351d92 commit 9107b34
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 77 deletions.
7 changes: 2 additions & 5 deletions src/main/java/com/maires/wnet/entity/Customer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;


Expand Down Expand Up @@ -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();
}

/**
Expand Down
37 changes: 27 additions & 10 deletions src/main/java/com/maires/wnet/entity/Equipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
87 changes: 25 additions & 62 deletions src/main/java/com/maires/wnet/entity/Installation.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Equipment> equipments;

@OneToOne
@JoinColumn(name = "plan_id")
Expand All @@ -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.
Expand All @@ -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();
}

/**
Expand All @@ -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<Equipment> 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<Equipment> equipments) {
this.equipments = equipments;
}

/**
Expand All @@ -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;
Expand All @@ -191,7 +154,7 @@ public void setTechnician(Technician technician) {
*
* @return the installation date
*/
public Date getInstallationDate() {
public String getInstallationDate() {
return installationDate;
}

Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/maires/wnet/repository/AddressRepository.java
Original file line number Diff line number Diff line change
@@ -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<Address, Long> {

}
13 changes: 13 additions & 0 deletions src/main/java/com/maires/wnet/repository/CustomerRepository.java
Original file line number Diff line number Diff line change
@@ -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<Customer, Long> {

}
11 changes: 11 additions & 0 deletions src/main/java/com/maires/wnet/repository/EquipmentRepository.java
Original file line number Diff line number Diff line change
@@ -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<Equipment, Long> {

}
Original file line number Diff line number Diff line change
@@ -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<Installation, Long> {

}
11 changes: 11 additions & 0 deletions src/main/java/com/maires/wnet/repository/PlanRepository.java
Original file line number Diff line number Diff line change
@@ -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<Plan, Long> {

}
11 changes: 11 additions & 0 deletions src/main/java/com/maires/wnet/repository/TechnicianRepository.java
Original file line number Diff line number Diff line change
@@ -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<Technician, Long> {

}
24 changes: 24 additions & 0 deletions src/main/java/com/maires/wnet/utils/DateUtil.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 9107b34

Please sign in to comment.