chore: update
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.30</version>
|
<version>1.18.46</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -139,6 +139,13 @@
|
|||||||
<version>${compiler-plugin.version}</version>
|
<version>${compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<parameters>true</parameters>
|
<parameters>true</parameters>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.46</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.drinkool.dtos;
|
||||||
|
|
||||||
|
import com.drinkool.interfaces.MenuItemInterface;
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.eclipse.microprofile.graphql.Input;
|
||||||
|
|
||||||
|
@Input
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RegisterForReflection
|
||||||
|
public class AddMenuItem implements MenuItemInterface {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private double price;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.drinkool.services;
|
|||||||
|
|
||||||
import com.drinkool.InternalValue;
|
import com.drinkool.InternalValue;
|
||||||
import com.drinkool.Role;
|
import com.drinkool.Role;
|
||||||
|
import com.drinkool.dtos.AddMenuItem;
|
||||||
import com.drinkool.dtos.event.ManagerCreate;
|
import com.drinkool.dtos.event.ManagerCreate;
|
||||||
import com.drinkool.entities.EateryEntity;
|
import com.drinkool.entities.EateryEntity;
|
||||||
import com.drinkool.entities.MenuItemEntity;
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
@@ -46,16 +47,13 @@ public class EateryService {
|
|||||||
@Mutation("addMenuItem")
|
@Mutation("addMenuItem")
|
||||||
@RolesAllowed(Role.Manager)
|
@RolesAllowed(Role.Manager)
|
||||||
@Transactional
|
@Transactional
|
||||||
public MenuItemEntity addMenuItem(
|
public MenuItemEntity addMenuItem(@Name("menuItem") AddMenuItem menuItem) {
|
||||||
@Name("name") String name,
|
|
||||||
@Name("price") double price
|
|
||||||
) {
|
|
||||||
String ownerId = request.getHeader(InternalValue.userId);
|
String ownerId = request.getHeader(InternalValue.userId);
|
||||||
|
|
||||||
EateryEntity eatery = EateryEntity.findByOwnerId(ownerId);
|
EateryEntity eatery = EateryEntity.findByOwnerId(ownerId);
|
||||||
if (eatery == null) return null;
|
if (eatery == null) return null;
|
||||||
|
|
||||||
MenuItemEntity item = MenuItemEntity.create(eatery, name, price);
|
MenuItemEntity item = MenuItemEntity.create(eatery, menuItem);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import static org.hamcrest.Matchers.hasSize;
|
|||||||
|
|
||||||
import com.drinkool.InternalValue;
|
import com.drinkool.InternalValue;
|
||||||
import com.drinkool.Role;
|
import com.drinkool.Role;
|
||||||
|
import com.drinkool.dtos.AddMenuItem;
|
||||||
import com.drinkool.dtos.event.ManagerCreate;
|
import com.drinkool.dtos.event.ManagerCreate;
|
||||||
import com.drinkool.entities.EateryEntity;
|
import com.drinkool.entities.EateryEntity;
|
||||||
import com.drinkool.entities.MenuItemEntity;
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
@@ -19,6 +20,8 @@ import jakarta.enterprise.context.control.ActivateRequestContext;
|
|||||||
import jakarta.enterprise.inject.Any;
|
import jakarta.enterprise.inject.Any;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.datafaker.Faker;
|
import net.datafaker.Faker;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
@@ -81,8 +84,10 @@ public class EateryServiceTest {
|
|||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
MenuItemEntity.create(
|
MenuItemEntity.create(
|
||||||
eatery,
|
eatery,
|
||||||
|
new AddMenuItem(
|
||||||
faker.food().dish(),
|
faker.food().dish(),
|
||||||
faker.number().randomDouble(2, 10, 100)
|
faker.number().randomDouble(2, 10, 100)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,19 +131,22 @@ public class EateryServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAddMenuItemSuccess() {
|
public void testAddMenuItemSuccess() {
|
||||||
String mutation =
|
String mutation =
|
||||||
"mutation addMenuItem($name: String!, $price: Float!) {" +
|
"mutation addMenuItem($menuItem: AddMenuItemInput!) {" +
|
||||||
" addMenuItem(name: $name, price: $price) {" +
|
" addMenuItem(menuItem: $menuItem) {" +
|
||||||
" id" +
|
" id" +
|
||||||
" name" +
|
" name" +
|
||||||
" price" +
|
" price" +
|
||||||
" }" +
|
" }" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
java.util.Map<String, Object> variables = new java.util.HashMap<>();
|
Map<String, Object> menuItemData = new HashMap<>();
|
||||||
variables.put("name", "Trà Sữa");
|
menuItemData.put("name", "Trà Sữa");
|
||||||
variables.put("price", 30000.0);
|
menuItemData.put("price", 30000.0);
|
||||||
|
|
||||||
java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
|
variables.put("menuItem", menuItemData);
|
||||||
|
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", mutation);
|
requestBody.put("query", mutation);
|
||||||
requestBody.put("variables", variables);
|
requestBody.put("variables", variables);
|
||||||
|
|
||||||
@@ -158,19 +166,22 @@ public class EateryServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAddMenuItemFailInvalidRole() {
|
public void testAddMenuItemFailInvalidRole() {
|
||||||
String mutation =
|
String mutation =
|
||||||
"mutation addMenuItem($name: String!, $price: Float!) {" +
|
"mutation addMenuItem($menuItem: AddMenuItemInput!) {" +
|
||||||
" addMenuItem(name: $name, price: $price) {" +
|
" addMenuItem(menuItem: $menuItem) {" +
|
||||||
" id" +
|
" id" +
|
||||||
" name" +
|
" name" +
|
||||||
" price" +
|
" price" +
|
||||||
" }" +
|
" }" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
java.util.Map<String, Object> variables = new java.util.HashMap<>();
|
Map<String, Object> menuItemData = new HashMap<>();
|
||||||
variables.put("name", "Trà Sữa");
|
menuItemData.put("name", "Trà Sữa");
|
||||||
variables.put("price", 30000.0);
|
menuItemData.put("price", 30000.0);
|
||||||
|
|
||||||
java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
|
variables.put("menuItem", menuItemData);
|
||||||
|
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", mutation);
|
requestBody.put("query", mutation);
|
||||||
requestBody.put("variables", variables);
|
requestBody.put("variables", variables);
|
||||||
|
|
||||||
@@ -190,7 +201,7 @@ public class EateryServiceTest {
|
|||||||
String mutation =
|
String mutation =
|
||||||
"mutation { addMenuItem(name: \"Coffee\", price: 20000.0) { id } }";
|
"mutation { addMenuItem(name: \"Coffee\", price: 20000.0) { id } }";
|
||||||
|
|
||||||
java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", mutation);
|
requestBody.put("query", mutation);
|
||||||
|
|
||||||
given()
|
given()
|
||||||
@@ -216,10 +227,10 @@ public class EateryServiceTest {
|
|||||||
" }" +
|
" }" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
java.util.Map<String, Object> variables = new java.util.HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("id", lastSavedId.toString());
|
variables.put("id", lastSavedId.toString());
|
||||||
|
|
||||||
java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", query);
|
requestBody.put("query", query);
|
||||||
requestBody.put("variables", variables);
|
requestBody.put("variables", variables);
|
||||||
|
|
||||||
@@ -244,10 +255,10 @@ public class EateryServiceTest {
|
|||||||
" }" +
|
" }" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
java.util.Map<String, Object> variables = new java.util.HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("id", randomId);
|
variables.put("id", randomId);
|
||||||
|
|
||||||
java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("query", query);
|
requestBody.put("query", query);
|
||||||
requestBody.put("variables", variables);
|
requestBody.put("variables", variables);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.30</version>
|
<version>1.18.46</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.drinkool.dtos;
|
|
||||||
|
|
||||||
import com.drinkool.interfaces.MenuItemInterface;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class AddMenuItem implements MenuItemInterface {
|
|
||||||
|
|
||||||
String name;
|
|
||||||
double price;
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ package com.drinkool.interfaces;
|
|||||||
|
|
||||||
public interface MenuItemInterface {
|
public interface MenuItemInterface {
|
||||||
String getName();
|
String getName();
|
||||||
void setName(String name);
|
void setName(String x);
|
||||||
double getPrice();
|
double getPrice();
|
||||||
void setPrice(double price);
|
void setPrice(double x);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user