aoztepe
7/20/2018 - 8:17 AM

User

User Entity

  package com.ozysoft.matchbie.domain.users;

import com.ozysoft.matchbie.enums.UserRoles;
import com.ozysoft.matchbie.helper.LocalDateTimeAttributeConverter;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.UUID;

@ToString
@Getter
@Setter
@Entity
@Table(name = "api_users")
public class Users {

    @Id
    @GenericGenerator(name = "uuid-gen", strategy = "uuid2")
    @GeneratedValue(generator = "uuid-gen")
    @Type(type = "pg-uuid")
    private UUID id;

    @Column(name = "user_name", nullable = false, unique = true)
    private String userName;

    @Column(name = "email", nullable = false, unique = true)
    private String email;

    @Column(name = "password", nullable = false)
    private String password;

    @Column(name = "activation_key")
    private String activationKey;

    @Column(name = "role")
    @Enumerated(value = EnumType.STRING)
    private UserRoles roles;

    @Column(name = "is_online")
    private Boolean isOnline = false;

    @Column(name = "status")
    private Boolean status;

    @Column(name = "enabled")
    private Boolean enabled;

    @Column(name = "created", updatable = false, nullable = false)
    @Convert(converter = LocalDateTimeAttributeConverter.class)
    private LocalDateTime created;

    @Column(name = "updated", insertable = false)
    @Convert(converter = LocalDateTimeAttributeConverter.class)
    private LocalDateTime updated;

    @PrePersist
    protected void onCreate() {
        if (this.created == null) {
            this.created = LocalDateTime.now();
        }
    }

    @PreUpdate
    protected void onUpdate() {
        this.updated = LocalDateTime.now();
    }

}