diff --git a/pom.xml b/pom.xml index 689858c..d027642 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,10 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-data-jpa + diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Attraction.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Attraction.java new file mode 100644 index 0000000..52607a1 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Attraction.java @@ -0,0 +1,47 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "ATTRACTIONS") +@NoArgsConstructor +@Getter +@Setter +public class Attraction extends Point { + + @Column(name = "BEST_TIME") + protected String bestTime; + @Column(name = "HARDNESS_DEGREE") + protected Float hardnessDegree; + + + + public Attraction(String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province, String bestTime, Float hardness) { + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; + this.hardnessDegree = hardness; + this.bestTime = bestTime; + } + + public Attraction(Long id, String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province, String bestTime, Float hardness) { + this.id = id; + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; + this.hardnessDegree = hardness; + this.bestTime = bestTime; + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionComment.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionComment.java new file mode 100644 index 0000000..5c5d855 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionComment.java @@ -0,0 +1,17 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Entity +@Table(name = "ATTRACTION_COMMENTS") +@NoArgsConstructor +@Getter +@Setter +public class AttractionComment extends Comment { + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionRates.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionRates.java new file mode 100644 index 0000000..7d760e9 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/AttractionRates.java @@ -0,0 +1,30 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "ATTRACTION_RATES") +@NoArgsConstructor +@Getter +@Setter +public class AttractionRates extends Rates { + // todo: complete it + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + @Column(name = "id", nullable = false) + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Comment.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Comment.java new file mode 100644 index 0000000..ba38810 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Comment.java @@ -0,0 +1,69 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@Getter +@Setter +@MappedSuperclass +@AllArgsConstructor +public class Comment implements Cloneable { + @Id + @GeneratedValue() + @Column(name = "ID", nullable = false) + protected Long id; + + @Column(name = "POINT_ID", nullable = false) + protected Long pointId; + + @Column(name = "USER_ID", nullable = false) + protected String userId; + + @Column(name = "Title", nullable = false) + protected String title; + + @Column(name = "CONTEXT", nullable = false) + protected String context; + + @Column(name = "REJECTED_DESCRIPTION", nullable = true) + protected String rejectedDescription; + + @Column(name = "INSERT_DATETIME") + protected LocalDateTime insertDateTime; + + @Column(name = "CHANGE_STATUS_DATETIME") + protected LocalDateTime changeStatusDateTime; + + @ManyToOne + @JoinColumn(name = "COMMENT_STATUS_id") + protected CommentStatus commentStatus; + + @PrePersist + public void saveTime() { + insertDateTime = LocalDateTime.now(); + } + + @PreUpdate + public void saveUpdateTime() { + changeStatusDateTime = LocalDateTime.now(); + } + + @Override + public int hashCode() { + if (id != null) { + return id.hashCode(); + } + return super.hashCode(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/CommentStatus.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/CommentStatus.java new file mode 100644 index 0000000..7a2dd13 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/CommentStatus.java @@ -0,0 +1,29 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Entity +@Table(name = "COMMENT_STATUSES") +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class CommentStatus { + + @Id + private Integer id; + private String name; + private Integer statusValue; + private String description; + private short isActive; + + + } diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlace.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlace.java new file mode 100644 index 0000000..3dfd8aa --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlace.java @@ -0,0 +1,35 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "EATING_PLACES") +@NoArgsConstructor +@Getter +@Setter +public class EatingPlace extends Point{ + + public EatingPlace(String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province) { + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; + } + + public EatingPlace(Long id, String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province) { + this.id = id; + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceComment.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceComment.java new file mode 100644 index 0000000..d8898cb --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceComment.java @@ -0,0 +1,16 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "EATINGPLACE_COMMENTS") +@NoArgsConstructor +@Getter +@Setter +public class EatingPlaceComment extends Comment { + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceRates.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceRates.java new file mode 100644 index 0000000..28739c1 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/EatingPlaceRates.java @@ -0,0 +1,16 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "EATING_PLACE_RATES") +@NoArgsConstructor +@Getter +@Setter +public class EatingPlaceRates extends Rates { + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Keywords.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Keywords.java new file mode 100644 index 0000000..19afe23 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Keywords.java @@ -0,0 +1,34 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "KEYWORDS") +@NoArgsConstructor +@Getter +@Setter +public class Keywords { + @Id + @GeneratedValue() + @Column(name = "id", nullable = false) + private Long id; + + //todo: +// @UniqueConstraint("name") + private String name; + + public Keywords(String name) { + this.name = name; + } + + @Override + public int hashCode() { + if (id != null) { + return id.hashCode(); + } + return super.hashCode(); + } +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Point.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Point.java new file mode 100644 index 0000000..765c651 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Point.java @@ -0,0 +1,69 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@Getter +@Setter +@MappedSuperclass +public class Point implements Cloneable{ + @Id + @GeneratedValue() + @Column(name = "ID", nullable = false) + protected Long id; + + @Column(name = "NAME", nullable = false) + protected String name; + + @Column(name = "DESCRIPTION", nullable = false) + protected String description; + + @Column(name = "LATITUDE", nullable = false) + protected Double latitude; + + @Column(name = "LONGITUDE", nullable = false) + protected Double longitude; + + @Column(name = "IMAGESNAME") + protected String imagesName; + + @Column(name = "RATE",columnDefinition="Float default '0'") + protected Float rate; + + @Column(name = "INSERT_DATETIME") + protected LocalDateTime insertDateTime; + + + @ManyToOne + @JoinColumn(name = "POINT_STATUSES_id", nullable = false) + protected PointStatus pointStatus; + + @ManyToOne + @JoinColumn(name = "PROVINCES_code", nullable = false) + protected Province province; + + @PrePersist + public void saveTime() { + insertDateTime = LocalDateTime.now(); + if (rate == null || rate.compareTo(0F) == 0) + rate = 0F; + } + + @Override + public int hashCode() { + if (id != null) { + return id.hashCode(); + } + return super.hashCode(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/PointStatus.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/PointStatus.java new file mode 100644 index 0000000..ccae025 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/PointStatus.java @@ -0,0 +1,52 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +@Entity +@Table(name = "POINT_STATUSES") +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class PointStatus { + + @Id + private Integer id; + private String name; + private Integer statusValue; + private String description; + private short isActive; + + /*@OneToMany(mappedBy = "pointStatus") + private Set attractions;*/ + + /* public PointStatus(Integer id, String name, Integer value, String description, short isActive) { + this.id= id; + this.name = name; + this.statusValue = value; + this.description = description; + this.isActive = isActive; + }*/ + + /* @Override + public boolean equals(Object obj) { + if (!(obj instanceof PointStatus)) { + return false; // null or other class + } + PointStatus other = (PointStatus) obj; + + if (id != null) { + return id.equals(other.id); + } + return super.equals(other); + }*/ + + } diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Province.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Province.java new file mode 100644 index 0000000..ba0174d --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Province.java @@ -0,0 +1,44 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Objects; + +@Entity +@Table(name = "PROVINCES") +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class Province { + + + @Id + private Integer code; + private Integer nationalIdentifier; + private String name; + +/* @OneToMany(mappedBy = "province") + private Set attractions;*/ +/* + public Province(Integer code, Integer nationalIdentifier, String name) { + this.code = code; + this.nationalIdentifier = nationalIdentifier; + this.name = name; + }*/ + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Province province = (Province) o; + return Objects.equals(nationalIdentifier, province.nationalIdentifier); + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Rates.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Rates.java new file mode 100644 index 0000000..de4a871 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Rates.java @@ -0,0 +1,52 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@Getter +@Setter +@MappedSuperclass +public class Rates implements Cloneable { + @Id + @GeneratedValue() + @Column(name = "id", nullable = false) + protected Long id; + + @Column(name = "POINT_ID", nullable = false) + protected Long pointId; + + @Column(name = "USER_ID", nullable = false) + protected String userId; + + @Column(name = "VALUE", nullable = false) + protected String value; + + @Column(name = "COUNTED", nullable = false) + protected Boolean counted; + + @Column(name = "INSERT_DATETIME") + protected LocalDateTime insertDateTime; + + @PrePersist + public void saveTime() { + insertDateTime = LocalDateTime.now(); + } + + @Override + public int hashCode() { + if (id != null) { + return id.hashCode(); + } + return super.hashCode(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Residence.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Residence.java new file mode 100644 index 0000000..268780a --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Residence.java @@ -0,0 +1,39 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "RESIDENCE") +@NoArgsConstructor +@Getter +@Setter +public class Residence extends Point{ + +// protected String bestTime; +// protected Integer hardness; + + public Residence(String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province) { + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; +// this.hardness = hardness; +// this.bestTime = bestTime; + } + + public Residence(Long id, String name, String description, Double latitude, Double longitude, PointStatus pointStatus, Province province) { + this.id = id; + this.name = name; + this.description = description; + this.latitude = latitude; + this.longitude = longitude; + this.pointStatus = pointStatus; + this.province = province; + } +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceComment.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceComment.java new file mode 100644 index 0000000..885042b --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceComment.java @@ -0,0 +1,16 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "RESIDENCE_COMMENTS") +@NoArgsConstructor +@Getter +@Setter +public class ResidenceComment extends Comment { + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceRates.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceRates.java new file mode 100644 index 0000000..d551fc0 --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/ResidenceRates.java @@ -0,0 +1,16 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "RESIDENCE_RATES") +@NoArgsConstructor +@Getter +@Setter +public class ResidenceRates extends Rates { + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Search.java b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Search.java new file mode 100644 index 0000000..239a70a --- /dev/null +++ b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/entity/Search.java @@ -0,0 +1,47 @@ +package ir.chaarfasl.back.api.core.dataAccess.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "SEARCH") +@NoArgsConstructor +@Getter +@Setter +public class Search { + @Id + @GeneratedValue() + @Column(name = "id", nullable = false) + private Long id; + private long keywordId; + private long pointId; + private String pointType; + private Double latitude; + private Double longitude; + private Integer index; + + @ManyToOne + @JoinColumn(name = "PROVINCES_code", nullable = false) + private Province province; + + public Search(long keywordId, long pointId, String pointType, Double latitude, Double longitude, Province province, Integer index) { + this.keywordId = keywordId; + this.pointId = pointId; + this.pointType = pointType; + this.latitude = latitude; + this.longitude = longitude; + this.province = province; + this.index = index; + } + + @Override + public int hashCode() { + if (id != null) { + return id.hashCode(); + } + return super.hashCode(); + } + +} diff --git a/src/main/java/ir/chaarfasl/back/api/core/repository/.gitkeep b/src/main/java/ir/chaarfasl/back/api/core/dataAccess/repository/.gitkeep similarity index 100% rename from src/main/java/ir/chaarfasl/back/api/core/repository/.gitkeep rename to src/main/java/ir/chaarfasl/back/api/core/dataAccess/repository/.gitkeep