parent
0c3d7ebb32
commit
c3d9c2b976
@ -1,12 +1,12 @@
|
|||||||
package SAE.ApiREST.Client;
|
package SAE.ApiREST.Client;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ClientApplication {
|
public class ClientApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ClientApplication.class, args);
|
@SuppressWarnings("unused")
|
||||||
|
TestArticle testArticle = new TestArticle();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package SAE.ApiREST.Client;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import SAE.ApiREST.Client.model.Article;
|
||||||
|
|
||||||
|
public class TestArticle {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ClientApplication.class);
|
||||||
|
private String baseURI = "http://localhost:8080/ArticleWebService";
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public TestArticle() {
|
||||||
|
testPost();
|
||||||
|
|
||||||
|
// testGetAllArticles();
|
||||||
|
testGetArticleById();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testPost() {
|
||||||
|
Article result = new Article();
|
||||||
|
|
||||||
|
Article article = new Article(
|
||||||
|
"title",
|
||||||
|
"url",
|
||||||
|
LocalDate.parse("10-06-2023", DateTimeFormatter.ofPattern("dd-MM-yyyy")),
|
||||||
|
LocalDate.parse("09-06-2023", DateTimeFormatter.ofPattern("dd-MM-yyyy")),
|
||||||
|
true,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
result = restTemplate.getForObject(
|
||||||
|
baseURI + "/getArticleById/1",
|
||||||
|
Article.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info(result.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void testGetAllArticles() {
|
||||||
|
ArrayList<Article> results = new ArrayList<>();
|
||||||
|
|
||||||
|
results = restTemplate.getForObject(
|
||||||
|
baseURI + "/getAllArticle",
|
||||||
|
ArrayList.class
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println(results.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGetArticleById() {
|
||||||
|
Article result = new Article();
|
||||||
|
|
||||||
|
result = restTemplate.getForObject(
|
||||||
|
baseURI + "/getArticleById/1",
|
||||||
|
Article.class
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info(result.toString());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
package SAE.ApiREST.Client.model;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Article {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
Integer id;
|
||||||
|
String title;
|
||||||
|
String url;
|
||||||
|
LocalDate dateAdded;
|
||||||
|
LocalDate datePublished;
|
||||||
|
Boolean visible;
|
||||||
|
Integer type;
|
||||||
|
// ArrayList<Keyword> keywords = new ArrayList<>();
|
||||||
|
|
||||||
|
public Article() {}
|
||||||
|
|
||||||
|
public Article(String title, String url, LocalDate dateAdded, LocalDate datePublished, Boolean visibility, Integer type) {
|
||||||
|
this.id = 1;
|
||||||
|
this.title = title;
|
||||||
|
this.url = url;
|
||||||
|
this.dateAdded = dateAdded;
|
||||||
|
this.datePublished = datePublished;
|
||||||
|
this.visible = visibility;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return this.title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return this.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getDateAdded() {
|
||||||
|
return this.dateAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateAdded(String dateAdded) {
|
||||||
|
this.dateAdded = LocalDate.parse(dateAdded, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getDatePublished() {
|
||||||
|
return this.datePublished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatePublished(String datePublished) {
|
||||||
|
this.datePublished = LocalDate.parse(datePublished, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getVisible() {
|
||||||
|
return this.visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibility(Boolean visible) {
|
||||||
|
this.visible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public List<Keyword> getKeywords() {
|
||||||
|
return this.keywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeywords(List<Keyword> keywords) {
|
||||||
|
this.keywords = keywords;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
|
||||||
|
message.append(String.format("title = %s\n", title));
|
||||||
|
message.append(String.format("url = %s\n", url));
|
||||||
|
message.append(String.format("dateAdded = %s\n", dateAdded));
|
||||||
|
message.append(String.format("datePublished = %s\n", datePublished));
|
||||||
|
message.append(String.format("visible = %s\n", visible));
|
||||||
|
message.append(String.format("type = %s\n", type));
|
||||||
|
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package SAE.ApiREST.Client.model;
|
||||||
|
|
||||||
|
public class Response {
|
||||||
|
|
||||||
|
Integer id;
|
||||||
|
String statusMessage;
|
||||||
|
|
||||||
|
public Response() {}
|
||||||
|
|
||||||
|
public Response(Integer id, String statusMessage) {
|
||||||
|
this.id = id;
|
||||||
|
this.statusMessage = statusMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusMessage() {
|
||||||
|
return this.statusMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusMessage(String statusMessage) {
|
||||||
|
this.statusMessage = statusMessage;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue