Compare commits

..

2 Commits

Author SHA1 Message Date
bekodeg
d3779e0ee2 работает 2024-04-16 13:35:25 +04:00
bekodeg
4cc4300a14 почти работает 2024-04-13 16:01:02 +04:00
9 changed files with 29 additions and 27 deletions

View File

@ -1,5 +1,5 @@
package com.example.demo.core.config;
public class Constants {
public static final String API_URL = "/api";
public static final String API_URL = "/api_2";
}

View File

@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(@NonNull CorsRegistry registry) {
registry.addMapping("lab2/**")
registry.addMapping("/**")
.allowedMethods("GET", "POST", "PUT", "DELETE");
}
}

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,15 +1,9 @@
package com.example.demo.users.api;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Past;
import java.util.Date;
import jakarta.validation.constraints.*;
public class UserDTO {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
@NotNull
@Min(2)
@ -17,9 +11,6 @@ public class UserDTO {
@NotNull
@Min(4)
private String password;
@NotNull
@Past
private Date dateCreate;
public String getName() {
return name;
@ -27,15 +18,17 @@ public class UserDTO {
public void setName(String name){
this.name = name;
}
public Date getDateCreate() {
return dateCreate;
}
public String getPassword() {
return password;
}
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

@ -13,11 +13,11 @@ public class UserEntity extends BaseEntity {
super();
}
public UserEntity(Long id, String name, String password, Date dateCreate){
public UserEntity(Long id, String name, String password) {
super(id);
this.name = name;
this.password = password;
this.dateCreate = dateCreate;
this.dateCreate = new Date();
}
public String getName(){

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