-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from netkicorp/bip75_endpoints
Bip75 endpoints
- Loading branch information
Showing
3 changed files
with
187 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/netki/transactidlibraryjavademo/controller/Bip75Controller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.netki.transactidlibraryjavademo.controller | ||
|
||
import com.netki.transactidlibraryjavademo.service.TransactIdService | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@Tag(name = "Bip75", description = "BIP75 API") | ||
class Bip75Controller { | ||
|
||
@Autowired | ||
private lateinit var transactIdService: TransactIdService | ||
|
||
@Operation( | ||
summary = "Post protocol message binary", | ||
description = "Post a protocol message binary, could be encrypted or not" | ||
) | ||
@ApiResponses( | ||
value = [ | ||
ApiResponse( | ||
responseCode = "202", | ||
description = "Protocol message accepted and stored." | ||
), | ||
ApiResponse( | ||
responseCode = "200", | ||
description = "Returns the correspondent response for the protocol message.", | ||
content = [ | ||
Content( | ||
mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE, | ||
schema = Schema(implementation = ByteArray::class) | ||
) | ||
] | ||
) | ||
] | ||
) | ||
@RequestMapping( | ||
method = [RequestMethod.POST], | ||
value = ["/addresses/{address_id}/messages"], | ||
consumes = [MediaType.APPLICATION_OCTET_STREAM_VALUE], | ||
produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE] | ||
) | ||
fun sendProtocolMessage( | ||
@Parameter(description = "Unique identifier for address.") | ||
@PathVariable("address_id") addressId: String, | ||
@Parameter(description = "Set to true if you want to do this flow async, false otherwise.") | ||
@RequestParam async: Boolean = false, | ||
@Parameter(description = "Binary containing the protocol message") | ||
@RequestBody protocolMessage: ByteArray | ||
): ResponseEntity<Any> { | ||
val messageResponse = when (async) { | ||
true -> transactIdService.sendProtocolMessageAsync(addressId, protocolMessage) | ||
false -> transactIdService.sendProtocolMessage(addressId, protocolMessage) | ||
} | ||
return if (messageResponse != null) { | ||
ResponseEntity.ok(messageResponse) | ||
} else { | ||
ResponseEntity(HttpStatus.ACCEPTED) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters