-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from dinhphu28/dev
Dev
- Loading branch information
Showing
26 changed files
with
1,331 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...d/knowsharing/src/main/java/com/ndp/knowsharing/Controllers/HomeNewArticleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.ndp.knowsharing.Controllers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ndp.knowsharing.Entities.Article; | ||
import com.ndp.knowsharing.Entities.Category; | ||
import com.ndp.knowsharing.Models.ArticleForHome.NewlyArticleForHomeReturnModel; | ||
import com.ndp.knowsharing.Services.ArticleService; | ||
import com.ndp.knowsharing.Services.CategoryService; | ||
|
||
@RestController | ||
@CrossOrigin("*") | ||
@RequestMapping("/api/v1/new-articles") | ||
public class HomeNewArticleController { | ||
|
||
@Autowired | ||
private ArticleService articleService; | ||
|
||
@Autowired | ||
private CategoryService categoryService; | ||
|
||
@GetMapping( | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> retrieveAll() { | ||
ResponseEntity<Object> entity; | ||
|
||
List<NewlyArticleForHomeReturnModel> newlyArticleForHomeReturnModels = new ArrayList<NewlyArticleForHomeReturnModel>(); | ||
|
||
List<Article> newestArticles = articleService.retrieveTop5ByHiddenAndNewest(0); | ||
|
||
for (Article article : newestArticles) { | ||
Category category = categoryService.retrieveById(article.getCategory()); | ||
|
||
NewlyArticleForHomeReturnModel tmp = new NewlyArticleForHomeReturnModel(article, category.getName()); | ||
|
||
newlyArticleForHomeReturnModels.add(tmp); | ||
} | ||
|
||
entity = new ResponseEntity<>(newlyArticleForHomeReturnModels, HttpStatus.OK); | ||
|
||
return entity; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...nd/knowsharing/src/main/java/com/ndp/knowsharing/Models/Article/ArticleHideShowModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.ndp.knowsharing.Models.Article; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ArticleHideShowModel { | ||
private Boolean hidden; | ||
} |
86 changes: 86 additions & 0 deletions
86
...c/main/java/com/ndp/knowsharing/Models/ArticleForHome/NewlyArticleForHomeReturnModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.ndp.knowsharing.Models.ArticleForHome; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.ndp.knowsharing.Entities.Article; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NewlyArticleForHomeReturnModel { | ||
private String id; | ||
|
||
private LocalDateTime dateCreated; | ||
|
||
private LocalDateTime dateModified; | ||
|
||
private String createdBy; | ||
|
||
private String createdByName; | ||
|
||
private String modifiedBy; | ||
|
||
private String modifiedByName; | ||
|
||
private String title; | ||
|
||
private String description; | ||
|
||
private String content; | ||
|
||
private String audioContent; | ||
|
||
private String author; | ||
|
||
private String url; | ||
|
||
private String category; | ||
|
||
private String thumbnailUrl; | ||
|
||
private Integer hidden; | ||
|
||
private String categoryName; | ||
|
||
public NewlyArticleForHomeReturnModel(Article article, String categoryName) { | ||
this.id = article.getId(); | ||
|
||
this.dateCreated = article.getDateCreated(); | ||
|
||
this.dateModified = article.getDateModified(); | ||
|
||
this.createdBy = article.getCreatedBy(); | ||
|
||
this.createdByName = article.getCreatedByName(); | ||
|
||
this.modifiedBy = article.getModifiedBy(); | ||
|
||
this.modifiedByName = article.getModifiedByName(); | ||
|
||
this.title = article.getTitle(); | ||
|
||
this.description = article.getDescription(); | ||
|
||
this.content = article.getContent(); | ||
|
||
this.audioContent = article.getAudioContent(); | ||
|
||
this.author = article.getAuthor(); | ||
|
||
this.url = article.getUrl(); | ||
|
||
this.category = article.getCategory(); | ||
|
||
this.thumbnailUrl = article.getThumbnailUrl(); | ||
|
||
this.hidden = article.getHidden(); | ||
|
||
this.categoryName = categoryName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.