Реализовано API для Post

This commit is contained in:
Никита Потапов 2024-03-29 14:08:53 +04:00
parent f5cfb3d95f
commit a038c57d1f
4 changed files with 17 additions and 17 deletions

View File

@ -10,13 +10,13 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.nekontakte.posts.model.PostEntity;
import com.example.nekontakte.posts.service.PostService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import jakarta.validation.Valid;
@RestController

View File

@ -2,7 +2,6 @@ package com.example.nekontakte.posts.api;
import java.util.Date;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
public class PostDTO {
@ -11,9 +10,7 @@ public class PostDTO {
private Integer userId;
@NotNull
private Date pubDate;
@NotBlank
private String image;
@NotBlank
private String html;
public Integer getId() {

View File

@ -1,5 +1,10 @@
package com.example.nekontakte.posts.repository;
public class PostRepository {
import org.springframework.stereotype.Repository;
import com.example.nekontakte.core.repository.MapRepository;
import com.example.nekontakte.posts.model.PostEntity;
@Repository
public class PostRepository extends MapRepository<PostEntity> {
}

View File

@ -1,12 +1,15 @@
package com.example.nekontakte.posts.service;
import java.util.List;
import java.util.Optional;
import org.apache.el.stream.Optional;
import org.springframework.stereotype.Service;
import com.example.nekontakte.core.errors.NotFoundException;
import com.example.nekontakte.posts.model.PostEntity;
import com.example.nekontakte.posts.repository.PostRepository;
@Service
public class PostService {
private final PostRepository repository;
@ -27,17 +30,12 @@ public class PostService {
}
public PostEntity update(Integer id, PostEntity entity) {
final PostEntity existsentity = get(id);
existsentity.setUsername(entity.getUsername());
existsentity.setPassword(entity.getPassword());
existsentity.setIsAdmin(entity.getIsAdmin());
existsentity.setName(entity.getName());
existsentity.setSurname(entity.getSurname());
existsentity.setStatus(entity.getStatus());
existsentity.setBirthday(entity.getBirthday());
existsentity.setCity(entity.getCity());
existsentity.setStatus(entity.getStatus());
return repository.update(existsentity);
final PostEntity existEntity = get(id);
existEntity.setUserId(entity.getUserId());
existEntity.setPubDate(entity.getPubDate());
existEntity.setImage(entity.getImage());
existEntity.setHtml(entity.getHtml());
return repository.update(existEntity);
}
public PostEntity delete(Integer id) {