Skip to content

Commit

Permalink
Feature : request util 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
Cha-Young-Ho committed Nov 2, 2022
1 parent af2cd31 commit 7df71b4
Show file tree
Hide file tree
Showing 73 changed files with 127 additions and 3 deletions.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation ("com.google.code.gson:gson:2.9.0")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.kafka:spring-kafka")
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2
24
0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/localstate/build-history.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.boribori.boardserver.board

import com.boribori.boardserver.board.dto.DtoOfGetBoard
import com.boribori.boardserver.board.dto.request.RequestOfGetBooks
import com.boribori.boardserver.util.RequestUtil
import com.boribori.boardserver.util.dto.ResponseOfGetBook
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
Expand All @@ -11,7 +13,8 @@ import java.util.*

@RestController
class BoardController(
private val boardService: BoardService
private val boardService: BoardService,
private val requestUtil: RequestUtil
) {

@GetMapping("/api/board/{boardId}")
Expand All @@ -23,7 +26,10 @@ class BoardController(
@GetMapping("/api/boards")
fun getBoardList(@RequestParam request: RequestOfGetBooks){

}


@GetMapping("/api/test")
fun getISBN(@RequestParam isbn : String): ResponseOfGetBook? {
return requestUtil.getIsbn(isbn);
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/boribori/boardserver/common/Content.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.boribori.boardserver.common

import com.google.gson.annotations.SerializedName

data class Content (

@SerializedName("isbn" ) var isbn : String? = null,
@SerializedName("title" ) var title : String? = null,
@SerializedName("author" ) var author : String? = null,
@SerializedName("description" ) var description : String? = null,
@SerializedName("imagePath" ) var imagePath : String? = null,
@SerializedName("price" ) var price : Int? = null,
@SerializedName("publisher" ) var publisher : String? = null,
@SerializedName("page" ) var page : Int? = null,
@SerializedName("pubDate" ) var pubDate : String? = null,
@SerializedName("adult" ) var adult : Boolean? = null

)
10 changes: 10 additions & 0 deletions src/main/kotlin/com/boribori/boardserver/common/Status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.boribori.boardserver.common

import com.google.gson.annotations.SerializedName


data class Status (

@SerializedName("msg" ) var msg : String? = null

)
19 changes: 19 additions & 0 deletions src/main/kotlin/com/boribori/boardserver/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.boribori.boardserver.config

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter

@EnableWebSecurity
class SecurityConfig: WebSecurityConfigurerAdapter() {


override fun configure(http: HttpSecurity) {
http.anonymous()
.and()
.formLogin().disable()
.authorizeRequests()
.anyRequest().permitAll()
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/boribori/boardserver/util/RequestUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.boribori.boardserver.util

import com.boribori.boardserver.util.dto.ResponseOfGetBook
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate

@Component
class RequestUtil (
private val restTemplateFactory: RestTemplateFactory
){

fun getIsbn(isbn : String) : ResponseOfGetBook? {
return restTemplateFactory.exchage(isbn)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.boribori.boardserver.util

import com.boribori.boardserver.util.dto.ResponseOfGetBook
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
import org.springframework.web.client.getForObject
import org.springframework.web.util.UriBuilder
import org.springframework.web.util.UriBuilderFactory
import org.springframework.web.util.UriComponentsBuilder

@Component
class RestTemplateFactory{
val objectMapper: ObjectMapper = ObjectMapper()
val restTemplate: RestTemplate = RestTemplate()

fun getHeader(): HttpHeaders {
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON
return headers
}

fun getHttpEntity(): HttpEntity<Any> {
return HttpEntity(getHeader())
}

fun exchage(isbn: String): ResponseOfGetBook? {
var params : HashMap<String, String> = HashMap();
params.put("isbn", isbn)
val response : String? = restTemplate.getForObject<String>("http://localhost:8081/api/search/book?isbn="+isbn,getHttpEntity(), String :: class)
return objectMapper.readValue(response, ResponseOfGetBook::class.java);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.boribori.boardserver.util.dto

import com.boribori.boardserver.common.Content
import com.boribori.boardserver.common.Status
import com.google.gson.annotations.SerializedName

data class ResponseOfGetBook (
@SerializedName("status" ) var status : Status? = Status(),
@SerializedName("content" ) var content : Content? = Content()

)

0 comments on commit 7df71b4

Please sign in to comment.