Реализовано 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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.example.nekontakte.posts.model.PostEntity; import com.example.nekontakte.posts.model.PostEntity;
import com.example.nekontakte.posts.service.PostService; import com.example.nekontakte.posts.service.PostService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@RestController @RestController

View File

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

View File

@ -1,5 +1,10 @@
package com.example.nekontakte.posts.repository; 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; package com.example.nekontakte.posts.service;
import java.util.List; 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.model.PostEntity;
import com.example.nekontakte.posts.repository.PostRepository; import com.example.nekontakte.posts.repository.PostRepository;
@Service
public class PostService { public class PostService {
private final PostRepository repository; private final PostRepository repository;
@ -27,17 +30,12 @@ public class PostService {
} }
public PostEntity update(Integer id, PostEntity entity) { public PostEntity update(Integer id, PostEntity entity) {
final PostEntity existsentity = get(id); final PostEntity existEntity = get(id);
existsentity.setUsername(entity.getUsername()); existEntity.setUserId(entity.getUserId());
existsentity.setPassword(entity.getPassword()); existEntity.setPubDate(entity.getPubDate());
existsentity.setIsAdmin(entity.getIsAdmin()); existEntity.setImage(entity.getImage());
existsentity.setName(entity.getName()); existEntity.setHtml(entity.getHtml());
existsentity.setSurname(entity.getSurname()); return repository.update(existEntity);
existsentity.setStatus(entity.getStatus());
existsentity.setBirthday(entity.getBirthday());
existsentity.setCity(entity.getCity());
existsentity.setStatus(entity.getStatus());
return repository.update(existsentity);
} }
public PostEntity delete(Integer id) { public PostEntity delete(Integer id) {