chore: update
This commit is contained in:
+19
-2
@@ -26,6 +26,8 @@
|
||||
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<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>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -54,9 +56,19 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.46</version>
|
||||
<version>${org.projectlombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</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>
|
||||
<groupId>net.datafaker</groupId>
|
||||
<artifactId>datafaker</artifactId>
|
||||
@@ -140,10 +152,15 @@
|
||||
<configuration>
|
||||
<parameters>true</parameters>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.46</version>
|
||||
<version>${org.projectlombok.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</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.Role;
|
||||
import com.drinkool.dtos.AddMenuItem;
|
||||
import com.drinkool.dtos.DtoMapper;
|
||||
import com.drinkool.dtos.UpdateMenuItem;
|
||||
import com.drinkool.dtos.event.ManagerCreate;
|
||||
import com.drinkool.entities.EateryEntity;
|
||||
import com.drinkool.entities.MenuItemEntity;
|
||||
@@ -23,6 +25,9 @@ import org.eclipse.microprofile.reactive.messaging.Incoming;
|
||||
@GraphQLApi
|
||||
public class EateryService {
|
||||
|
||||
@Inject
|
||||
DtoMapper dtoMapper;
|
||||
|
||||
@Inject
|
||||
HttpServerRequest request;
|
||||
|
||||
@@ -58,6 +63,23 @@ public class EateryService {
|
||||
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")
|
||||
public List<MenuItemEntity> getMenuItemsByEatery(
|
||||
@Name("eateryId") UUID eateryId
|
||||
|
||||
@@ -271,4 +271,42 @@ public class EateryServiceTest {
|
||||
.statusCode(200)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user