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;
|
||||
|
||||
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 {
|
||||
@Override
|
||||
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
registry.addMapping("lab2/**")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE");
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ public interface CommonRepository<E, T> {
|
||||
E create(E entity);
|
||||
E update(E entity);
|
||||
E delete(E entity);
|
||||
void deleteAll();
|
||||
long deleteAll();
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
@Override
|
||||
public E create(E entity){
|
||||
entity.setId(++lastId);
|
||||
entities.put(lastId, entity);
|
||||
return entity;
|
||||
return entities.put(lastId, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,8 +33,7 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
if (get(entity.getId()) == null){
|
||||
return null;
|
||||
}
|
||||
entities.put(entity.getId(), entity);
|
||||
return entity;
|
||||
return entities.put(entity.getId(), entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,14 +41,14 @@ public abstract class MapRepository<E extends BaseEntity> implements CommonRepos
|
||||
if (get(entity.getId()) == null){
|
||||
return null;
|
||||
}
|
||||
entities.remove(entity.getId());
|
||||
return entity;
|
||||
return entities.remove(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(){
|
||||
public long deleteAll(){
|
||||
long count = lastId;
|
||||
lastId = 0L;
|
||||
entities.clear();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class UserController {
|
||||
}
|
||||
|
||||
private UserEntity toEntity(UserDTO dto){
|
||||
return new UserEntity(-1L, dto.getName(), dto.getPassword());
|
||||
return modelMapper.map(dto, UserEntity.class);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
|
@ -1,9 +1,15 @@
|
||||
package com.example.demo.users.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
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 {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotNull
|
||||
@Min(2)
|
||||
@ -11,6 +17,9 @@ public class UserDTO {
|
||||
@NotNull
|
||||
@Min(4)
|
||||
private String password;
|
||||
@NotNull
|
||||
@Past
|
||||
private Date dateCreate;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -18,17 +27,15 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
public UserEntity(Long id, String name, String password) {
|
||||
public UserEntity(Long id, String name, String password, Date dateCreate){
|
||||
super(id);
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.dateCreate = new Date();
|
||||
this.dateCreate = dateCreate;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
@ -34,7 +34,7 @@ public class UserService {
|
||||
final UserEntity existEntity = get(id);
|
||||
existEntity.setName(entity.getName());
|
||||
existEntity.setPassword(entity.getPassword());
|
||||
return repository.update(existEntity);
|
||||
return repository.update(entity);
|
||||
}
|
||||
|
||||
public UserEntity delete(Long id){
|
||||
|
Loading…
Reference in New Issue
Block a user