Add uploader module and add http for servlet with service container factory and config
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
83bc97bb02
commit
4910bd9122
@ -0,0 +1,30 @@
|
|||||||
|
package com.cubetiqs.web.config
|
||||||
|
|
||||||
|
import org.apache.catalina.connector.Connector
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
|
||||||
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
|
||||||
|
@ConditionalOnProperty(name = ["http.port"], matchIfMissing = false)
|
||||||
|
@Configuration
|
||||||
|
class HttpServletConfig(
|
||||||
|
@Value("\${http.port:8080}")
|
||||||
|
private val httpPort: Int,
|
||||||
|
) {
|
||||||
|
@Bean
|
||||||
|
fun servletContainer(): ServletWebServerFactory {
|
||||||
|
val tomcat = TomcatServletWebServerFactory()
|
||||||
|
tomcat.addAdditionalTomcatConnectors(createStandardConnector())
|
||||||
|
return tomcat
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createStandardConnector(): Connector {
|
||||||
|
val connector = Connector("org.apache.coyote.http11.Http11NioProtocol")
|
||||||
|
connector.port = httpPort
|
||||||
|
connector.scheme = "http"
|
||||||
|
return connector
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,6 @@ class OpenApiDocConfig @Autowired constructor(
|
|||||||
val appProperties: AppProperties,
|
val appProperties: AppProperties,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private val ADMIN_API_PATH get() = "/admin/**"
|
|
||||||
private val DEFAULT_API_PATH get() = "/**"
|
private val DEFAULT_API_PATH get() = "/**"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,19 +54,10 @@ class OpenApiDocConfig @Autowired constructor(
|
|||||||
return GroupedOpenApi.builder()
|
return GroupedOpenApi.builder()
|
||||||
.group("default")
|
.group("default")
|
||||||
.pathsToMatch(DEFAULT_API_PATH)
|
.pathsToMatch(DEFAULT_API_PATH)
|
||||||
.pathsToExclude("/error", ADMIN_API_PATH)
|
|
||||||
.packagesToScan("com.cubetiqs.web")
|
.packagesToScan("com.cubetiqs.web")
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
fun adminApi(): GroupedOpenApi {
|
|
||||||
return GroupedOpenApi.builder()
|
|
||||||
.group("admin")
|
|
||||||
.pathsToMatch(ADMIN_API_PATH)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun cubetiqOpenAPI(): OpenAPI {
|
fun cubetiqOpenAPI(): OpenAPI {
|
||||||
return OpenAPI()
|
return OpenAPI()
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package com.cubetiqs.web.controller.admin
|
|
||||||
|
|
||||||
import com.cubetiqs.web.annotation.ApiBearerAuth
|
|
||||||
import com.cubetiqs.web.controller.BaseController
|
|
||||||
import com.cubetiqs.web.util.RouteConstants
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
|
||||||
import org.springframework.web.bind.annotation.RestController
|
|
||||||
|
|
||||||
@Tag(name = "Admin")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(RouteConstants.ADMIN)
|
|
||||||
class AdminController : BaseController {
|
|
||||||
@ApiBearerAuth
|
|
||||||
@GetMapping
|
|
||||||
fun getAdmin(): String {
|
|
||||||
return "Admin"
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.cubetiqs.web.modules.uploader
|
||||||
|
|
||||||
|
import com.cubetiqs.web.util.RouteConstants
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag
|
||||||
|
import org.springdoc.core.converters.models.PageableAsQueryParam
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.data.domain.Page
|
||||||
|
import org.springframework.data.domain.Pageable
|
||||||
|
import org.springframework.web.bind.annotation.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@UploaderModule
|
||||||
|
@Tag(name = "Uploader Controller")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(RouteConstants.INDEX + "uploader")
|
||||||
|
class UploaderController @Autowired constructor(
|
||||||
|
private val repository: UploaderRepository,
|
||||||
|
) {
|
||||||
|
@GetMapping
|
||||||
|
@PageableAsQueryParam
|
||||||
|
fun getAll(
|
||||||
|
@Parameter(hidden = true)
|
||||||
|
pageable: Pageable?,
|
||||||
|
): Page<UploaderEntity> {
|
||||||
|
return repository.findAll(pageable ?: Pageable.unpaged())
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseStatus(value = org.springframework.http.HttpStatus.CREATED)
|
||||||
|
@PostMapping
|
||||||
|
fun create(
|
||||||
|
@RequestBody body: UploaderEntity
|
||||||
|
): UploaderEntity {
|
||||||
|
return repository.save(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseStatus(value = org.springframework.http.HttpStatus.OK)
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
fun update(
|
||||||
|
@PathVariable id: String,
|
||||||
|
@RequestBody body: UploaderEntity
|
||||||
|
): UploaderEntity {
|
||||||
|
val user = repository.findById(UUID.fromString(id)).orElseThrow {
|
||||||
|
throw IllegalArgumentException("File not found")
|
||||||
|
}
|
||||||
|
body.id = user.id
|
||||||
|
return repository.save(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseStatus(value = org.springframework.http.HttpStatus.NO_CONTENT)
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
fun delete(
|
||||||
|
@PathVariable id: String,
|
||||||
|
) {
|
||||||
|
val user = repository.findById(UUID.fromString(id)).orElseThrow {
|
||||||
|
throw IllegalArgumentException("File not found")
|
||||||
|
}
|
||||||
|
repository.delete(user)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.cubetiqs.web.modules.uploader
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate
|
||||||
|
import java.io.Serializable
|
||||||
|
import java.util.*
|
||||||
|
import javax.persistence.*
|
||||||
|
|
||||||
|
@UploaderModule
|
||||||
|
@Entity
|
||||||
|
@Table(name = "uploader")
|
||||||
|
open class UploaderEntity(
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
open var id: UUID? = null,
|
||||||
|
|
||||||
|
@Column(name = "filename")
|
||||||
|
open var filename: String? = null,
|
||||||
|
|
||||||
|
@Column(name = "content_type")
|
||||||
|
open var contentType: String? = null,
|
||||||
|
|
||||||
|
@Column(name = "content_length")
|
||||||
|
open var contentLength: Long? = null,
|
||||||
|
|
||||||
|
@Column(name = "path", length = 300)
|
||||||
|
open var path: String? = null,
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name = "created_at")
|
||||||
|
open var createdAt: Date? = null,
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name = "updated_at")
|
||||||
|
open var updatedAt: Date? = null,
|
||||||
|
) : Serializable {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false
|
||||||
|
other as UploaderEntity
|
||||||
|
|
||||||
|
return id != null && id == other.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = javaClass.hashCode()
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.cubetiqs.web.modules.uploader
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
|
|
||||||
|
@ConditionalOnProperty(name = ["module.uploader.enabled", "spring.datasource.enabled"], havingValue = "true")
|
||||||
|
annotation class UploaderModule
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.cubetiqs.web.modules.uploader
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@UploaderModule
|
||||||
|
@Repository
|
||||||
|
interface UploaderRepository : JpaRepository<UploaderEntity, UUID>
|
@ -15,7 +15,7 @@ import java.util.*
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(RouteConstants.INDEX + "user")
|
@RequestMapping(RouteConstants.INDEX + "user")
|
||||||
class UserController @Autowired constructor(
|
class UserController @Autowired constructor(
|
||||||
private val userRepository: UserRepository,
|
private val repository: UserRepository,
|
||||||
) {
|
) {
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PageableAsQueryParam
|
@PageableAsQueryParam
|
||||||
@ -23,7 +23,7 @@ class UserController @Autowired constructor(
|
|||||||
@Parameter(hidden = true)
|
@Parameter(hidden = true)
|
||||||
pageable: Pageable?,
|
pageable: Pageable?,
|
||||||
): Page<UserEntity> {
|
): Page<UserEntity> {
|
||||||
return userRepository.findAll(pageable ?: Pageable.unpaged())
|
return repository.findAll(pageable ?: Pageable.unpaged())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(value = org.springframework.http.HttpStatus.CREATED)
|
@ResponseStatus(value = org.springframework.http.HttpStatus.CREATED)
|
||||||
@ -31,7 +31,7 @@ class UserController @Autowired constructor(
|
|||||||
fun create(
|
fun create(
|
||||||
@RequestBody body: UserEntity
|
@RequestBody body: UserEntity
|
||||||
): UserEntity {
|
): UserEntity {
|
||||||
return userRepository.save(body)
|
return repository.save(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(value = org.springframework.http.HttpStatus.OK)
|
@ResponseStatus(value = org.springframework.http.HttpStatus.OK)
|
||||||
@ -40,11 +40,11 @@ class UserController @Autowired constructor(
|
|||||||
@PathVariable id: String,
|
@PathVariable id: String,
|
||||||
@RequestBody body: UserEntity
|
@RequestBody body: UserEntity
|
||||||
): UserEntity {
|
): UserEntity {
|
||||||
val user = userRepository.findById(UUID.fromString(id)).orElseThrow {
|
val user = repository.findById(UUID.fromString(id)).orElseThrow {
|
||||||
throw IllegalArgumentException("User not found")
|
throw IllegalArgumentException("User not found")
|
||||||
}
|
}
|
||||||
body.id = user.id
|
body.id = user.id
|
||||||
return userRepository.save(body)
|
return repository.save(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(value = org.springframework.http.HttpStatus.NO_CONTENT)
|
@ResponseStatus(value = org.springframework.http.HttpStatus.NO_CONTENT)
|
||||||
@ -52,9 +52,9 @@ class UserController @Autowired constructor(
|
|||||||
fun delete(
|
fun delete(
|
||||||
@PathVariable id: String,
|
@PathVariable id: String,
|
||||||
) {
|
) {
|
||||||
val user = userRepository.findById(UUID.fromString(id)).orElseThrow {
|
val user = repository.findById(UUID.fromString(id)).orElseThrow {
|
||||||
throw IllegalArgumentException("User not found")
|
throw IllegalArgumentException("User not found")
|
||||||
}
|
}
|
||||||
userRepository.delete(user)
|
repository.delete(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ import java.io.Serializable
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
|
|
||||||
|
@UserModule
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "user")
|
@Table(name = "user")
|
||||||
open class UserEntity(
|
open class UserEntity(
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
http:
|
||||||
|
port: ${HTTP_PORT:8080}
|
||||||
server:
|
server:
|
||||||
port: ${SERVER_PORT:8080}
|
port: ${SERVER_PORT:8443}
|
||||||
ssl:
|
ssl:
|
||||||
key-store: ${SERVER_SSL_KEY_STORE:classpath:keystore/server.jks}
|
key-store: ${SERVER_SSL_KEY_STORE:classpath:keystore/server.jks}
|
||||||
key-store-password: ${SERVER_SSL_KEY_STORE_PASSWORD:cubetiq}
|
key-store-password: ${SERVER_SSL_KEY_STORE_PASSWORD:cubetiq}
|
||||||
@ -12,7 +14,7 @@ spring:
|
|||||||
profiles:
|
profiles:
|
||||||
active: ${APP_PROFILE:demo}
|
active: ${APP_PROFILE:demo}
|
||||||
application:
|
application:
|
||||||
name: cubetiq-api-service
|
name: ${SERVICE_NAME:cubetiq-api-service}
|
||||||
redis:
|
redis:
|
||||||
enabled: ${REDIS_ENABLED:false}
|
enabled: ${REDIS_ENABLED:false}
|
||||||
host: ${REDIS_HOST:localhost}
|
host: ${REDIS_HOST:localhost}
|
||||||
@ -30,12 +32,14 @@ spring:
|
|||||||
module:
|
module:
|
||||||
user:
|
user:
|
||||||
enabled: ${MODULE_USER_ENABLED:true}
|
enabled: ${MODULE_USER_ENABLED:true}
|
||||||
|
uploader:
|
||||||
|
enabled: ${MODULE_UPLOADER_ENABLED:true}
|
||||||
|
|
||||||
cubetiq:
|
cubetiq:
|
||||||
app:
|
app:
|
||||||
data-dir: ${APP_DATA_DIR:${user.home}/${spring.application.name}}
|
data-dir: ${APP_DATA_DIR:${user.home}/${spring.application.name}}
|
||||||
name: CUBETIQ Web API
|
name: ${APP_NAME:CUBETIQ Web API}
|
||||||
description: CUBETIQ Spring Web API's Documentation
|
description: ${APP_DESCRIPTION:CUBETIQ Spring Web API's Documentation}
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
file:
|
file:
|
||||||
|
Loading…
Reference in New Issue
Block a user