-
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 #27 from dinhphu28/dev
Dev
- Loading branch information
Showing
30 changed files
with
1,150 additions
and
84 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
102 changes: 102 additions & 0 deletions
102
...owsharing/src/main/java/com/ndp/knowsharing/Controllers/LeaderBoardArticleController.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,102 @@ | ||
package com.ndp.knowsharing.Controllers; | ||
|
||
import java.time.LocalDateTime; | ||
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.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.ndp.knowsharing.Entities.Article; | ||
import com.ndp.knowsharing.Entities.ArticleForHome; | ||
import com.ndp.knowsharing.Models.ArticleForHome.ArticleForHomeReturnModel; | ||
import com.ndp.knowsharing.Models.ArticleForHome.ArticleForHomeUpdateModel; | ||
import com.ndp.knowsharing.Services.ArticleForHomeService; | ||
import com.ndp.knowsharing.Services.ArticleService; | ||
|
||
@RestController | ||
@CrossOrigin("*") | ||
@RequestMapping("/api/v1/leader-board-articles") | ||
public class LeaderBoardArticleController { | ||
private final String TYPE = "leader-board"; | ||
|
||
@Autowired | ||
private ArticleForHomeService articleForHomeService; | ||
|
||
@Autowired | ||
private ArticleService articleService; | ||
|
||
@GetMapping( | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> retrieveAll() { | ||
ResponseEntity<Object> entity; | ||
|
||
List<ArticleForHomeReturnModel> articleForHomeReturnModels = new ArrayList<ArticleForHomeReturnModel>(); | ||
|
||
List<ArticleForHome> nominatedArticles = articleForHomeService.retrieveByType(TYPE); | ||
|
||
for (ArticleForHome articleForHome : nominatedArticles) { | ||
Article tmpArticle = articleService.retrieveOne(articleForHome.getArticleId()); | ||
|
||
if(tmpArticle != null) { | ||
if(tmpArticle.getHidden() == 0) { | ||
ArticleForHomeReturnModel articleForHomeReturnModel = new ArticleForHomeReturnModel(articleForHome.getId(), articleForHome.getDateCreated(), articleForHome.getDateModified(), articleForHome.getType(), tmpArticle.getId(), tmpArticle.getDateCreated(), tmpArticle.getTitle(), tmpArticle.getContent(), tmpArticle.getDescription(), tmpArticle.getAuthor(), tmpArticle.getUrl(), tmpArticle.getCategory(), tmpArticle.getThumbnailUrl(), tmpArticle.getHidden()); | ||
|
||
articleForHomeReturnModels.add(articleForHomeReturnModel); | ||
} | ||
} | ||
} | ||
|
||
entity = new ResponseEntity<>(articleForHomeReturnModels, HttpStatus.OK); | ||
|
||
return entity; | ||
} | ||
|
||
@PutMapping( | ||
value = "/{id}", | ||
produces = MediaType.APPLICATION_JSON_VALUE, | ||
consumes = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> updateById(@PathVariable("id") String id, @RequestBody ArticleForHomeUpdateModel articleForHomeUpdateModel) { | ||
ResponseEntity<Object> entity; | ||
|
||
if(articleForHomeUpdateModel.getArticleId().isBlank()) { | ||
entity = new ResponseEntity<>("{ \"Notice\": \"Failed\" }", HttpStatus.BAD_REQUEST); | ||
} else { | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
ArticleForHome articleForHome = new ArticleForHome(id, articleForHomeUpdateModel.getArticleId(), now, now, TYPE); | ||
|
||
ArticleForHome tmpSaved = articleForHomeService.saveOne(articleForHome); | ||
|
||
entity = new ResponseEntity<>(tmpSaved, HttpStatus.OK); | ||
} | ||
|
||
return entity; | ||
} | ||
|
||
@DeleteMapping( | ||
value = "/{id}", | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> deleteById(@PathVariable("id") String id) { | ||
ResponseEntity<Object> entity; | ||
|
||
Boolean isSuccess = articleForHomeService.deleteById(id); | ||
|
||
entity = new ResponseEntity<>("{ \"isSuccess\": " + isSuccess + " }", HttpStatus.OK); | ||
|
||
return entity; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...knowsharing/src/main/java/com/ndp/knowsharing/Controllers/NominatedArticleController.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,102 @@ | ||
package com.ndp.knowsharing.Controllers; | ||
|
||
import java.time.LocalDateTime; | ||
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.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.ndp.knowsharing.Entities.Article; | ||
import com.ndp.knowsharing.Entities.ArticleForHome; | ||
import com.ndp.knowsharing.Models.ArticleForHome.ArticleForHomeReturnModel; | ||
import com.ndp.knowsharing.Models.ArticleForHome.ArticleForHomeUpdateModel; | ||
import com.ndp.knowsharing.Services.ArticleForHomeService; | ||
import com.ndp.knowsharing.Services.ArticleService; | ||
|
||
@RestController | ||
@CrossOrigin("*") | ||
@RequestMapping("/api/v1/nominated-articles") | ||
public class NominatedArticleController { | ||
private final String TYPE = "nomination"; | ||
|
||
@Autowired | ||
private ArticleForHomeService articleForHomeService; | ||
|
||
@Autowired | ||
private ArticleService articleService; | ||
|
||
@GetMapping( | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> retrieveAll() { | ||
ResponseEntity<Object> entity; | ||
|
||
List<ArticleForHomeReturnModel> articleForHomeReturnModels = new ArrayList<ArticleForHomeReturnModel>(); | ||
|
||
List<ArticleForHome> nominatedArticles = articleForHomeService.retrieveByType(TYPE); | ||
|
||
for (ArticleForHome articleForHome : nominatedArticles) { | ||
Article tmpArticle = articleService.retrieveOne(articleForHome.getArticleId()); | ||
|
||
if(tmpArticle != null) { | ||
if(tmpArticle.getHidden() == 0) { | ||
ArticleForHomeReturnModel articleForHomeReturnModel = new ArticleForHomeReturnModel(articleForHome.getId(), articleForHome.getDateCreated(), articleForHome.getDateModified(), articleForHome.getType(), tmpArticle.getId(), tmpArticle.getDateCreated(), tmpArticle.getTitle(), tmpArticle.getContent(), tmpArticle.getDescription(), tmpArticle.getAuthor(), tmpArticle.getUrl(), tmpArticle.getCategory(), tmpArticle.getThumbnailUrl(), tmpArticle.getHidden()); | ||
|
||
articleForHomeReturnModels.add(articleForHomeReturnModel); | ||
} | ||
} | ||
} | ||
|
||
entity = new ResponseEntity<>(articleForHomeReturnModels, HttpStatus.OK); | ||
|
||
return entity; | ||
} | ||
|
||
@PutMapping( | ||
value = "/{id}", | ||
produces = MediaType.APPLICATION_JSON_VALUE, | ||
consumes = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> updateById(@PathVariable("id") String id, @RequestBody ArticleForHomeUpdateModel articleForHomeUpdateModel) { | ||
ResponseEntity<Object> entity; | ||
|
||
if(articleForHomeUpdateModel.getArticleId().isBlank()) { | ||
entity = new ResponseEntity<>("{ \"Notice\": \"Failed\" }", HttpStatus.BAD_REQUEST); | ||
} else { | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
ArticleForHome articleForHome = new ArticleForHome(id, articleForHomeUpdateModel.getArticleId(), now, now, TYPE); | ||
|
||
ArticleForHome tmpSaved = articleForHomeService.saveOne(articleForHome); | ||
|
||
entity = new ResponseEntity<>(tmpSaved, HttpStatus.OK); | ||
} | ||
|
||
return entity; | ||
} | ||
|
||
@DeleteMapping( | ||
value = "/{id}", | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<Object> deleteById(@PathVariable("id") String id) { | ||
ResponseEntity<Object> entity; | ||
|
||
Boolean isSuccess = articleForHomeService.deleteById(id); | ||
|
||
entity = new ResponseEntity<>("{ \"isSuccess\": " + isSuccess + " }", HttpStatus.OK); | ||
|
||
return entity; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
back-end/knowsharing/src/main/java/com/ndp/knowsharing/Entities/ArticleForHome.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,42 @@ | ||
package com.ndp.knowsharing.Entities; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Table(name = "app_fd_articles_for_home") | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ArticleForHome { | ||
@Id | ||
// @GeneratedValue(generator = "UUID") | ||
// @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") | ||
@Column(name = "id") | ||
private String id; | ||
|
||
@Column(name = "c_article_id") | ||
private String articleId; | ||
|
||
@Column(name = "datecreated") | ||
private LocalDateTime dateCreated; | ||
|
||
@Column(name = "datemodified") | ||
private LocalDateTime dateModified; | ||
|
||
@Column(name = "c_type") | ||
private String type; | ||
} |
43 changes: 43 additions & 0 deletions
43
...ng/src/main/java/com/ndp/knowsharing/Models/ArticleForHome/ArticleForHomeReturnModel.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,43 @@ | ||
package com.ndp.knowsharing.Models.ArticleForHome; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ArticleForHomeReturnModel { | ||
|
||
private String id; | ||
|
||
private LocalDateTime dateCreated; | ||
|
||
private LocalDateTime dateModified; | ||
|
||
private String type; | ||
|
||
private String articleId; | ||
|
||
private LocalDateTime dateCreatedArticle; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
private String description; | ||
|
||
private String author; | ||
|
||
private String url; | ||
|
||
private String category; | ||
|
||
private String thumbnailUrl; | ||
|
||
private Integer hidden; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ng/src/main/java/com/ndp/knowsharing/Models/ArticleForHome/ArticleForHomeUpdateModel.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.ArticleForHome; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ArticleForHomeUpdateModel { | ||
private String articleId; | ||
} |
14 changes: 14 additions & 0 deletions
14
back-end/knowsharing/src/main/java/com/ndp/knowsharing/Repositories/ArticleForHomeRepo.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.Repositories; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.ndp.knowsharing.Entities.ArticleForHome; | ||
|
||
@Repository | ||
public interface ArticleForHomeRepo extends JpaRepository<ArticleForHome, String> { | ||
|
||
List<ArticleForHome> findByType(String type); | ||
} |
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.