add node details

This commit is contained in:
Carsten Otto
2021-11-19 17:31:35 +01:00
parent 840938676e
commit e938c2d8a0
6 changed files with 144 additions and 7 deletions

View File

@@ -26,8 +26,8 @@ public class ChannelDetailsController {
}
@GetMapping("/details")
public ChannelDetailsDto getChannelDetails(@PathVariable ChannelId channelId) throws NotFoundException {
metrics.mark(MetricRegistry.name(getClass(), "getChannelDetails"));
public ChannelDetailsDto getDetails(@PathVariable ChannelId channelId) throws NotFoundException {
metrics.mark(MetricRegistry.name(getClass(), "getDetails"));
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
if (localChannel == null) {
throw new NotFoundException();

View File

@@ -0,0 +1,34 @@
package de.cotto.lndmanagej.controller;
import com.codahale.metrics.MetricRegistry;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.NodeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/node/{pubkey}")
public class NodeController {
private final NodeService nodeService;
private final Metrics metrics;
public NodeController(NodeService nodeService, Metrics metrics) {
this.nodeService = nodeService;
this.metrics = metrics;
}
@GetMapping("/alias")
public String getAlias(Pubkey pubkey) {
metrics.mark(MetricRegistry.name(getClass(), "getAlias"));
return nodeService.getAlias(pubkey);
}
@GetMapping("/details")
public NodeDetailsDto getDetails(@PathVariable Pubkey pubkey) {
metrics.mark(MetricRegistry.name(getClass(), "getDetails"));
return new NodeDetailsDto(pubkey, getAlias(pubkey));
}
}

View File

@@ -0,0 +1,11 @@
package de.cotto.lndmanagej.controller;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import de.cotto.lndmanagej.model.Pubkey;
public record NodeDetailsDto(
@JsonSerialize(using = ToStringSerializer.class) Pubkey pubkey,
String alias
) {
}