diff --git a/src/main/java/com/alkemy/ong/core/model/Member.java b/src/main/java/com/alkemy/ong/core/model/Member.java new file mode 100644 index 00000000..c539cdd5 --- /dev/null +++ b/src/main/java/com/alkemy/ong/core/model/Member.java @@ -0,0 +1,73 @@ +package com.alkemy.ong.core.model; + +import com.alkemy.ong.core.model.audit.Audit; +import com.alkemy.ong.core.model.audit.AuditListener; +import com.alkemy.ong.core.model.audit.Auditable; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Objects; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@Entity +@Table(name = "member") +@Where(clause = "is_active=true") +@SQLDelete(sql = "UPDATE member SET is_active=false WHERE member_id=?") +@EntityListeners(AuditListener.class) +public class Member implements Auditable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; + + @Column(nullable = false) + private String name; + + @Column + private String facebookUrl; + + @Column + private String instagramUrl; + + @Column + private String linkedinUrl; + + @Column(nullable = false) + private String image; + + @Column + private String description; + + @Embedded + private Audit audit; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Member member = (Member) o; + return Objects.equals(id, member.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + +} diff --git a/src/main/java/com/alkemy/ong/core/repository/MemberRepository.java b/src/main/java/com/alkemy/ong/core/repository/MemberRepository.java new file mode 100644 index 00000000..b1fb5b29 --- /dev/null +++ b/src/main/java/com/alkemy/ong/core/repository/MemberRepository.java @@ -0,0 +1,7 @@ +package com.alkemy.ong.core.repository; + +import com.alkemy.ong.core.model.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { +} diff --git a/src/main/resources/db/migration/V1.23__create_table_member.sql b/src/main/resources/db/migration/V1.23__create_table_member.sql new file mode 100644 index 00000000..ea435f18 --- /dev/null +++ b/src/main/resources/db/migration/V1.23__create_table_member.sql @@ -0,0 +1,16 @@ +drop table if exists member; + +create table member + ( + member_id bigint not null auto_increment, + name varchar(255) not null, + facebook_url varchar(255), + instagram_url varchar(255), + linkedin_url varchar(255), + image varchar(255) not null, + description varchar(255), + created_at datetime(6) not null, + is_active bit not null, + updated_at datetime(6) null, + primary key (member_id) + )engine = InnoDB; \ No newline at end of file