From 0fe8ba86c60a96b4e67196074ba4ec9944e34d5d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 1 Jul 2024 02:46:30 +0300 Subject: JPA: map UserEntity to User using `mapstruct` library --- .../java/com/juick/data/entities/UserEntity.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/juick/data/entities') diff --git a/src/main/java/com/juick/data/entities/UserEntity.java b/src/main/java/com/juick/data/entities/UserEntity.java index 1984799e..63edadd9 100644 --- a/src/main/java/com/juick/data/entities/UserEntity.java +++ b/src/main/java/com/juick/data/entities/UserEntity.java @@ -18,6 +18,8 @@ package com.juick.data.entities; import jakarta.persistence.*; + +import java.time.OffsetDateTime; import java.util.HashSet; import java.util.Set; @@ -25,18 +27,22 @@ import java.util.Set; @Table(name = "users") public class UserEntity { @Id - @Column(name = "id", columnDefinition = "int(10) unsigned not null auto_increment") + @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; - @Column(name = "nick", columnDefinition = "char(64)") + @Column(name = "nick") private String name; - @Column(name = "passw", columnDefinition = "char(32)") + @Column(name = "passw") private String password; - @Column(name = "banned", columnDefinition = "tinyint(1)") + @Column(name = "banned") private boolean banned; + @Column(name = "last_seen") + private OffsetDateTime seen; + @Column + private boolean premium; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") private Set emails = new HashSet<>(); @@ -84,6 +90,14 @@ public class UserEntity { this.banned = banned; } + public OffsetDateTime getSeen() { + return this.seen; + } + + public void setSeen(OffsetDateTime seen) { + this.seen = seen; + } + public Set getEmails() { return emails; } @@ -123,4 +137,12 @@ public class UserEntity { public void setTgIds(Set tgIds) { this.tgIds = tgIds; } + + public boolean isPremium() { + return premium; + } + + public void setPremium(boolean premium) { + this.premium = premium; + } } -- cgit v1.2.3