Skip to content

Commit 9175e81

Browse files
author
Aibek Abykeev
committed
Merge branch 'sprint' into 'master'
Open Chain Integration See merge request open-platform/state!36
2 parents 4d8828a + cff8e7e commit 9175e81

19 files changed

Lines changed: 169 additions & 83 deletions

src/main/kotlin/io/openfuture/state/controller/ExceptionHandler.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.openfuture.state.controller
22

33
import io.openfuture.state.controller.domain.dto.ErrorDto
44
import io.openfuture.state.controller.domain.dto.FieldErrorDto
5-
import io.openfuture.state.exception.ApiException
5+
import io.openfuture.state.exception.DuplicateEntityException
66
import io.openfuture.state.exception.NotFoundException
77
import org.springframework.http.HttpStatus
88
import org.springframework.web.bind.MethodArgumentNotValidException
@@ -19,17 +19,18 @@ class ExceptionHandler {
1919
return ErrorDto(HttpStatus.NOT_FOUND.value(), ex.message)
2020
}
2121

22-
@ResponseStatus(HttpStatus.BAD_REQUEST)
23-
@ExceptionHandler(ApiException::class)
24-
fun handleApiException(ex: ApiException): ErrorDto {
25-
return ErrorDto(HttpStatus.BAD_REQUEST.value(), ex.message)
26-
}
27-
2822
@ResponseStatus(HttpStatus.BAD_REQUEST)
2923
@ExceptionHandler(MethodArgumentNotValidException::class)
3024
fun handleException(ex: MethodArgumentNotValidException): ErrorDto {
3125
val fieldErrors = ex.bindingResult.fieldErrors.map { FieldErrorDto(it.field, it.defaultMessage) }
3226
return ErrorDto(HttpStatus.BAD_REQUEST.value(), "Invalid parameters", fieldErrors)
3327
}
3428

29+
30+
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
31+
@ExceptionHandler(DuplicateEntityException::class)
32+
fun handleDuplicateException(ex: DuplicateEntityException): ErrorDto {
33+
return ErrorDto(HttpStatus.UNPROCESSABLE_ENTITY.value(), ex.message)
34+
}
35+
3536
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.openfuture.state.controller
2+
3+
import io.openfuture.state.controller.domain.dto.OpenScaffoldDto
4+
import io.openfuture.state.controller.domain.request.SaveOpenScaffoldRequest
5+
import io.openfuture.state.service.OpenScaffoldService
6+
import org.springframework.web.bind.annotation.PostMapping
7+
import org.springframework.web.bind.annotation.RequestBody
8+
import org.springframework.web.bind.annotation.RequestMapping
9+
import org.springframework.web.bind.annotation.RestController
10+
import javax.validation.Valid
11+
12+
@RestController
13+
@RequestMapping("/api/open-scaffolds")
14+
class OpenScaffoldController(
15+
private val openScaffoldService: OpenScaffoldService
16+
) {
17+
18+
@PostMapping
19+
fun save(@RequestBody @Valid request: SaveOpenScaffoldRequest): OpenScaffoldDto {
20+
return OpenScaffoldDto(openScaffoldService.save(request))
21+
}
22+
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.openfuture.state.controller.domain.dto
2+
3+
import io.openfuture.state.entity.OpenScaffold
4+
5+
data class OpenScaffoldDto(
6+
val id: Long,
7+
val recipientAddress: String,
8+
val webHook: String
9+
) {
10+
11+
constructor(openScaffold: OpenScaffold) : this(
12+
openScaffold.id,
13+
openScaffold.recipientAddress,
14+
openScaffold.webHook
15+
)
16+
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.openfuture.state.controller.domain.request
2+
3+
import javax.validation.constraints.NotBlank
4+
5+
data class SaveOpenScaffoldRequest(
6+
@field:NotBlank val address: String,
7+
@field:NotBlank val webHook: String
8+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.openfuture.state.entity
2+
3+
import io.openfuture.state.entity.base.BaseModel
4+
import javax.persistence.Column
5+
import javax.persistence.Entity
6+
import javax.persistence.Table
7+
8+
@Entity
9+
@Table(name = "open_scaffolds")
10+
class OpenScaffold(
11+
12+
@Column(name = "recipient_address", nullable = false, unique = true)
13+
var recipientAddress: String,
14+
15+
@Column(name = "web_hook", nullable = false)
16+
var webHook: String
17+
) : BaseModel()

src/main/kotlin/io/openfuture/state/exception/ApiException.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.openfuture.state.exception
2+
3+
class DuplicateEntityException(message: String) : Exception(message)

src/main/kotlin/io/openfuture/state/openchain/component/openrpc/dto/transfertransaction/TransferTransactionDto.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class TransferTransactionDto(
44
val timestamp: Long,
55
val fee: Long,
66
val amount: Long,
7-
val recipientAddress: String?,
7+
val recipientAddress: String,
88
val senderPublicKey: String,
99
val senderAddress: String,
1010
val senderSignature: String,

src/main/kotlin/io/openfuture/state/openchain/dto/OpenTransferTransactionDto.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/kotlin/io/openfuture/state/openchain/entity/OpenTransferTransaction.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ class OpenTransferTransaction(
1212
@Column(name = "fee")
1313
var fee: Long,
1414

15-
@Column(name = "amount", nullable = false)
15+
@Column(name = "amount")
1616
var amount: Long,
1717

18-
@Column(name = "hash", nullable = false)
18+
@Column(name = "hash")
1919
var hash: String,
2020

21-
@Column(name = "sender_address", nullable = false)
21+
@Column(name = "sender_address")
2222
var senderAddress: String,
2323

24-
@Column(name = "recipient_address", nullable = false)
25-
var recipientAddress: String,
24+
@Column(name = "recipient_address")
25+
var recipientAddress: String?,
2626

27-
@Column(name = "block_hash", nullable = false)
27+
@Column(name = "block_hash")
2828
var blockHash: String,
2929

30-
@Column(name = "date", nullable = false)
30+
@Column(name = "date")
3131
var date: Long,
3232

33-
@Column(name = "web_hook", nullable = false)
34-
var webHook: String
33+
@Column(name = "web_hook")
34+
var webHook: String?
3535

3636
) : BaseModel()

0 commit comments

Comments
 (0)