именены классы юзеров

This commit is contained in:
ekallin 2024-04-14 23:26:52 +03:00
parent e83cce2315
commit e865488ab5
3 changed files with 19 additions and 6 deletions

View File

@ -4,15 +4,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
public class UserDTO { public class UserDTO {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Integer id; private Integer id;
@NotBlank @NotBlank
@Size(min = 2, max = 50)
private String username; private String username;
@NotBlank @NotBlank
@Size(min = 2, max = 10)
private String password; private String password;
@NotNull @NotNull

View File

@ -4,10 +4,21 @@ import java.util.Objects;
import com.example.backend.core.model.BaseEntity; import com.example.backend.core.model.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "users")
public class UserEntity extends BaseEntity { public class UserEntity extends BaseEntity {
@Column(nullable = false, unique = true, length = 15)
private String username; private String username;
@Column(nullable = false, unique = true, length = 5)
private String password; private String password;
@Column(nullable = false)
private boolean isAdmin; private boolean isAdmin;
public UserEntity() { public UserEntity() {
@ -15,7 +26,6 @@ public class UserEntity extends BaseEntity {
} }
public UserEntity(Integer id, String username, String password, boolean isAdmin) { public UserEntity(Integer id, String username, String password, boolean isAdmin) {
super(id);
this.username = username; this.username = username;
this.password = password; this.password = password;
this.isAdmin = isAdmin; this.isAdmin = isAdmin;

View File

@ -1,11 +1,10 @@
package com.example.backend.users.repository; package com.example.backend.users.repository;
import org.springframework.stereotype.Repository; import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import com.example.backend.core.repository.MapRepository;
import com.example.backend.users.model.UserEntity; import com.example.backend.users.model.UserEntity;
@Repository public interface UserRepository extends CrudRepository<UserEntity, Integer> {
public class UserRepository extends MapRepository<UserEntity> { Optional<UserEntity> findByUsernameIgnoreCase(String username);
} }