volvox/service-chats/src/main/java/io/volvox/chats/ChatResource.java

69 lines
1.6 KiB
Java
Raw Normal View History

2021-11-26 01:01:34 +01:00
package io.volvox.chats;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import java.net.URI;
2021-11-27 00:54:51 +01:00
import javax.enterprise.context.ApplicationScoped;
2021-11-26 01:01:34 +01:00
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
2021-11-26 18:48:17 +01:00
@Path("/chats")
2021-11-27 00:54:51 +01:00
@ApplicationScoped
2021-11-26 01:01:34 +01:00
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ChatResource {
2021-11-27 00:54:51 +01:00
@Inject
ChatService chatService;
2021-11-26 01:01:34 +01:00
@GET
2021-11-27 00:54:51 +01:00
public Multi<Chat> list() {
return chatService.listAll();
2021-11-26 01:01:34 +01:00
}
@GET
@Path("/{id}")
2021-11-26 18:23:44 +01:00
public Uni<Chat> get(@PathParam("id") Long id) {
2021-11-27 00:54:51 +01:00
return chatService.get(id);
2021-11-26 01:01:34 +01:00
}
@POST
public Uni<Response> create(Chat chat) {
2021-11-27 00:54:51 +01:00
return chatService.create(chat)
2021-11-26 18:48:17 +01:00
.onItem().transform(inserted -> Response.created(URI.create("/chats/" + chat.id)).build());
2021-11-26 01:01:34 +01:00
}
@PUT
@Path("/{id}")
2021-11-26 18:23:44 +01:00
public Uni<Chat> update(@PathParam("id") Long id, Chat chat) {
2021-11-27 00:54:51 +01:00
return chatService.update(id, chat);
2021-11-26 01:01:34 +01:00
}
@DELETE
@Path("/{id}")
2021-11-26 18:23:44 +01:00
public Uni<Void> delete(@PathParam("id") Long id) {
2021-11-27 00:54:51 +01:00
return chatService.delete(id);
2021-11-26 01:01:34 +01:00
}
@GET
2021-11-27 00:54:51 +01:00
@Path("/by-username/{username}")
public Uni<Chat> resolveByUsername(@PathParam("username") String username) {
return chatService.resolveByUsername(username);
2021-11-26 01:01:34 +01:00
}
@GET
@Path("/count")
public Uni<Long> count() {
2021-11-27 00:54:51 +01:00
return chatService.count();
2021-11-26 01:01:34 +01:00
}
}