Skip to content

Commit

Permalink
⚡ Refactor + Vaadin Stable
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Mar 23, 2024
1 parent e26f107 commit dccc42d
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
./frontend
frontend
./frontend/

### STS ###
.apt_generated
Expand Down
14 changes: 10 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ plugins {
kotlin("plugin.noarg") version "1.9.10"
kotlin("plugin.allopen") version "1.9.10"
id("com.google.cloud.tools.jib") version "3.3.1"
id("com.vaadin") version "24.3.7"
}

allOpen {
Expand Down Expand Up @@ -63,18 +64,23 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-elasticsearch")

// Vaadin
//implementation("com.vaadin:vaadin-spring-boot-starter")
implementation("com.vaadin:vaadin-spring-boot-starter")

// Lombok
compileOnly("org.projectlombok:lombok")
// Kotlin
implementation("org.jetbrains.kotlin:kotlin-reflect")

// Lombok
annotationProcessor("org.projectlombok:lombok")
compileOnly("org.projectlombok:lombok")

// Persistence
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
runtimeOnly("org.postgresql:postgresql")

// WebClient
implementation("org.springframework.boot:spring-boot-starter-webflux")

// Swagger-UI + OpenApi
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0")

Expand All @@ -95,7 +101,7 @@ dependencies {

dependencyManagement {
imports {
// mavenBom("com.vaadin:vaadin-bom:24.3.7")
mavenBom("com.vaadin:vaadin-bom:24.3.7")
mavenBom("org.springframework.ai:spring-ai-bom:0.8.1")
}
}
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
depends_on:
- db
- redis
- search
environment:
- 'SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/database'
- 'SPRING_DATASOURCE_USERNAME=user'
Expand Down Expand Up @@ -47,7 +48,7 @@ services:
max-file: "10"
environment:
- 'discovery.type=single-node'
- 'xpack.security.enabled=false'
ports:
- "9200:9200"
- "9600:9600"

- "9600:9600"
1 change: 1 addition & 0 deletions docker-compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
depends_on:
- db
- redis
- search
environment:
- 'SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/database'
- 'SPRING_DATASOURCE_USERNAME=user'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.albatros.springsecurity

import com.albatros.springsecurity.config.api.ApiInfoConfig
import com.albatros.springsecurity.config.webclient.TenderApiConfig
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories

@EnableCaching
@SpringBootApplication
@EnableConfigurationProperties(ApiInfoConfig::class)
@EnableConfigurationProperties(ApiInfoConfig::class, TenderApiConfig::class)
@EnableElasticsearchRepositories
class SpringSecurityApplication

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.util.Collections

@Configuration
class CacheManagerConfig {

companion object {
val timeToLiveDuration: Duration = Duration.ofSeconds(40_000)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.albatros.springsecurity.config.webclient

import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotEmpty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.validation.annotation.Validated

@Validated
@EnableConfigurationProperties(TenderApiConfig::class)
@ConfigurationProperties(prefix = "tender-config")
data class TenderApiConfig(
@field:NotEmpty
val apiUrl: String,
@field:NotEmpty
val apiKey: String,
@field:Min(0)
val timeoutMs: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.albatros.springsecurity.config.webclient

import io.netty.channel.ChannelOption
import io.netty.handler.timeout.ReadTimeoutHandler
import io.netty.handler.timeout.WriteTimeoutHandler
import java.util.concurrent.TimeUnit
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.http.codec.xml.Jaxb2XmlDecoder
import org.springframework.http.codec.xml.Jaxb2XmlEncoder
import org.springframework.web.reactive.function.client.ExchangeStrategies
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class WebClientConfig(
private val tenderApiConfig: TenderApiConfig
) {

fun clientHttpConnector() = ReactorClientHttpConnector(
HttpClient.create().apply {
option(ChannelOption.CONNECT_TIMEOUT_MILLIS, tenderApiConfig.timeoutMs).doOnConnected {
it.addHandlerLast(ReadTimeoutHandler(tenderApiConfig.timeoutMs.toLong(), TimeUnit.MILLISECONDS))
it.addHandlerLast(WriteTimeoutHandler(tenderApiConfig.timeoutMs.toLong(), TimeUnit.MILLISECONDS))
}
}
)

@Bean
fun webClientWithTimeOut() = WebClient.builder().exchangeStrategies(
ExchangeStrategies.builder().codecs {
it.defaultCodecs().jaxb2Decoder(Jaxb2XmlDecoder())
it.defaultCodecs().jaxb2Encoder(Jaxb2XmlEncoder())
}.build()
).clientConnector(clientHttpConnector()).baseUrl(tenderApiConfig.apiUrl).build()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albatros.springsecurity.domain.model.database
package com.albatros.springsecurity.data.model.database

import jakarta.persistence.Column
import jakarta.persistence.GeneratedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.albatros.springsecurity.data.model.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class TenderDto {
private int ID;
private String Date;
private String TenderName;
private String Customer;
private String Category;
private String Region;
private Long Price;
private String EndTime;
private String Etp;
private String TenderLink;
private String TenderLinkInner;
@JsonProperty("User_id")
private int UserId;
private String CustomerINN;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.albatros.springsecurity.data.model.dto

import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable

class TenderProviderDto(
@JsonProperty("ID")
var id: Int,
@JsonProperty("EtpName")
var etpName: String,
@JsonProperty("EtpLink")
var etpLink: String
) : Serializable
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.albatros.springsecurity.domain.model.exception
package com.albatros.springsecurity.data.model.exception

import com.albatros.springsecurity.domain.model.response.ApiResponse
import com.albatros.springsecurity.data.model.response.ApiResponse
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import org.springframework.http.HttpStatus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albatros.springsecurity.domain.model.exception
package com.albatros.springsecurity.data.model.exception

import org.springframework.http.HttpStatus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albatros.springsecurity.domain.model.exception
package com.albatros.springsecurity.data.model.exception

import org.springframework.http.HttpStatus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.albatros.springsecurity.domain.model.response
package com.albatros.springsecurity.data.model.response

import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.albatros.springsecurity.domain.repository
package com.albatros.springsecurity.data.repository

import com.albatros.springsecurity.domain.model.database.AbstractEntity
import com.albatros.springsecurity.data.model.database.AbstractEntity
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.NoRepositoryBean

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.albatros.springsecurity.data.service

import com.albatros.springsecurity.config.webclient.TenderApiConfig
import com.albatros.springsecurity.data.model.dto.TenderProviderDto
import org.springframework.http.MediaType
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient

@Service
class TenderService(
private val tenderApiConfig: TenderApiConfig,
private val webClient: WebClient
) {
fun getAllTenderProviders(mode: String = "eauc"): MutableList<TenderProviderDto>? = webClient
.get()
.uri("/export?mode=$mode&api_code=${tenderApiConfig.apiKey}&dtype=json")
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToFlux(TenderProviderDto::class.java)
.collectList()
.block()



}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit dccc42d

Please sign in to comment.