blob: 677fd26c3d1f3e00b71288852c29a4f265019851 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package dev.submelon.view;
import java.util.List;
import org.bson.types.ObjectId;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;
import dev.submelon.exceptions.ItemNotFoundException;
import dev.submelon.model.PantryItem;
import io.smallrye.mutiny.Uni;
@GraphQLApi
public class PantryItemResource {
@Query("allItems")
@Description("Get all items stored in the pantry")
public Uni<List<PantryItem>> getItems() {
return PantryItem.findAll().list();
}
@Query
@Description("Get an item stored in the pantry")
public Uni<PantryItem> getItem(@Name("itemId") String id) {
ObjectId _id = new ObjectId(id);
return PantryItem.findById(_id);
}
@Mutation
@Description("Store an item in the pantry")
public Uni<PantryItem> storeItem(PantryItem item) {
return PantryItem.persist(item).replaceWith(item);
}
@Mutation
@Description("Remove an item from the pantry")
public Uni<Boolean> deleteItem(String id) {
ObjectId _id = new ObjectId(id);
return PantryItem.deleteById(_id)
.onFailure()
.transform(ItemNotFoundException::new);
}
}
|