generated from alkemyTech/base-ong-server-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/alkemy/ong/core/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/resources/db/migration/V1.23__create_table_member.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |