Browse Source

Shared libraries

dagarcos 2 years ago
parent
commit
25cecc2fe7

+ 17 - 0
.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>DBCDS_S10_1</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>

+ 3 - 3
DBCDS_S10_1_Api/pom.xml

@@ -29,9 +29,9 @@
 			<optional>true</optional>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
+			<groupId>es.uv.garcosda.shared</groupId>
+		    <artifactId>DBCDS_S10_1_Shared</artifactId>
+		    <version>0.0.1-SNAPSHOT</version>
 		</dependency>
 	</dependencies>
 

+ 24 - 0
DBCDS_S10_1_Api/src/main/java/es/uv/garcosda/api/controllers/NewsController.java

@@ -0,0 +1,24 @@
+package es.uv.garcosda.api.controllers;
+
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import es.uv.garcosda.shared.Document;
+
+@RestController
+@RequestMapping("/api/v1/news")
+@CrossOrigin
+public class NewsController {
+	
+
+	
+	@GetMapping("{id}")
+    public Document getOne(@PathVariable("id") Integer id) {
+		Document d = new Document();
+		return d;
+    }
+	
+}

+ 1 - 1
DBCDS_S10_1_Api/src/main/resources/application.properties

@@ -1 +1 @@
-
+server.port=8080

+ 0 - 13
DBCDS_S10_1_Api/src/test/java/es/uv/garcosda/api/DbcdsS101ApiApplicationTests.java

@@ -1,13 +0,0 @@
-package es.uv.garcosda.api;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class DbcdsS101ApiApplicationTests {
-
-	@Test
-	void contextLoads() {
-	}
-
-}

+ 4 - 5
DBCDS_S10_1_Repository/pom.xml

@@ -29,15 +29,14 @@
 			<optional>true</optional>
 		</dependency>
 		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-data-jpa</artifactId>
+		</dependency>
+		<dependency>
 			<groupId>com.h2database</groupId>
 			<artifactId>h2</artifactId>
 			<scope>runtime</scope>
 		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
-		</dependency>
 	</dependencies>
 
 	<build>

+ 34 - 0
DBCDS_S10_1_Repository/src/main/java/es/uv/garcosda/repository/News.java

@@ -0,0 +1,34 @@
+package es.uv.garcosda.repository;
+
+import java.util.Optional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+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.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import es.uv.garcosda.repository.domain.Document;
+import es.uv.garcosda.repository.repos.NewsRepository;
+
+@RestController
+@RequestMapping("/api/v1/news")
+@CrossOrigin
+public class News {
+
+	@Autowired
+	NewsRepository nr;
+	
+	@GetMapping("{id}")
+    public ResponseEntity<?> getOne(@PathVariable("id") Integer id) {
+		Optional<Document> op = nr.findById(id);
+		if(op.isEmpty()) {
+			return new ResponseEntity<String>("ID not found", HttpStatus.NOT_FOUND);
+		}
+		return new ResponseEntity<Document>(op.get(), HttpStatus.OK);
+    }
+	
+}

+ 108 - 0
DBCDS_S10_1_Repository/src/main/java/es/uv/garcosda/repository/domain/Document.java

@@ -0,0 +1,108 @@
+package es.uv.garcosda.repository.domain;
+
+
+import org.springframework.data.annotation.Id;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Document {
+	
+	@Id
+	@JsonProperty("id")
+	private Integer id;
+	
+	@JsonProperty("title")
+	private String title;
+	
+	@JsonProperty("publisher")
+	private String publisher;
+	
+	@JsonProperty("author")
+	private String author;
+	
+	@JsonProperty("date_add")
+	private String date_add;
+	
+	@JsonProperty("content")
+	private String content;
+	
+	public Document() {}
+	
+	public Document(Integer id, String title, String publisher, String author, String date_add, String content) {
+		this.id = id;
+		this.title = title;
+		this.publisher = publisher;
+		this.author = author;
+		this.date_add = date_add;
+		this.content = content;
+	}
+	
+	public Document(String title, String publisher, String author, String date_add, String content) {
+		this.title = title;
+		this.publisher = publisher;
+		this.author = author;
+		this.date_add = date_add;
+		this.content = content;
+	}
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public String getPublisher() {
+		return publisher;
+	}
+
+	public void setPublisher(String publisher) {
+		this.publisher = publisher;
+	}
+
+	public String getAuthor() {
+		return author;
+	}
+
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+
+	public String getDateAdd() {
+		return date_add;
+	}
+
+	public void setDateAdd(String date_add) {
+		this.date_add = date_add;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+	
+	public String toString() {
+		ObjectMapper objectMapper = new ObjectMapper();
+		try {
+			return objectMapper.writeValueAsString(this);
+		} catch (JsonProcessingException e) {
+			e.printStackTrace();
+			return "";
+		}
+	}
+	
+}

+ 16 - 0
DBCDS_S10_1_Repository/src/main/java/es/uv/garcosda/repository/repos/NewsRepository.java

@@ -0,0 +1,16 @@
+package es.uv.garcosda.repository.repos;
+
+
+import java.util.List;
+
+import org.springframework.data.repository.CrudRepository;
+
+import es.uv.garcosda.repository.domain.Document;
+
+
+public interface NewsRepository extends CrudRepository<Document, Integer>{
+
+	public List<Document> findByAuthor(String author);
+	public List<Document> findByPublisher(String publisher);
+	
+}

+ 1 - 1
DBCDS_S10_1_Repository/src/main/resources/application.properties

@@ -1 +1 @@
-
+server.port=8081

+ 0 - 13
DBCDS_S10_1_Repository/src/test/java/es/uv/garcosda/repository/DbcdsS101RepositoryApplicationTests.java

@@ -1,13 +0,0 @@
-package es.uv.garcosda.repository;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class DbcdsS101RepositoryApplicationTests {
-
-	@Test
-	void contextLoads() {
-	}
-
-}

+ 55 - 0
DBCDS_S10_1_Shared/.classpath

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="test" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="test" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="target/generated-sources/annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+			<attribute name="test" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 1 - 0
DBCDS_S10_1_Shared/.gitignore

@@ -0,0 +1 @@
+/target/

+ 28 - 0
DBCDS_S10_1_Shared/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>DBCDS_S10_1_Shared</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>

+ 2 - 0
DBCDS_S10_1_Shared/.settings/org.eclipse.jdt.apt.core.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.apt.aptEnabled=false

+ 9 - 0
DBCDS_S10_1_Shared/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,9 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
+org.eclipse.jdt.core.compiler.processAnnotations=disabled
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.5

+ 4 - 0
DBCDS_S10_1_Shared/.settings/org.eclipse.m2e.core.prefs

@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

+ 2 - 0
DBCDS_S10_1_Shared/.settings/org.springframework.ide.eclipse.prefs

@@ -0,0 +1,2 @@
+boot.validation.initialized=true
+eclipse.preferences.version=1

+ 23 - 0
DBCDS_S10_1_Shared/pom.xml

@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>3.0.5</version>
+		<relativePath/> <!-- lookup parent from repository -->
+  </parent>
+  <groupId>es.uv.garcosda.shared</groupId>
+  <artifactId>DBCDS_S10_1_Shared</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <name>DBCDS_S10_1_Shared</name>
+  <description>DBCDS_S10_1_Shared</description>
+  <properties>
+		<java.version>17</java.version>
+  </properties>
+  <dependencies>
+  	<dependency>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-web</artifactId>
+	</dependency>
+  </dependencies>
+</project>

+ 104 - 0
DBCDS_S10_1_Shared/src/main/java/es/uv/garcosda/shared/Document.java

@@ -0,0 +1,104 @@
+package es.uv.garcosda.shared;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Document {
+	
+	@JsonProperty("id")
+	private Integer id;
+	
+	@JsonProperty("title")
+	private String title;
+	
+	@JsonProperty("publisher")
+	private String publisher;
+	
+	@JsonProperty("author")
+	private String author;
+	
+	@JsonProperty("date_add")
+	private String date_add;
+	
+	@JsonProperty("content")
+	private String content;
+	
+	public Document() {}
+	
+	public Document(Integer id, String title, String publisher, String author, String date_add, String content) {
+		this.id = id;
+		this.title = title;
+		this.publisher = publisher;
+		this.author = author;
+		this.date_add = date_add;
+		this.content = content;
+	}
+	
+	public Document(String title, String publisher, String author, String date_add, String content) {
+		this.title = title;
+		this.publisher = publisher;
+		this.author = author;
+		this.date_add = date_add;
+		this.content = content;
+	}
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public String getPublisher() {
+		return publisher;
+	}
+
+	public void setPublisher(String publisher) {
+		this.publisher = publisher;
+	}
+
+	public String getAuthor() {
+		return author;
+	}
+
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+
+	public String getDateAdd() {
+		return date_add;
+	}
+
+	public void setDateAdd(String date_add) {
+		this.date_add = date_add;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+	
+	public String toString() {
+		ObjectMapper objectMapper = new ObjectMapper();
+		try {
+			return objectMapper.writeValueAsString(this);
+		} catch (JsonProcessingException e) {
+			e.printStackTrace();
+			return "";
+		}
+	}
+	
+}

+ 4 - 3
pom.xml

@@ -7,11 +7,12 @@
   <name>DBCDS_S10_1</name>
   <description>Spring microservices</description>
   <modules>
-      <module>DBCDS_S10_1_data</module>
-      <module>DBCDS_S10_1_api</module>
+      <module>DBCDS_S10_1_Repository</module>
+      <module>DBCDS_S10_1_Api</module>
+      <module>DBCDS_S10_1_Shared</module>
    </modules>
    <properties>
-		<java.version>11</java.version>
+		<java.version>17</java.version>
 	</properties>
    <build>
 		<plugins>