wrap response in object

This commit is contained in:
Carsten Otto
2021-12-09 14:30:25 +01:00
parent 9a8549b527
commit fc4ac8ebd9
5 changed files with 67 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ package de.cotto.lndmanagej.controller;
import com.codahale.metrics.annotation.Timed;
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
import de.cotto.lndmanagej.controller.dto.SelfPaymentDto;
import de.cotto.lndmanagej.dto.SelfPaymentsDto;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.SelfPaymentsService;
@@ -12,8 +13,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/")
@Import(ObjectMapperConfiguration.class)
@@ -26,33 +25,33 @@ public class SelfPaymentsController {
@Timed
@GetMapping("/channel/{channelId}/self-payments-from-channel")
public List<SelfPaymentDto> getSelfPaymentsFromChannel(@PathVariable ChannelId channelId) {
return selfPaymentsService.getSelfPaymentsFromChannel(channelId).stream()
public SelfPaymentsDto getSelfPaymentsFromChannel(@PathVariable ChannelId channelId) {
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromChannel(channelId).stream()
.map(SelfPaymentDto::createFromModel)
.toList();
.toList());
}
@Timed
@GetMapping("/node/{pubkey}/self-payments-from-peer")
public List<SelfPaymentDto> getSelfPaymentsFromPeer(@PathVariable Pubkey pubkey) {
return selfPaymentsService.getSelfPaymentsFromPeer(pubkey).stream()
public SelfPaymentsDto getSelfPaymentsFromPeer(@PathVariable Pubkey pubkey) {
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromPeer(pubkey).stream()
.map(SelfPaymentDto::createFromModel)
.toList();
.toList());
}
@Timed
@GetMapping("/channel/{channelId}/self-payments-to-channel")
public List<SelfPaymentDto> getSelfPaymentsToChannel(@PathVariable ChannelId channelId) {
return selfPaymentsService.getSelfPaymentsToChannel(channelId).stream()
public SelfPaymentsDto getSelfPaymentsToChannel(@PathVariable ChannelId channelId) {
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToChannel(channelId).stream()
.map(SelfPaymentDto::createFromModel)
.toList();
.toList());
}
@Timed
@GetMapping("/node/{pubkey}/self-payments-to-peer")
public List<SelfPaymentDto> getSelfPaymentsToPeer(@PathVariable Pubkey pubkey) {
return selfPaymentsService.getSelfPaymentsToPeer(pubkey).stream()
public SelfPaymentsDto getSelfPaymentsToPeer(@PathVariable Pubkey pubkey) {
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToPeer(pubkey).stream()
.map(SelfPaymentDto::createFromModel)
.toList();
.toList());
}
}

View File

@@ -0,0 +1,8 @@
package de.cotto.lndmanagej.dto;
import de.cotto.lndmanagej.controller.dto.SelfPaymentDto;
import java.util.List;
public record SelfPaymentsDto(List<SelfPaymentDto> selfPayments) {
}