|
3 | 3 | import java.util.List;
|
4 | 4 |
|
5 | 5 | import com.example.articlemanager.model.rqrs.AddArticleRs;
|
| 6 | +import lombok.extern.slf4j.Slf4j; |
6 | 7 | import org.springframework.beans.factory.annotation.Autowired;
|
7 | 8 | import org.springframework.http.HttpStatus;
|
8 | 9 | import org.springframework.stereotype.Repository;
|
|
14 | 15 | import com.example.articlemanager.repository.ArticleRepository;
|
15 | 16 |
|
16 | 17 | @Repository
|
| 18 | +@Slf4j |
17 | 19 | public class ArticleUsecase {
|
18 | 20 |
|
19 | 21 | @Autowired
|
@@ -67,8 +69,10 @@ public GenericResponse updateArticle(ArticleRequest article, Long id){
|
67 | 69 | articleRepository.save(newArticle);
|
68 | 70 |
|
69 | 71 | genericResponse.setSuccessMsg("Article Updated Successfully");
|
| 72 | + log.info("{}", genericResponse.getMessage()); |
70 | 73 | }catch(Exception e){
|
71 | 74 | genericResponse.setFailed(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
| 75 | + log.info("{}", genericResponse.getError()); |
72 | 76 | }
|
73 | 77 |
|
74 | 78 | return genericResponse;
|
@@ -115,22 +119,24 @@ public GenericResponse getArticleById(Long id){
|
115 | 119 | return genericResponse;
|
116 | 120 | }
|
117 | 121 |
|
118 |
| - public GenericResponse deleteArticleById(Long id){ |
| 122 | + public void deleteArticleById(Long id){ |
119 | 123 | GenericResponse genericResponse = new GenericResponse();
|
120 | 124 | try{
|
121 | 125 | List<Article> articles = articleRepository.findById(id).stream().toList();
|
122 | 126 | if(articles.isEmpty()){
|
123 | 127 | genericResponse.setFailed(HttpStatus.NOT_FOUND, "Article not found");
|
124 |
| - return genericResponse; |
| 128 | + |
125 | 129 | }
|
126 | 130 | articleRepository.deleteById(id);
|
127 | 131 |
|
128 | 132 | genericResponse.setSuccessMsg("Article Deleted Successfully");
|
| 133 | + log.info("{}", genericResponse.getMessage()); |
129 | 134 | }catch(Exception e){
|
130 |
| - genericResponse.setFailed(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 135 | + genericResponse.setFailed(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 136 | + log.info("{}", genericResponse.getError()); |
131 | 137 | }
|
132 | 138 |
|
133 |
| - return genericResponse; |
| 139 | + |
134 | 140 | }
|
135 | 141 |
|
136 | 142 |
|
|
0 commit comments