Compare commits
No commits in common. "d3779e0ee2729304a2797a3d67990456e0a68aef" and "57a412b0d713e0c712816b8f4a5ead570f90def5" have entirely different histories.
d3779e0ee2
...
57a412b0d7
@ -1,5 +1,5 @@
|
|||||||
package com.example.demo.core.config;
|
package com.example.demo.core.config;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
public static final String API_URL = "/api_2";
|
public static final String API_URL = "/api";
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||||||
public class WebConfig implements WebMvcConfigurer {
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
@Override
|
@Override
|
||||||
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
||||||
registry.addMapping("/**")
|
registry.addMapping("lab2/**")
|
||||||
.allowedMethods("GET", "POST", "PUT", "DELETE");
|
.allowedMethods("GET", "POST", "PUT", "DELETE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,5 @@ public interface CommonRepository<E, T> {
|
|||||||
E create(E entity);
|
E create(E entity);
|
||||||
E update(E entity);
|
E update(E entity);
|
||||||
E delete(E entity);
|
E delete(E entity);
|
||||||
void deleteAll();
|
long deleteAll();
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,7 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
|||||||
@Override
|
@Override
|
||||||
public E create(E entity){
|
public E create(E entity){
|
||||||
entity.setId(++lastId);
|
entity.setId(++lastId);
|
||||||
entities.put(lastId, entity);
|
return entities.put(lastId, entity);
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -34,8 +33,7 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
|||||||
if (get(entity.getId()) == null){
|
if (get(entity.getId()) == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
entities.put(entity.getId(), entity);
|
return entities.put(entity.getId(), entity);
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,14 +41,14 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
|||||||
if (get(entity.getId()) == null){
|
if (get(entity.getId()) == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
entities.remove(entity.getId());
|
return entities.remove(entity.getId());
|
||||||
return entity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAll(){
|
public long deleteAll(){
|
||||||
long count = lastId;
|
long count = lastId;
|
||||||
lastId = 0L;
|
lastId = 0L;
|
||||||
entities.clear();
|
entities.clear();
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UserEntity toEntity(UserDTO dto){
|
private UserEntity toEntity(UserDTO dto){
|
||||||
return new UserEntity(-1L, dto.getName(), dto.getPassword());
|
return modelMapper.map(dto, UserEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package com.example.demo.users.api;
|
package com.example.demo.users.api;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import jakarta.validation.constraints.Past;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class UserDTO {
|
public class UserDTO {
|
||||||
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
private Long id;
|
private Long id;
|
||||||
@NotNull
|
@NotNull
|
||||||
@Min(2)
|
@Min(2)
|
||||||
@ -11,6 +17,9 @@ public class UserDTO {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Min(4)
|
@Min(4)
|
||||||
private String password;
|
private String password;
|
||||||
|
@NotNull
|
||||||
|
@Past
|
||||||
|
private Date dateCreate;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -18,17 +27,15 @@ public class UserDTO {
|
|||||||
public void setName(String name){
|
public void setName(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getDateCreate() {
|
||||||
|
return dateCreate;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
public void setPassword(String password){
|
public void setPassword(String password){
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
|
||||||
public long getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
public void setId(long id){
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package com.example.demo.users.api;
|
|
||||||
|
|
||||||
import org.modelmapper.ModelMapper;
|
|
||||||
|
|
||||||
public class UserMapper extends ModelMapper {
|
|
||||||
|
|
||||||
}
|
|
@ -13,11 +13,11 @@ public class UserEntity extends BaseEntity {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEntity(Long id, String name, String password) {
|
public UserEntity(Long id, String name, String password, Date dateCreate){
|
||||||
super(id);
|
super(id);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.dateCreate = new Date();
|
this.dateCreate = dateCreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
|
@ -34,7 +34,7 @@ public class UserService {
|
|||||||
final UserEntity existEntity = get(id);
|
final UserEntity existEntity = get(id);
|
||||||
existEntity.setName(entity.getName());
|
existEntity.setName(entity.getName());
|
||||||
existEntity.setPassword(entity.getPassword());
|
existEntity.setPassword(entity.getPassword());
|
||||||
return repository.update(existEntity);
|
return repository.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEntity delete(Long id){
|
public UserEntity delete(Long id){
|
||||||
|
Loading…
Reference in New Issue
Block a user