работает
This commit is contained in:
parent
4cc4300a14
commit
d3779e0ee2
@ -1,5 +1,5 @@
|
||||
package com.example.demo.core.config;
|
||||
|
||||
public class Constants {
|
||||
public static final String API_URL = "/api/2";
|
||||
public static final String API_URL = "/api_2";
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ public interface CommonRepository<E, T> {
|
||||
E create(E entity);
|
||||
E update(E entity);
|
||||
E delete(E entity);
|
||||
long deleteAll();
|
||||
void deleteAll();
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
@Override
|
||||
public E create(E entity){
|
||||
entity.setId(++lastId);
|
||||
return entities.put(lastId, entity);
|
||||
entities.put(lastId, entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,7 +34,8 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
if (get(entity.getId()) == null){
|
||||
return null;
|
||||
}
|
||||
return entities.put(entity.getId(), entity);
|
||||
entities.put(entity.getId(), entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,14 +43,14 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
if (get(entity.getId()) == null){
|
||||
return null;
|
||||
}
|
||||
return entities.remove(entity.getId());
|
||||
entities.remove(entity.getId());
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long deleteAll(){
|
||||
public void deleteAll(){
|
||||
long count = lastId;
|
||||
lastId = 0L;
|
||||
entities.clear();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class UserController {
|
||||
}
|
||||
|
||||
private UserEntity toEntity(UserDTO dto){
|
||||
return modelMapper.map(dto, UserEntity.class);
|
||||
return new UserEntity(-1L, dto.getName(), dto.getPassword());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
|
@ -1,13 +1,9 @@
|
||||
package com.example.demo.users.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class UserDTO {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotNull
|
||||
@Min(2)
|
||||
@ -28,4 +24,11 @@ public class UserDTO {
|
||||
public void setPassword(String password){
|
||||
this.password = password;
|
||||
}
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
public long getId(){
|
||||
return id;
|
||||
}
|
||||
public void setId(long id){
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.example.demo.users.api;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
|
||||
public class UserMapper extends ModelMapper {
|
||||
|
||||
}
|
@ -2,8 +2,6 @@ package com.example.demo.users.model;
|
||||
|
||||
import com.example.demo.core.model.BaseEntity;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class UserEntity extends BaseEntity {
|
||||
@ -15,9 +13,7 @@ public class UserEntity extends BaseEntity {
|
||||
super();
|
||||
}
|
||||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yy");
|
||||
|
||||
public UserEntity(Long id, String name, String password, String dateCreate) throws ParseException {
|
||||
public UserEntity(Long id, String name, String password) {
|
||||
super(id);
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
@ -40,8 +36,8 @@ public class UserEntity extends BaseEntity {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDateCreate(){
|
||||
return formatter.format(dateCreate);
|
||||
public Date getDateCreate(){
|
||||
return dateCreate;
|
||||
}
|
||||
|
||||
public void setDateCreate(Date dateCreate){
|
||||
|
@ -34,7 +34,7 @@ public class UserService {
|
||||
final UserEntity existEntity = get(id);
|
||||
existEntity.setName(entity.getName());
|
||||
existEntity.setPassword(entity.getPassword());
|
||||
return repository.update(entity);
|
||||
return repository.update(existEntity);
|
||||
}
|
||||
|
||||
public UserEntity delete(Long id){
|
||||
|
Loading…
Reference in New Issue
Block a user