diff options
| author | terminaldweller <thabogre@gmail.com> | 2022-03-17 15:37:17 +0000 | 
|---|---|---|
| committer | terminaldweller <thabogre@gmail.com> | 2022-03-17 15:37:17 +0000 | 
| commit | 70aa3558759921f7ec44adffec081ba1e9d7fb6a (patch) | |
| tree | eef7dd6dee34d26ac10f64076cd9f7df25d77f88 | |
| parent | daily commit.wip (diff) | |
| download | mdrtl-70aa3558759921f7ec44adffec081ba1e9d7fb6a.tar.gz mdrtl-70aa3558759921f7ec44adffec081ba1e9d7fb6a.zip | |
daily commit.wip
Diffstat (limited to '')
| -rw-r--r-- | build.gradle.kts | 58 | ||||
| -rw-r--r-- | settings.gradle.kts | 3 | ||||
| -rw-r--r-- | src/main/java/com/terminaldweller/doc/DocConfig.java | 20 | ||||
| -rw-r--r-- | src/main/java/com/terminaldweller/doc/DocController.java | 17 | ||||
| -rw-r--r-- | src/main/java/com/terminaldweller/doc/DocRepository.java | 13 | ||||
| -rw-r--r-- | src/main/java/com/terminaldweller/doc/DocService.java | 38 | ||||
| -rw-r--r-- | src/main/resources/application.properties | 2 | 
7 files changed, 133 insertions, 18 deletions
| diff --git a/build.gradle.kts b/build.gradle.kts index 30630b9..3712725 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,10 @@  // https://docs.gradle.org/current/userguide/building_java_projects.html  plugins {    `java-library` -  // application    id("org.springframework.boot") version "2.6.4"    id("io.spring.dependency-management") version "1.0.11.RELEASE"    id("java-library") +  // id("com.sourcegraph.gradle") version "1.3"  }  repositories { @@ -12,31 +12,57 @@ repositories {  }  dependencies { -  implementation("org.springframework.boot:spring-boot-starter-data-jdbc") -  implementation("org.springframework.boot:spring-boot-starter-data-jpa") -  implementation("org.springframework.boot:spring-boot-starter-web") +  implementation("org.springframework.boot:spring-boot-starter-data-jdbc:2.6.4") +  implementation("org.springframework.boot:spring-boot-starter-data-jdbc:2.6.4:sources") +  api("org.springframework.boot:spring-boot-starter-data-jdbc:2.6.4:javadoc") +  implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.6.4") +  implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.6.4:sources") +  api("org.springframework.boot:spring-boot-starter-data-jpa:2.6.4:javadoc") +  implementation("org.springframework.boot:spring-boot-starter-web:2.6.4") +  implementation("org.springframework.boot:spring-boot-starter-web:2.6.4:sources") +  api("org.springframework.boot:spring-boot-starter-web:2.6.4:javadoc") +  implementation("org.commonmark:commonmark:0.18.2") +  implementation("org.commonmark:commonmark:0.18.2:sources") +  implementation("org.commonmark:commonmark:0.18.2:javadoc") +  implementation("org.commonmark:commonmark-ext-gfm-tables:0.18.2") +  implementation("org.commonmark:commonmark-ext-gfm-strikethrough:0.18.2") +  implementation("org.commonmark:commonmark-ext-task-list-items:0.18.2") +  implementation("org.commonmark:commonmark-ext-ins:0.18.2")    runtimeOnly("org.postgresql:postgresql")    testImplementation("org.hibernate.javax.persistence:hibernate-jpa-2.1-api")  } -// tasks.create("FatJar", Jar::class) { -//   description = "makes a fatjar" -//   group = "build" -//   manifest.attributes["Main-Class"] = "com.terminaldweller.MainApplication" -//   duplicatesStrategy = DuplicatesStrategy.EXCLUDE -//   val dependencies = configurations.runtimeClasspath.get().map(::zipTree) -//   from(dependencies) -//   with(tasks.jar.get()) +// task copyJavadocsAndSources { +//     inputs.files configurations.runtime +//     outputs.dir "${buildDir}/download" +//     doLast { +//         def componentIds = configurations.runtime.incoming.resolutionResult.allDependencies.collect { it.selected.id } +//         ArtifactResolutionResult result = dependencies.createArtifactResolutionQuery() +//             .forComponents(componentIds) +//             .withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact) +//             .execute() +//         def sourceArtifacts = [] +//         result.resolvedComponents.each { ComponentArtifactsResult component -> +//             Set<ArtifactResult> sources = component.getArtifacts(SourcesArtifact) +//             println "Found ${sources.size()} sources for ${component.id}" +//             sources.each { ArtifactResult ar -> +//                 if (ar instanceof ResolvedArtifactResult) { +//                     sourceArtifacts << ar.file +//                 } +//             } +//         } + +//         copy {             +//             from sourceArtifacts +//             into "${buildDir}/download" +//         } +//     }  // }  springBoot {    mainClass.set("com.terminaldweller.MainApplication")  } -// application { -//   mainClass.set("com.terminaldweller.MainApplication") -// } -  sourceSets {    main {      java { diff --git a/settings.gradle.kts b/settings.gradle.kts index d5ae214..6fdeedf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,5 @@   * This project uses @Incubating APIs which are subject to change.   */ -rootProject.name = "src" +rootProject.name = "rtlmd" +include("app") diff --git a/src/main/java/com/terminaldweller/doc/DocConfig.java b/src/main/java/com/terminaldweller/doc/DocConfig.java new file mode 100644 index 0000000..1826817 --- /dev/null +++ b/src/main/java/com/terminaldweller/doc/DocConfig.java @@ -0,0 +1,20 @@ +package com.terminaldweller.doc; + +import java.util.List; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** The config class. */ +@Configuration +public class DocConfig { +  @Bean +  CommandLineRunner commandLineRunner(DocRepository repository) { +    return args -> { +      Doc mydoc1 = new Doc("mydoc1", 0L); +      Doc mydoc2 = new Doc("mydoc2", 0L); + +      repository.saveAll(List.of(mydoc1, mydoc2)); +    }; +  } +} diff --git a/src/main/java/com/terminaldweller/doc/DocController.java b/src/main/java/com/terminaldweller/doc/DocController.java index 564f37c..a91fb0d 100644 --- a/src/main/java/com/terminaldweller/doc/DocController.java +++ b/src/main/java/com/terminaldweller/doc/DocController.java @@ -2,8 +2,14 @@ package com.terminaldweller.doc;  import java.util.List;  import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody;  import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus;  import org.springframework.web.bind.annotation.RestController;  /** The document controller class. */ @@ -21,4 +27,15 @@ public class DocController {    public List<Doc> getDocs() {      return docService.getDocs();    } + +  @PostMapping +  @ResponseStatus(HttpStatus.CREATED) +  public void postDocs(@RequestBody Doc doc) { +    docService.addNewDoc(doc); +  } + +  @DeleteMapping(path = "{Id}") +  public void deleteDocs(@PathVariable("Id") Long id) { +    docService.deleteDoc(id); +  }  } diff --git a/src/main/java/com/terminaldweller/doc/DocRepository.java b/src/main/java/com/terminaldweller/doc/DocRepository.java new file mode 100644 index 0000000..387835e --- /dev/null +++ b/src/main/java/com/terminaldweller/doc/DocRepository.java @@ -0,0 +1,13 @@ +package com.terminaldweller.doc; + +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +/** The interface of the doc class for the data store. */ +@Repository +public interface DocRepository extends JpaRepository<Doc, Long> { +  @Query("SELECT d FROM Doc d WHERE d.name = ?1") +  Optional<Doc> findDocByName(String name); +} diff --git a/src/main/java/com/terminaldweller/doc/DocService.java b/src/main/java/com/terminaldweller/doc/DocService.java index 4aee30b..90fd9df 100644 --- a/src/main/java/com/terminaldweller/doc/DocService.java +++ b/src/main/java/com/terminaldweller/doc/DocService.java @@ -1,12 +1,48 @@  package com.terminaldweller.doc;  import java.util.List; +import java.util.Optional; +import org.springframework.beans.factory.annotation.Autowired;  import org.springframework.stereotype.Service;  /** The document service class. */  @Service  public class DocService { +  private final DocRepository docRepository; + +  @Autowired +  public DocService(DocRepository docRepository) { +    this.docRepository = docRepository; +  } +    public List<Doc> getDocs() { -    return List.of(new Doc(1L, "loco", 0L)); +    return docRepository.findAll(); +    // return List.of(new Doc(1L, "loco", 0L)); +  } + +  /** +   * Adds a new Document to the data store. +   * +   * @param doc the new Document to add. +   */ +  public void addNewDoc(Doc doc) { +    Optional<Doc> docOptional = docRepository.findDocByName(doc.getName()); +    if (docOptional.isPresent()) { +      throw new IllegalStateException("Id is already taken"); +    } +    docRepository.save(doc); +  } + +  /** +   * Deletes a document from the data store. +   * +   * @param id The identifier for the document to be deleted. +   */ +  public void deleteDoc(Long id) { +    boolean exists = docRepository.existsById(id); +    if (!exists) { +      throw new IllegalStateException("doc " + id + " does not exitst"); +    } +    docRepository.deleteById(id);    }  } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e0578c9..357f85a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,3 +5,5 @@ spring.jpa.hibernate.ddl-auto=create-drop  spring.jpa.show-sql=true  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect  spring.jpa.properties.hibernate.format_sql=true + +server.error.include-message=always | 
