Bladeren bron

簡単な検索、登録

master
t.yamanaka 5 jaren geleden
bovenliggende
commit
67adb6ecf7
8 gewijzigde bestanden met toevoegingen van 67 en 73 verwijderingen
  1. +21
    -2
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/controller/APIController.kt
  2. +0
    -20
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/model/Bank.kt
  3. +11
    -0
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/model/Matching.kt
  4. +0
    -11
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/repository/BankRepository.kt
  5. +9
    -0
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/repository/MatchingRepository.kt
  6. +0
    -12
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/BankService.kt
  7. +0
    -28
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/BankServiceImpl.kt
  8. +26
    -0
      elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/MatchingService.kt

+ 21
- 2
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/controller/APIController.kt Bestand weergeven

@@ -1,6 +1,7 @@
package com.example.elasticsearch.elasticsearchdemo.controller

import com.example.elasticsearch.elasticsearchdemo.service.BankService
import com.example.elasticsearch.elasticsearchdemo.model.Matching
import com.example.elasticsearch.elasticsearchdemo.service.MatchingService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@@ -9,7 +10,7 @@ import org.springframework.web.bind.annotation.*
class APIController {

@Autowired
lateinit var bankService:BankService
lateinit var matchingService: MatchingService

@GetMapping("hello")
fun hello(): String{
@@ -18,5 +19,23 @@ class APIController {
"""
}

@GetMapping("/search/{id}")
fun search(@PathVariable("id") id:String): Matching {

lateinit var matching: Matching

matching = matchingService.getMatching(id)

return matching
}

@GetMapping("/insert/{name}")
fun save(@PathVariable("name") name:String):String {
matchingService.save(name)

return "ねねっち"
}



}

+ 0
- 20
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/model/Bank.kt Bestand weergeven

@@ -1,20 +0,0 @@
package com.example.elasticsearch.elasticsearchdemo.model

import org.springframework.data.annotation.Id
import org.springframework.data.elasticsearch.annotations.Document

@Document(indexName = "bank",type = "_doc")
data class Bank (
@Id
val accountNumber: Long
,val balance: Long
,val firstName: String
,val lastName: String
,val age: Int
,val gender: String
,val address: String
,val employer: String
,val email: String
,val city: String
,val state: String
)

+ 11
- 0
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/model/Matching.kt Bestand weergeven

@@ -0,0 +1,11 @@
package com.example.elasticsearch.elasticsearchdemo.model

import org.springframework.data.annotation.Id
import org.springframework.data.elasticsearch.annotations.Document

@Document(indexName = "matching")
data class Matching(
@Id
val id: String ? = null ,
val name: String
)

+ 0
- 11
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/repository/BankRepository.kt Bestand weergeven

@@ -1,11 +0,0 @@
package com.example.elasticsearch.elasticsearchdemo.repository

import com.example.elasticsearch.elasticsearchdemo.model.Bank
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.stereotype.Repository

@Repository
interface BankRepository : ElasticsearchRepository<Bank,String> {

fun findByName(name: String): List<Bank>
}

+ 9
- 0
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/repository/MatchingRepository.kt Bestand weergeven

@@ -0,0 +1,9 @@
package com.example.elasticsearch.elasticsearchdemo.repository

import com.example.elasticsearch.elasticsearchdemo.model.Matching
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository

interface matchingRepository: ElasticsearchRepository<Matching, String> {

fun findByName(name:String): List<Matching>
}

+ 0
- 12
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/BankService.kt Bestand weergeven

@@ -1,12 +0,0 @@
package com.example.elasticsearch.elasticsearchdemo.service

import com.example.elasticsearch.elasticsearchdemo.model.Bank

interface BankService {

fun save(bank:Bank): Bank

fun delete(bank:Bank)

fun findByName(name:String):List<Bank>
}

+ 0
- 28
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/BankServiceImpl.kt Bestand weergeven

@@ -1,28 +0,0 @@
package com.example.elasticsearch.elasticsearchdemo.service

import com.example.elasticsearch.elasticsearchdemo.model.Bank
import com.example.elasticsearch.elasticsearchdemo.repository.BankRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class BankServiceImpl : BankService{
lateinit var repository: BankRepository

@Autowired
fun setBankRepository(repository: BankRepository){
this.repository = repository
}

override fun save(bank: Bank): Bank {
return repository.save(bank)
}

override fun delete(bank: Bank) {
return repository.delete(bank)
}

override fun findByName(name: String): List<Bank> {
return repository.findByName(name)
}
}

+ 26
- 0
elasticsearchdemo/src/main/kotlin/com/example/elasticsearch/elasticsearchdemo/service/MatchingService.kt Bestand weergeven

@@ -0,0 +1,26 @@
package com.example.elasticsearch.elasticsearchdemo.service

import com.example.elasticsearch.elasticsearchdemo.model.Matching
import com.example.elasticsearch.elasticsearchdemo.repository.matchingRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class MatchingService {

@Autowired
lateinit var matchingRepository: matchingRepository


fun save(name: String) {
val matching = Matching(null ,name)
matchingRepository.save(matching)

}

fun getMatching(id: String): Matching {
val matching = matchingRepository.findById(id)

return matching.get()
}
}

Laden…
Annuleren
Opslaan