-
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.
* 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
Showing
16 changed files
with
180 additions
and
0 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
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() | ||
} | ||
} |
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,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") | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
save-backend/src/main/kotlin/org/cqfn/save/backend/SaveApplication.kt
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,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) | ||
} |
34 changes: 34 additions & 0 deletions
34
save-backend/src/main/kotlin/org/cqfn/save/backend/controllers/DownloadFilesController.kt
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,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")) | ||
} | ||
} |
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 @@ | ||
server.port = 5000 |
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,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> |
41 changes: 41 additions & 0 deletions
41
save-backend/src/test/kotlin/org/cqfn/save/backend/DownloadFilesTest.kt
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,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.
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,7 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
} | ||
|
||
kotlin { | ||
jvm() | ||
} |
Empty file.
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,3 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} |
Empty file.
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,3 @@ | ||
plugins { | ||
// kotlin("js") | ||
} |
Empty file.
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,3 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} |
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,7 @@ | ||
rootProject.name = "save" | ||
|
||
include("save-backend") | ||
include("save-core") | ||
include("save-frontend") | ||
include("save-plugins") | ||
include("save-common") |