fix: menu items CRUD #44
+19
-2
@@ -26,6 +26,8 @@
|
|||||||
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
||||||
<skipITs>true</skipITs>
|
<skipITs>true</skipITs>
|
||||||
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
||||||
|
<org.mapstruct.version>1.6.3</org.mapstruct.version>
|
||||||
|
<org.projectlombok.version>1.18.46</org.projectlombok.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -54,9 +56,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.46</version>
|
<version>${org.projectlombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkiverse.mapstruct</groupId>
|
||||||
|
<artifactId>quarkus-mapstruct</artifactId>
|
||||||
|
<version>1.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>${org.mapstruct.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.datafaker</groupId>
|
<groupId>net.datafaker</groupId>
|
||||||
<artifactId>datafaker</artifactId>
|
<artifactId>datafaker</artifactId>
|
||||||
@@ -140,10 +152,15 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<parameters>true</parameters>
|
<parameters>true</parameters>
|
||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>${org.mapstruct.version}</version>
|
||||||
|
</path>
|
||||||
<path>
|
<path>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.46</version>
|
<version>${org.projectlombok.version}</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.drinkool.dtos;
|
||||||
|
|
||||||
|
import com.drinkool.entities.MenuItemEntity;
|
||||||
|
import org.mapstruct.BeanMapping;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.MappingTarget;
|
||||||
|
import org.mapstruct.NullValuePropertyMappingStrategy;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "cdi")
|
||||||
|
public interface DtoMapper {
|
||||||
|
@BeanMapping(
|
||||||
|
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
|
||||||
|
)
|
||||||
|
void updateMenuItemToEntity(
|
||||||
|
UpdateMenuItem input,
|
||||||
|
@MappingTarget MenuItemEntity entity
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.drinkool.dtos;
|
||||||
|
|
||||||
|
import com.drinkool.interfaces.EntityInterface;
|
||||||
|
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||||
|
import java.util.UUID;
|
||||||
|
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 UpdateMenuItem extends AddMenuItem implements EntityInterface {
|
||||||
|
|
||||||
|
UUID id;
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ 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.AddMenuItem;
|
||||||
|
import com.drinkool.dtos.DtoMapper;
|
||||||
|
import com.drinkool.dtos.UpdateMenuItem;
|
||||||
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;
|
||||||
@@ -23,6 +25,9 @@ import org.eclipse.microprofile.reactive.messaging.Incoming;
|
|||||||
@GraphQLApi
|
@GraphQLApi
|
||||||
public class EateryService {
|
public class EateryService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DtoMapper dtoMapper;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
HttpServerRequest request;
|
HttpServerRequest request;
|
||||||
|
|
||||||
@@ -58,6 +63,23 @@ public class EateryService {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mutation("updateMenuItem")
|
||||||
|
@RolesAllowed(Role.Manager)
|
||||||
|
@Transactional
|
||||||
|
public MenuItemEntity updateMenuItem(
|
||||||
|
@Name("menuItem") UpdateMenuItem menuItem
|
||||||
|
) {
|
||||||
|
MenuItemEntity item = MenuItemEntity.findById(menuItem.getId());
|
||||||
|
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
dtoMapper.updateMenuItemToEntity(menuItem, item);
|
||||||
|
|
||||||
|
item.persist();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
@Query("menuItemsByEatery")
|
@Query("menuItemsByEatery")
|
||||||
public List<MenuItemEntity> getMenuItemsByEatery(
|
public List<MenuItemEntity> getMenuItemsByEatery(
|
||||||
@Name("eateryId") UUID eateryId
|
@Name("eateryId") UUID eateryId
|
||||||
|
|||||||
@@ -271,4 +271,42 @@ public class EateryServiceTest {
|
|||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
.body("data.menuItemsByEatery", hasSize(0)); // Phải trả về List rỗng như code bạn viết
|
.body("data.menuItemsByEatery", hasSize(0)); // Phải trả về List rỗng như code bạn viết
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateMenuItem_Success() {
|
||||||
|
String mutation = """
|
||||||
|
mutation updateMenuItem($menuItem: UpdateMenuItemInput!) {
|
||||||
|
updateMenuItem(menuItem: $menuItem) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
String newValue = "Phở Bò";
|
||||||
|
|
||||||
|
Map<String, Object> menuItemData = new HashMap<>();
|
||||||
|
menuItemData.put("id", lastSavedName);
|
||||||
|
menuItemData.put("name", newValue);
|
||||||
|
|
||||||
|
Map<String, Object> variables = new HashMap<>();
|
||||||
|
variables.put("menuItem", menuItemData);
|
||||||
|
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("query", mutation);
|
||||||
|
requestBody.put("variables", variables);
|
||||||
|
|
||||||
|
given()
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.header(InternalValue.role, Role.Customer)
|
||||||
|
.header(InternalValue.userId, lastOwnerId)
|
||||||
|
.body(requestBody)
|
||||||
|
.when()
|
||||||
|
.post("/graphql")
|
||||||
|
.then()
|
||||||
|
.body("data.updateMenuItem.name", is(newValue))
|
||||||
|
.body("data.updateMenuItem.id", is(lastSavedId))
|
||||||
|
.statusCode(200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<project
|
<project
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
>
|
>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -63,4 +63,4 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.drinkool.interfaces;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface EateryInterface {
|
||||||
|
UUID getOwnerId();
|
||||||
|
void setOwnerId(UUID x);
|
||||||
|
String getName();
|
||||||
|
void setName(String x);
|
||||||
|
boolean getIsVerified();
|
||||||
|
void setIsVerified(boolean x);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.drinkool.interfaces;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface EntityInterface {
|
||||||
|
UUID getId();
|
||||||
|
void setId(UUID x);
|
||||||
|
}
|
||||||
@@ -3,6 +3,6 @@ package com.drinkool.interfaces;
|
|||||||
public interface MenuItemInterface {
|
public interface MenuItemInterface {
|
||||||
String getName();
|
String getName();
|
||||||
void setName(String x);
|
void setName(String x);
|
||||||
double getPrice();
|
double getPrice();
|
||||||
void setPrice(double x);
|
void setPrice(double x);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user