@@ -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 "ねねっち" | |||
} | |||
} |
@@ -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 | |||
) |
@@ -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 | |||
) |
@@ -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> | |||
} |
@@ -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> | |||
} |
@@ -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> | |||
} |
@@ -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) | |||
} | |||
} |
@@ -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() | |||
} | |||
} |