Skip to content

Commit

Permalink
[OT276-23] Crear modelo y repositorio base de Members (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matiaguro authored Aug 24, 2022
1 parent 61ad7c3 commit ede9ec6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/main/java/com/alkemy/ong/core/model/Member.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Member, Long> {
}
16 changes: 16 additions & 0 deletions src/main/resources/db/migration/V1.23__create_table_member.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ede9ec6

Please sign in to comment.