diff --git a/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java b/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java index 30acf9e..5181427 100644 --- a/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java +++ b/src/main/java/ch/dissem/bitmessage/server/JabitServerApplication.java @@ -2,7 +2,6 @@ package ch.dissem.bitmessage.server; import ch.dissem.bitmessage.BitmessageContext; import ch.dissem.bitmessage.entity.BitmessageAddress; -import ch.dissem.bitmessage.entity.Plaintext; import ch.dissem.bitmessage.networking.DefaultNetworkHandler; import ch.dissem.bitmessage.ports.MemoryNodeRegistry; import ch.dissem.bitmessage.repository.JdbcAddressRepository; @@ -10,14 +9,13 @@ import ch.dissem.bitmessage.repository.JdbcConfig; import ch.dissem.bitmessage.repository.JdbcInventory; import ch.dissem.bitmessage.repository.JdbcMessageRepository; import ch.dissem.bitmessage.security.bc.BouncySecurity; +import ch.dissem.bitmessage.server.entities.Broadcasts; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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 @EnableAutoConfiguration public class JabitServerApplication { @@ -29,7 +27,7 @@ public class JabitServerApplication { } @RequestMapping("read/{broadcastAddress}") - public List read(@PathVariable String broadcastAddress) { + public Broadcasts read(@PathVariable String broadcastAddress) { BitmessageAddress broadcaster = ctx.addresses().getAddress(broadcastAddress); if (broadcaster == null) { broadcaster = new BitmessageAddress(broadcastAddress); @@ -37,7 +35,7 @@ public class JabitServerApplication { if (!broadcaster.isSubscribed()) { ctx.addSubscribtion(broadcaster); } - return ctx.messages().findMessages(broadcaster); + return new Broadcasts(broadcaster, ctx.messages().findMessages(broadcaster)); } public JabitServerApplication() { diff --git a/src/main/java/ch/dissem/bitmessage/server/entities/Broadcasts.java b/src/main/java/ch/dissem/bitmessage/server/entities/Broadcasts.java index 2c56615..6b825f1 100644 --- a/src/main/java/ch/dissem/bitmessage/server/entities/Broadcasts.java +++ b/src/main/java/ch/dissem/bitmessage/server/entities/Broadcasts.java @@ -1,7 +1,31 @@ package ch.dissem.bitmessage.server.entities; +import ch.dissem.bitmessage.entity.BitmessageAddress; +import ch.dissem.bitmessage.entity.Plaintext; + +import java.util.Collection; + /** * Created by chrigu on 30.09.15. */ public class Broadcasts { + private final Sender sender; + private final Message[] messages; + + public Broadcasts(BitmessageAddress sender, Collection<Plaintext> messages) { + this.sender = new Sender(sender); + this.messages = new Message[messages.size()]; + int i = 0; + for (Plaintext msg : messages) { + this.messages[i] = new Message(msg); + } + } + + public Sender getSender() { + return sender; + } + + public Message[] getMessages() { + return messages; + } } diff --git a/src/main/java/ch/dissem/bitmessage/server/entities/Message.java b/src/main/java/ch/dissem/bitmessage/server/entities/Message.java index ccd1c04..e25c1be 100644 --- a/src/main/java/ch/dissem/bitmessage/server/entities/Message.java +++ b/src/main/java/ch/dissem/bitmessage/server/entities/Message.java @@ -1,7 +1,43 @@ package ch.dissem.bitmessage.server.entities; +import ch.dissem.bitmessage.entity.Plaintext; + /** * Created by chrigu on 30.09.15. */ public class Message { + private Object id; + private String subject; + private String body; + + public Message(){} + public Message(Plaintext plaintext) { + this.id = plaintext.getId(); + this.subject = plaintext.getSubject(); + this.body = plaintext.getText(); + } + + public void setId(Object id) { + this.id = id; + } + + public Object getId() { + return id; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getSubject() { + return subject; + } + + public void setBody(String body) { + this.body = body; + } + + public String getBody() { + return body; + } } diff --git a/src/main/java/ch/dissem/bitmessage/server/entities/Sender.java b/src/main/java/ch/dissem/bitmessage/server/entities/Sender.java index 7e375bf..7ec6882 100644 --- a/src/main/java/ch/dissem/bitmessage/server/entities/Sender.java +++ b/src/main/java/ch/dissem/bitmessage/server/entities/Sender.java @@ -1,7 +1,24 @@ package ch.dissem.bitmessage.server.entities; +import ch.dissem.bitmessage.entity.BitmessageAddress; + /** * Created by chrigu on 30.09.15. */ public class Sender { + private final String address; + private final String alias; + + public Sender(BitmessageAddress address) { + this.address = address.getAddress(); + this.alias = address.toString(); + } + + public String getAddress() { + return address; + } + + public String getAlias() { + return alias; + } }