Skip to content

Commit

Permalink
Feature. Backend flux service (#3)
Browse files Browse the repository at this point in the history
* feature/backend-flux-service

### What's done:
  * Flux controllers
  * Added: actuator, security and liquibase
  * Added build.gradle.kts to all modules
  * Added logback and it's configuration
  • Loading branch information
aktsay6 authored Feb 3, 2021
1 parent 8c3d521 commit fc3c508
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
kotlin("jvm") version "1.4.21" apply false
}

allprojects {
repositories {
jcenter()
mavenCentral()
}
}
33 changes: 33 additions & 0 deletions save-backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

val kotlinVersion = "1.4.21"
val springBootVersion = "2.4.2"
val springSecurityVersion = "5.4.2"
val hibernateVersion = "5.4.2.Final"
val liquibaseVersion = "4.2.2"
val slf4jVersion = "1.7.30"
val logbackVersion = "1.2.3"
val compileKotlin: KotlinCompile by tasks

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}

kotlin {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")
implementation("org.springframework.boot:spring-boot-starter-actuator:$springBootVersion")
implementation("org.springframework.security:spring-security-core:$springSecurityVersion")
implementation("org.liquibase:liquibase-core:$liquibaseVersion")
implementation("org.hibernate:hibernate-core:$hibernateVersion")
implementation("org.slf4j:slf4j-api:$slf4jVersion")
implementation("ch.qos.logback:logback-core:$logbackVersion")
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.cqfn.save.backend

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.web.reactive.config.EnableWebFlux

@SpringBootApplication
@EnableWebFlux
open class SaveApplication

fun main(args: Array<String>) {
SpringApplication.run(SaveApplication::class.java, *args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cqfn.save.backend.controllers

import org.slf4j.LoggerFactory
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.http.codec.multipart.FilePart
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono
import java.io.File

@RestController
class DownloadFilesController {
private val logger = LoggerFactory.getLogger("org.cqfn.save.logback")

@GetMapping(value = ["/download"], produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE])
fun download(): Mono<ByteArray> {
return Mono.fromCallable {
val file = File("test.txt")
file.createNewFile()
file.bufferedWriter().use {
it.write("qweqwe")
}
file.readBytes()
}
}

@PostMapping(value = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
fun upload(@RequestPart("file") file: Mono<FilePart>): Mono<ResponseEntity<String>> {
return Mono.just(ResponseEntity.ok().body("test"))
}
}
1 change: 1 addition & 0 deletions save-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server.port = 5000
25 changes: 25 additions & 0 deletions save-backend/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<property name="LOG_DIR" value="logs/application"/>
<property name="LOG_FILE" value="LogFile"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/${LOG_FILE}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/%d{yyyy-MM-dd}/${LOG_FILE}.gz</fileNamePattern>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.cqfn.save.logback" />
<logger name="org.cqfn.save.logback.tests" />
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.cqfn.save.backend

import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
import org.springframework.core.io.ByteArrayResource
import org.springframework.http.client.MultipartBodyBuilder
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.reactive.function.BodyInserters
import kotlin.io.path.ExperimentalPathApi

@WebFluxTest
class DownloadFilesTest {

@Autowired
lateinit var webClient: WebTestClient

@Test
fun checkDownload() {
webClient.get().uri("/download").exchange().expectStatus().isOk
webClient.get().uri("/download").exchange().expectBody(String::class.java).isEqualTo<Nothing>("qweqwe")
}

@Test
@ExperimentalPathApi
fun checkUpload() {
val tmpFile = kotlin.io.path.createTempFile("test", "txt")

val body = MultipartBodyBuilder().apply {
part("file", object : ByteArrayResource("testString".toByteArray()) {
override fun getFilename(): String? {
return tmpFile.fileName.toString()
}
})
}.build()

webClient.post().uri("/upload").body(BodyInserters.fromMultipartData(body)).exchange().expectStatus().isOk

webClient.post().uri("/upload").body(BodyInserters.fromMultipartData(body)).exchange().expectBody(String::class.java).isEqualTo<Nothing>("test")
}
}
Empty file added save-common/README.md
Empty file.
7 changes: 7 additions & 0 deletions save-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("multiplatform")
}

kotlin {
jvm()
}
Empty file added save-core/README.md
Empty file.
3 changes: 3 additions & 0 deletions save-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm")
}
Empty file added save-frontend/README.md
Empty file.
3 changes: 3 additions & 0 deletions save-frontend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
// kotlin("js")
}
Empty file added save-plugins/README.md
Empty file.
3 changes: 3 additions & 0 deletions save-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm")
}
7 changes: 7 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "save"

include("save-backend")
include("save-core")
include("save-frontend")
include("save-plugins")
include("save-common")

0 comments on commit fc3c508

Please sign in to comment.