Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fake service implementation #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions backend/src/main/kotlin/de/sovity/chatapp/api/ApiResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,46 @@ import de.sovity.chatapp.model.ConnectorCreateDto
import de.sovity.chatapp.model.ConnectorDto
import de.sovity.chatapp.model.MessageDto
import de.sovity.chatapp.model.MessageNotificationDto
import de.sovity.chatapp.model.MessageSendDto
import de.sovity.chatapp.service.EdcService
import jakarta.ws.rs.GET
import jakarta.ws.rs.HeaderParam
import jakarta.ws.rs.POST
import jakarta.ws.rs.Path
import jakarta.ws.rs.QueryParam

@Path("/")
class ApiResource {
class ApiResource(
val edcService: EdcService
) {

@GET
@Path("ui/connectors")
fun getConnectors(): List<ConnectorDto> {
TODO("Implementation")
return edcService.getConnectors()
}

@POST
@Path("ui/connectors")
fun createConnector(request: ConnectorCreateDto): ConnectorDto {
TODO("Implementation")
return edcService.createConnector(request)
}

@GET
@Path("ui/connectors/{connectorId}/messages")
fun getAllMessages(@QueryParam("connectorId") connectorId: String): List<MessageDto> {
TODO("Implementation")
return edcService.getMessages(connectorId)
}

@POST
@Path("ui/connectors/{connectorId}/messages")
fun sendMessage(@QueryParam("connectorId") connectorId: String): MessageDto {
TODO("Implementation")
fun sendMessage(@QueryParam("connectorId") connectorId: String, message: MessageSendDto): MessageDto {
return edcService.sendMessage(connectorId, message)
}

@POST
@Path("edc/notifications/receive")
fun receiveNotification(@HeaderParam("Edc-Bpn") edcBpn: String, notification: MessageNotificationDto) {
TODO("Implementation")
edcService.receiveNotification(edcBpn, notification)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.sovity.chatapp.model

data class MessageSendDto(
val message: String,
val username: String
val message: String
)
15 changes: 15 additions & 0 deletions backend/src/main/kotlin/de/sovity/chatapp/service/EdcService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.sovity.chatapp.service

import de.sovity.chatapp.model.ConnectorCreateDto
import de.sovity.chatapp.model.ConnectorDto
import de.sovity.chatapp.model.MessageDto
import de.sovity.chatapp.model.MessageNotificationDto
import de.sovity.chatapp.model.MessageSendDto

interface EdcService {
fun getConnectors(): List<ConnectorDto>
fun createConnector(dto: ConnectorCreateDto): ConnectorDto
fun getMessages(connectorId: String): List<MessageDto>
fun sendMessage(string: String, dto: MessageSendDto): MessageDto
fun receiveNotification(string: String, dto: MessageNotificationDto)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.sovity.chatapp.service

import de.sovity.chatapp.model.ConnectorCreateDto
import de.sovity.chatapp.model.ConnectorDto
import de.sovity.chatapp.model.ConnectorStatusDto
import de.sovity.chatapp.model.MessageDirectionDto
import de.sovity.chatapp.model.MessageDto
import de.sovity.chatapp.model.MessageNotificationDto
import de.sovity.chatapp.model.MessageSendDto
import de.sovity.chatapp.model.MessageStatusDto
import jakarta.enterprise.context.ApplicationScoped
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.UUID

@ApplicationScoped
class FakeEdcService : EdcService {

val connectors = mutableSetOf<ConnectorDto>()
val messages = mutableMapOf<String, MutableList<MessageDto>>()

override fun getConnectors(): List<ConnectorDto> {
return connectors.toList()
}

override fun createConnector(connectorCreateDto: ConnectorCreateDto): ConnectorDto {
val connector = ConnectorDto(
UUID.randomUUID().toString(),
connectorCreateDto.participantId,
connectorCreateDto.connectorEndpoint,
ConnectorStatusDto.ONLINE
)

connectors.add(connector)

return connector
}

override fun getMessages(connectorId: String): List<MessageDto> {
return messages[connectorId] ?: listOf()
}

override fun sendMessage(
recievingConnectorId: String,
messageSendDto: MessageSendDto
): MessageDto {
val message = MessageDto(
UUID.randomUUID().toString(),
ZonedDateTime.now(ZoneOffset.UTC).toString(),
messageSendDto.message,
MessageDirectionDto.INCOMING,
MessageStatusDto.OK
)

val messages = messages.computeIfAbsent(recievingConnectorId) { mutableListOf() }
messages.add(message)

return message
}

override fun receiveNotification(edcBpn: String, notification: MessageNotificationDto) {
TODO("Not yet implemented")
}
}