Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

backend: add rest services #103

Merged
12 commits merged into from
Jun 10, 2024
Merged
2 changes: 1 addition & 1 deletion node/code/RIOT
3 changes: 0 additions & 3 deletions node/code/modules/display_handler/forg (1).c:Zone.Identifier

This file was deleted.

Binary file modified node/pcb/teamagotchi.zip
Binary file not shown.
36 changes: 36 additions & 0 deletions web_backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<jakarta.validation.version>3.0.2</jakarta.validation.version>
<jakarta.ws.rs.version>3.1.0</jakarta.ws.rs.version>
<lombok.version>1.18.32</lombok.version>
<mapstruct.version>1.6.0.Beta2</mapstruct.version>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -41,6 +42,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
Expand All @@ -53,6 +62,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand All @@ -78,6 +91,11 @@
<artifactId>jakarta.validation-api</artifactId>
<version>${jakarta.validation.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -112,6 +130,24 @@
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<!-- This is needed when using Lombok 1.18.16 and above -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
@ApplicationScoped
public class UcHandleLeshanEventsImpl implements UcHandleLeshanEvents {

@Override
public void handleRegistration(RegistrationDto dto) {
System.out.println("Registration: " + dto.registrationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import haw.teamagochi.backend.leshanclient.datatypes.events.CoaplogDto;
import haw.teamagochi.backend.leshanclient.datatypes.events.RegistrationDto;
import haw.teamagochi.backend.leshanclient.datatypes.events.UpdatedDto;
import io.quarkus.arc.profile.UnlessBuildProfile;
import io.quarkus.logging.Log;
import io.quarkus.runtime.Startup;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -17,6 +18,7 @@
/**
* Subscribes to Leshan events and passes them to {@link UcHandleLeshanEvents}.
*/
@UnlessBuildProfile("test")
@ApplicationScoped
public class LeshanEventListener {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
package haw.teamagochi.backend.device.logic.clients.rest;

import haw.teamagochi.backend.leshanclient.datatypes.rest.*;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import java.util.Set;
import org.eclipse.microprofile.rest.client.inject.RestClient;

/** Resource for {@link LeshanClientRestclient}. */
@Path("/")
/**
* Resource for {@link LeshanClientRestclient}.
*/
public class LeshanClientResource {

@RestClient LeshanClientRestclient clientRestclient;

@GET
public Set<ClientDto> getClients() {
return clientRestclient.getClients();
}

@GET
@Path("/clients/{endpoint}")
public ClientDto getClient(@PathParam("endpoint") String endpoint) {
return clientRestclient.getClient(endpoint);
}

@GET
@Path("/clients/{endpoint}/{object}")
public ObjectResponseDto getClientObject(
@PathParam("endpoint") String endpoint, @PathParam("object") Integer object) {
return clientRestclient.getClientObject(endpoint, object);
}

@GET
@Path("/clients/{endpoint}/{object}/{instance}")
public ObjectInstanceResponseDto getClientObjectInstance(
@PathParam("endpoint") String endpoint,
@PathParam("object") Integer object,
@PathParam("instance") Integer instance) {
return clientRestclient.getClientObjectInstance(endpoint, object, instance);
}

@GET
@Path("/clients/{endpoint}/{object}/{instance}/{resource}")
public ResourceResponseDto getClientResource(
@PathParam("endpoint") String endpoint,
@PathParam("object") Integer object,
Expand All @@ -50,8 +40,6 @@ public ResourceResponseDto getClientResource(
return clientRestclient.getClientResource(endpoint, object, instance, resource);
}

@GET
@Path("/objectspecs/{endpoint}")
public Set<ObjectspecDto> getClientObjectSpecifications(@PathParam("endpoint") String endpoint) {
return clientRestclient.getClientObjectSpecifications(endpoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ public interface LeshanClientRestclient {

@GET
@Path("/clients/{endpoint}/{object}")
ObjectResponseDto getClientObject(@PathParam("endpoint") String endpoint, @PathParam("object") Integer object);
ObjectResponseDto getClientObject(
@PathParam("endpoint") String endpoint, @PathParam("object") Integer object);

@GET
@Path("/clients/{endpoint}/{object}/{instance}")
ObjectInstanceResponseDto getClientObjectInstance(@PathParam("endpoint") String endpoint, @PathParam("object") Integer object, @PathParam("instance") Integer instance);
ObjectInstanceResponseDto getClientObjectInstance(
@PathParam("endpoint") String endpoint,
@PathParam("object") Integer object,
@PathParam("instance") Integer instance);

@GET
@Path("/clients/{endpoint}/{object}/{instance}/{resource}")
ResourceResponseDto getClientResource(@PathParam("endpoint") String endpoint, @PathParam("object") Integer object, @PathParam("instance") Integer instance, @PathParam("resource") Integer resource);
ResourceResponseDto getClientResource(
@PathParam("endpoint") String endpoint,
@PathParam("object") Integer object,
@PathParam("instance") Integer instance,
@PathParam("resource") Integer resource);

@GET
@Path("/objectspecs/{endpoint}")
Set<ObjectspecDto> getClientObjectSpecifications(@PathParam("endpoint") String endpoint);

// @GET
// @Path("/{id}")
// ClientDto getById(@PathParam("id") String id);

// @GET
// @Path("/{id}/{objectId}/{objectInstanceId}/{resourceId}")
// ClientDto getById(@PathParam("id") String id, @PathParam("objectId") Integer objectId, @PathParam("objectInstanceId") Integer objectInstanceId, @PathParam("resourceId") Integer resourceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,43 @@
public interface LeshanEventClient {

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(RegistrationEventFilter.class)
Multi<SseEvent<String>> registration();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(DeregistrationEventFilter.class)
Multi<SseEvent<String>> deregistration();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(UpdatedEventFilter.class)
Multi<SseEvent<String>> updated();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(SleepingEventFilter.class)
Multi<SseEvent<String>> sleeping();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(AwakeEventFilter.class)
Multi<SseEvent<String>> awake();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseEventFilter(CoaplogEventFilter.class)
Multi<SseEvent<String>> coaplog();

@GET
@Path("/")
@Produces(MediaType.SERVER_SENT_EVENTS)
Multi<SseEvent<String>> events();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,49 @@
import io.smallrye.mutiny.Multi;
import jakarta.inject.Singleton;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.resteasy.reactive.client.SseEvent;

/**
* Event resource for {@link LeshanEventClient}.
*/
@Path("/event")
@Singleton
public class LeshanEventResource {

@RestClient
LeshanEventClient eventClient;

@GET
@Path("/")
public Multi<SseEvent<String>> registration() {
return eventClient.registration();
}

@GET
@Path("/")
public Multi<SseEvent<String>> deregistration() {
return eventClient.deregistration();
}

@GET
@Path("/")
public Multi<SseEvent<String>> updated() {
return eventClient.updated();
}

@GET
@Path("/")
public Multi<SseEvent<String>> sleeping() {
return eventClient.sleeping();
}

@GET
@Path("/")
public Multi<SseEvent<String>> awake() {
return eventClient.awake();
}

@GET
@Path("/")
public Multi<SseEvent<String>> coaplog() {
return eventClient.coaplog();
}

@GET
@Path("/")
public Multi<SseEvent<String>> events() {
return eventClient.events();
}
Expand Down
Loading