From ede9ec623969eac0f99b60042f2c17cf0b6d1d37 Mon Sep 17 00:00:00 2001 From: matiaguro <105395800+matiaguro@users.noreply.github.com> Date: Wed, 24 Aug 2022 10:36:34 -0300 Subject: [PATCH] [OT276-23] Crear modelo y repositorio base de Members (#4) * Crear modelo y repositorio base de Members * correccion de errores dentro del script sql, cambio de nombre * Correccion de errores en el tipeo * creacion de endpoint Member * revert changes --- .../com/alkemy/ong/core/model/Member.java | 73 +++++++++++++++++++ .../ong/core/repository/MemberRepository.java | 7 ++ .../migration/V1.23__create_table_member.sql | 16 ++++ 3 files changed, 96 insertions(+) create mode 100644 src/main/java/com/alkemy/ong/core/model/Member.java create mode 100644 src/main/java/com/alkemy/ong/core/repository/MemberRepository.java create mode 100644 src/main/resources/db/migration/V1.23__create_table_member.sql 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