Skip to content

Commit 38d9169

Browse files
committed
Changes:
Backend 1. Swagger-ui was added 2. Kotlin-front renamed to front 3. Test message controller was added 4. Custom runtime exception Front: 1. Router was refactored (Home, Message components were added) 2. Message component was added 3. Router links in main App component were added
1 parent 468188f commit 38d9169

34 files changed

+225
-212
lines changed

backend/build.gradle.kts

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ repositories {
1717
}
1818

1919
dependencies {
20-
runtimeOnly(project(":kotlin-front"))
20+
runtimeOnly(project(":front"))
21+
//spring frameworks
22+
runtimeOnly("org.springframework.boot:spring-boot-devtools:2.1.3.RELEASE")
2123
implementation("org.springframework.boot:spring-boot-starter-actuator")
2224
implementation("org.springframework.boot:spring-boot-starter-web")
2325
implementation("org.springframework.boot:spring-boot-starter-mustache")
26+
//kotlin
2427
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
25-
runtimeOnly("org.springframework.boot:spring-boot-devtools:2.1.3.RELEASE")
2628
implementation("org.jetbrains.kotlin:kotlin-reflect")
2729
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
2830
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
31+
//swagger
32+
api("io.springfox:springfox-boot-starter:3.0.0")
33+
api("io.springfox:springfox-swagger-ui:3.0.0")
34+
//open-api gen
2935
testImplementation("org.springframework.boot:spring-boot-starter-test") {
3036
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
3137
}

backend/src/main/kotlin/com/kotapp/exapp/Test.kt

-117
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,8 @@
11
package com.kotapp.exapp.config
22

3-
import org.springframework.boot.web.servlet.FilterRegistrationBean
4-
import org.springframework.context.annotation.Bean
53
import org.springframework.context.annotation.Configuration
6-
import org.springframework.core.Ordered
7-
import org.springframework.web.cors.CorsConfiguration
8-
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
9-
import org.springframework.web.filter.CorsFilter
10-
import org.springframework.web.servlet.config.annotation.CorsRegistry
11-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
12-
import java.util.*
134

145
@Configuration
156
class Configuration {
167

17-
// @Bean
18-
// fun corsFilter(): FilterRegistrationBean<*> {
19-
// val source = UrlBasedCorsConfigurationSource()
20-
// val config = CorsConfiguration()
21-
//
22-
// config.allowedOrigins = Collections.singletonList("http://localhost:8080")
23-
// config.allowedMethods = Collections.singletonList("*")
24-
// config.allowedHeaders = Collections.singletonList("*")
25-
//
26-
// source.registerCorsConfiguration("/path", config)
27-
// val filterRegistrationBean = FilterRegistrationBean(CorsFilter(source))
28-
//
29-
// filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE)
30-
// return filterRegistrationBean
31-
// }
32-
//
33-
// @Bean
34-
// fun corsConfig(): WebMvcConfigurer {
35-
// return object : WebMvcConfigurer {
36-
// override fun addCorsMappings(registry: CorsRegistry) {
37-
// registry.addMapping("/**")
38-
// }
39-
// }
40-
// }
41-
428
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.kotapp.exapp.config
2+
3+
import org.springframework.context.annotation.Bean
4+
import org.springframework.context.annotation.Configuration
5+
import springfox.documentation.builders.PathSelectors
6+
import springfox.documentation.builders.RequestHandlerSelectors
7+
import springfox.documentation.spi.DocumentationType
8+
import springfox.documentation.spring.web.plugins.Docket
9+
import springfox.documentation.swagger2.annotations.EnableSwagger2
10+
11+
@Configuration
12+
@EnableSwagger2
13+
class SpringFoxConfiguration {
14+
15+
@Bean
16+
fun api(): Docket {
17+
return Docket(DocumentationType.SWAGGER_2)
18+
.select()
19+
.apis(RequestHandlerSelectors.any())
20+
.paths(PathSelectors.any())
21+
.build()
22+
}
23+
}

backend/src/main/kotlin/com/kotapp/exapp/controller/MainController.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.*
55
import kotlin.random.Random
66

77
@RestController
8-
@RequestMapping(("/api"))
8+
@RequestMapping("/api")
99
class MainController{
1010

1111
@GetMapping("/greetings")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.kotapp.exapp.controller
2+
3+
import com.kotapp.exapp.exceprions.NotFoundException
4+
import io.swagger.annotations.Api
5+
import org.springframework.web.bind.annotation.*
6+
7+
8+
@RestController
9+
@RequestMapping("/api/message")
10+
@Api(value = "/api/message", description = "controller for the basic operations with messages")
11+
class MessageController {
12+
13+
val listOfMap = mutableListOf(
14+
mutableMapOf("id" to "0", "text" to "m0"),
15+
mutableMapOf("id" to "1", "text" to "m1"),
16+
mutableMapOf("id" to "12", "text" to "m12"),
17+
mutableMapOf("id" to "2", "text" to "m2"))
18+
19+
@GetMapping
20+
fun getAllMessages(): List<Map<String, String>> {
21+
return listOfMap
22+
}
23+
24+
@GetMapping("{id}")
25+
fun getMessage(@PathVariable(value = "id", required = true) id: String): Map<String, String> {
26+
return gerMessageById(id)
27+
}
28+
29+
@PostMapping("/add")
30+
fun addMessage(@RequestBody message: MutableMap<String, String>): Map<String, String> {
31+
listOfMap.add(message)
32+
return message
33+
}
34+
35+
@PutMapping("{id}")
36+
fun updateMessage(@PathVariable id: String,
37+
@RequestBody message: MutableMap<String, String>): Map<String, String> {
38+
val messageFromDB = gerMessageById(id)
39+
messageFromDB.putAll(message)
40+
return messageFromDB
41+
}
42+
43+
@DeleteMapping("{id}")
44+
fun deleteMessage(@PathVariable id: String) {
45+
listOfMap.remove(gerMessageById(id))
46+
}
47+
48+
private fun gerMessageById(id: String) = listOfMap.firstOrNull { id == it["id"] } ?: throw NotFoundException()
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.kotapp.exapp.exceprions
2+
3+
import org.springframework.http.HttpStatus
4+
import org.springframework.web.bind.annotation.ResponseStatus
5+
6+
@ResponseStatus(value = HttpStatus.NOT_FOUND)
7+
class NotFoundException : RuntimeException() {
8+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

kotlin-front/package-lock.json renamed to front/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kotlin-front/package.json renamed to front/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "kotlin-front",
2+
"name": "front",
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
File renamed without changes.
File renamed without changes.

kotlin-front/src/App.vue renamed to front/src/App.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
2-
<div id="App">
3-
<!-- <router-link to="/"></router-link>-->
2+
<div id="nav">
3+
<router-link to="/">Home</router-link>
4+
<router-link to="/about">About</router-link>
5+
<router-link to="/messages">Messages</router-link>
46
</div>
57
<router-view/>
68
</template>
File renamed without changes.

front/src/components/About.vue

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div id="about">
3+
<h3>About page</h3>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: "About",
10+
data() {
11+
return {
12+
13+
}
14+
},
15+
methods: {}
16+
}
17+
</script>
18+
19+
<style lang="scss" scoped>
20+
</style>

front/src/components/Home.vue

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<h3>Home page</h3>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: "Home",
10+
data() {
11+
return {
12+
13+
}
14+
},
15+
methods: {}
16+
}
17+
</script>
18+
19+
<style lang="scss" scoped>
20+
</style>

0 commit comments

Comments
 (0)