Files
skamp/src/main/java/de/iwomm/propify_api/entity/Property.java
2025-10-09 10:37:26 +02:00

227 lines
4.9 KiB
Java

package de.iwomm.propify_api.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Entity
public class Property {
@Id
@GeneratedValue
private UUID id;
@Column(nullable = false)
private String name;
private String owner;
@Column(nullable = false)
private String street;
@Column(nullable = false)
private String houseNumber;
@Column(nullable = false)
private String zipCode;
@Column(nullable = false)
private String city;
@ManyToOne
@JoinColumn(name = "federal_state_id")
private FederalState federalState;
private String notes;
@Column(nullable = false)
private int yearOfConstruction; // baujahr
@Column(nullable = false)
private int unitCount; // anzahl einheiten
@OneToMany(mappedBy = "property", orphanRemoval = true)
@OrderBy("fileName")
private List<Attachment> attachments;
@Column(nullable = false)
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
@OneToMany(mappedBy = "property", cascade = CascadeType.PERSIST, orphanRemoval = true)
@OrderBy("createdAt")
@JsonBackReference
private List<Project> projects = new ArrayList<>();
@ManyToOne(optional = false)
@JoinColumn(name = "property_status_id", nullable = false)
private PropertyStatus propertyStatus;
public PropertyStatus getPropertyStatus() {
return propertyStatus;
}
public void setPropertyStatus(PropertyStatus propertyStatus) {
this.propertyStatus = propertyStatus;
}
public List<Project> getProjects() {
return projects;
}
public void setProjects(List<Project> projects) {
this.projects = projects;
}
public List<Attachment> getAttachments() {
return attachments;
}
public void setAttachments(List<Attachment> attachment) {
this.attachments = attachment;
}
public Property() {}
public Property(
String name, String street, String houseNumber,
String zipCode, String city,
FederalState federalState,
String notes, PropertyStatus propertyStatus) {
this.name = name;
this.street = street;
this.houseNumber = houseNumber;
this.zipCode = zipCode;
this.city = city;
this.federalState = federalState;
this.notes = notes;
this.propertyStatus = propertyStatus;
}
@PrePersist
protected void onCreate() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}
@PreUpdate
protected void onUpdate() {
this.updatedAt = LocalDateTime.now();
}
public LocalDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}
public LocalDateTime getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getNotes() {
return this.notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public int getYearOfConstruction() {
return yearOfConstruction;
}
public void setYearOfConstruction(int yearOfConstruction) {
this.yearOfConstruction = yearOfConstruction;
}
public int getUnitCount() {
return unitCount;
}
public void setUnitCount(int unitCount) {
this.unitCount = unitCount;
}
public FederalState getFederalState() {
return federalState;
}
public void setFederalState(FederalState federalState) {
this.federalState = federalState;
}
public String getAddress() {
return this.street + " " + this.houseNumber + ", " + this.zipCode + " " + this.city;
}
}