mvp
This commit is contained in:
@@ -14,6 +14,7 @@ import com.example.oneul.domain.post.service.command.PostCommandService;
|
||||
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/post")
|
||||
public class PostCommandApi {
|
||||
@@ -35,4 +36,10 @@ public class PostCommandApi {
|
||||
return post;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/{postId}/", method=RequestMethod.DELETE)
|
||||
public String deletePost(HttpSession httpSession, @PathVariable Long postId) {
|
||||
postCommandService.deletePost(postId, httpSession);
|
||||
return postId + " is deleted";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.example.oneul.domain.post.domain.Post;
|
||||
import com.example.oneul.domain.user.domain.UserEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PostCommandRepository extends JpaRepository<Post, Long> {
|
||||
Post save(Post post);
|
||||
Optional<Post> findByIdAndWriter(Long id, UserEntity writer);
|
||||
|
||||
@@ -61,6 +61,9 @@ public class PostCommnadServiceImpl implements PostCommandService{
|
||||
Post postEntity = postCommandRepository.findByIdAndWriter(id, userEntity).orElseThrow(() -> new NotFoundException(id + " post not found"));
|
||||
postEntity.setConent(post.getContent());
|
||||
postEntity = postCommandRepository.save(postEntity);
|
||||
PostDocument postDocument = postQueryRepository.findById(postEntity.getId()).orElseThrow(() -> new NotFoundException("query repository doesn't have " + id));
|
||||
postDocument.setContent(postEntity.getContent());
|
||||
postQueryRepository.save(postDocument);
|
||||
log.info(postEntity.toString() + " is updated");
|
||||
|
||||
return postEntity;
|
||||
@@ -71,6 +74,7 @@ public class PostCommnadServiceImpl implements PostCommandService{
|
||||
// TODO: 이 때 세션이 만기되면 어떡함
|
||||
UserEntity userEntity = (UserEntity)httpSession.getAttribute("user");
|
||||
postCommandRepository.deleteByIdAndWriter(id, userEntity);
|
||||
postQueryRepository.deleteById(id);
|
||||
log.info("post " + id + " is deleted");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user