работает

This commit is contained in:
bekodeg 2024-04-16 13:35:25 +04:00
parent 4cc4300a14
commit d3779e0ee2
8 changed files with 28 additions and 20 deletions

View File

@ -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";
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -0,0 +1,7 @@
package com.example.demo.users.api;
import org.modelmapper.ModelMapper;
public class UserMapper extends ModelMapper {
}

View File

@ -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){

View File

@ -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){