Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #61
This commit was merged in pull request #61.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.drinkool.dtos;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.microprofile.graphql.NonNull;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.eclipse.microprofile.graphql.NonNull;
|
||||
public class CreateShift {
|
||||
|
||||
@NonNull
|
||||
public Date date;
|
||||
public LocalDate date;
|
||||
|
||||
@NonNull
|
||||
public LocalTime startTime;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.drinkool.dtos;
|
||||
|
||||
import com.drinkool.entities.MenuItemEntity;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.lib.dtos.SendReview;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.mapstruct.BeanMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.lib.entities.BaseEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -2,8 +2,12 @@ package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.dtos.AddMenuItem;
|
||||
import com.drinkool.interfaces.MenuItemInterface;
|
||||
import com.drinkool.lib.entities.BaseEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.interfaces.ReviewInterface;
|
||||
import com.drinkool.lib.entities.BaseEntity;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.UUID;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -17,6 +16,7 @@ import lombok.Setter;
|
||||
@Table(name = "reviews")
|
||||
public class ReviewEntity extends BaseEntity implements ReviewInterface {
|
||||
|
||||
@Column(nullable = true)
|
||||
public UUID reviewerId;
|
||||
|
||||
public UUID eateryId;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.lib.entities.BaseEntity;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -9,9 +8,9 @@ import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@@ -23,7 +22,7 @@ public class ShiftEntity extends BaseEntity {
|
||||
public EateryEntity eatery;
|
||||
|
||||
@Column(nullable = false)
|
||||
public Date date;
|
||||
public LocalDate date;
|
||||
|
||||
@Column(nullable = false)
|
||||
public LocalTime startTime;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.lib.entities.BaseEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
@@ -30,10 +29,11 @@ public class ShiftRegistrationEntity extends BaseEntity {
|
||||
ShiftEntity registratingShift
|
||||
) {
|
||||
return list(
|
||||
"staffId = ?1 and shift.startTime < ?2 and shift.endTime > ?3",
|
||||
"staffId = ?1 and shift.startTime < ?2 and shift.endTime > ?3 and shift.date = ?4",
|
||||
staffId,
|
||||
registratingShift.endTime,
|
||||
registratingShift.startTime
|
||||
registratingShift.startTime,
|
||||
registratingShift.date
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.drinkool.filters;
|
||||
|
||||
import com.drinkool.lib.utils.BaseHeaderAuthentication;
|
||||
import com.drinkool.BaseHeaderAuthentication;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.drinkool.dtos.DtoMapper;
|
||||
import com.drinkool.dtos.UpdateMenuItem;
|
||||
import com.drinkool.entities.EateryEntity;
|
||||
import com.drinkool.entities.MenuItemEntity;
|
||||
import com.drinkool.lib.dtos.event.ManagerCreate;
|
||||
import com.drinkool.dtos.event.ManagerCreate;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@@ -4,12 +4,11 @@ import com.drinkool.InternalValue;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.DtoMapper;
|
||||
import com.drinkool.dtos.SendReview;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.enums.SortBy;
|
||||
import com.drinkool.lib.dtos.SendReview;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
@@ -50,14 +49,14 @@ public class ReviewService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@RolesAllowed(Role.Customer)
|
||||
@Transactional
|
||||
public Response receiveReview(SendReview input) {
|
||||
UUID reviewerId = UUID.fromString(request.getHeader(InternalValue.userId));
|
||||
String userId = request.getHeader(InternalValue.userId);
|
||||
|
||||
try {
|
||||
ReviewEntity entity = dtoMapper.toReviewEntity(input);
|
||||
entity.setReviewerId(reviewerId);
|
||||
|
||||
if (userId != null) entity.setReviewerId(UUID.fromString(userId));
|
||||
|
||||
entity.persist();
|
||||
|
||||
|
||||
@@ -154,6 +154,8 @@ public class ShiftService {
|
||||
throw new GraphQLException("InvalidEndTime");
|
||||
}
|
||||
|
||||
shift.persist();
|
||||
|
||||
return shift;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.UUID;
|
||||
import net.datafaker.Faker;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
public class ReviewEntityTest {
|
||||
|
||||
private final Faker faker = new Faker();
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testCreateReview() {
|
||||
UUID testReviewerId = UUID.randomUUID();
|
||||
UUID testEateryId = UUID.randomUUID();
|
||||
String comment = faker.famousLastWords().lastWords();
|
||||
int rating = faker.random().nextInt(1, 5);
|
||||
|
||||
ReviewEntity savedReview = new ReviewEntity(
|
||||
testReviewerId,
|
||||
testEateryId,
|
||||
rating,
|
||||
comment
|
||||
);
|
||||
|
||||
savedReview.persist();
|
||||
|
||||
// 3. Kiểm chứng (Assert)
|
||||
Assertions.assertNotNull(
|
||||
savedReview,
|
||||
"Thực thể Review sau khi tạo không được null"
|
||||
);
|
||||
Assertions.assertEquals(
|
||||
testReviewerId,
|
||||
savedReview.reviewerId,
|
||||
"Reviewer ID không khớp"
|
||||
);
|
||||
Assertions.assertEquals(
|
||||
testEateryId,
|
||||
savedReview.eateryId,
|
||||
"Eatery ID không khớp"
|
||||
);
|
||||
Assertions.assertEquals(rating, savedReview.rating, "Rating không khớp");
|
||||
Assertions.assertEquals(comment, savedReview.comment, "Comment không khớp");
|
||||
|
||||
Assertions.assertNotNull(
|
||||
savedReview.id,
|
||||
"ID phải được tự động sinh ra sau khi persist"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import com.drinkool.Role;
|
||||
import com.drinkool.dtos.AddMenuItem;
|
||||
import com.drinkool.entities.EateryEntity;
|
||||
import com.drinkool.entities.MenuItemEntity;
|
||||
import com.drinkool.lib.dtos.event.ManagerCreate;
|
||||
import com.drinkool.dtos.event.ManagerCreate;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.smallrye.reactive.messaging.memory.InMemoryConnector;
|
||||
|
||||
@@ -7,10 +7,10 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
import com.drinkool.InternalValue;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.SendReview;
|
||||
import com.drinkool.entities.EateryEntity;
|
||||
import com.drinkool.entities.MenuItemEntity;
|
||||
import com.drinkool.entities.ReviewEntity;
|
||||
import com.drinkool.lib.dtos.SendReview;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -26,7 +26,7 @@ public class ReviewServiceTest {
|
||||
|
||||
private UUID savedEateryId;
|
||||
private String savedEateryName;
|
||||
private UUID savedOwnerId = UUID.randomUUID();
|
||||
private UUID savedOwnerId;
|
||||
|
||||
@BeforeEach
|
||||
@Transactional
|
||||
@@ -36,15 +36,17 @@ public class ReviewServiceTest {
|
||||
EateryEntity.deleteAll();
|
||||
|
||||
savedEateryName = faker.restaurant().name();
|
||||
savedOwnerId = UUID.randomUUID();
|
||||
|
||||
EateryEntity eatery = new EateryEntity();
|
||||
eatery = eatery.create(savedOwnerId, savedEateryName);
|
||||
|
||||
savedEateryId = eatery.id;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ReviewEntity entity = new ReviewEntity(
|
||||
UUID.randomUUID(),
|
||||
savedEateryId,
|
||||
eatery.id,
|
||||
faker.random().nextInt(1, 5),
|
||||
faker.famousLastWords().lastWords()
|
||||
);
|
||||
@@ -56,11 +58,15 @@ public class ReviewServiceTest {
|
||||
@Test
|
||||
void receiveReview_Success() {
|
||||
UUID reviewerId = UUID.randomUUID();
|
||||
UUID eateryId = UUID.randomUUID();
|
||||
String comment = faker.famousLastWords().lastWords();
|
||||
int rating = faker.random().nextInt(1, 5);
|
||||
|
||||
SendReview input = new SendReview(reviewerId, eateryId, rating, comment);
|
||||
SendReview input = new SendReview(
|
||||
reviewerId,
|
||||
savedEateryId,
|
||||
rating,
|
||||
comment
|
||||
);
|
||||
|
||||
given()
|
||||
.header(InternalValue.role, Role.Customer)
|
||||
|
||||
@@ -10,8 +10,8 @@ import com.drinkool.entities.ShiftEntity;
|
||||
import com.drinkool.entities.ShiftRegistrationEntity;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -208,7 +208,7 @@ public class ShiftServiceTest {
|
||||
) {
|
||||
ShiftEntity shift = new ShiftEntity();
|
||||
shift.eatery = eatery;
|
||||
shift.date = new Date();
|
||||
shift.date = LocalDate.now();
|
||||
shift.startTime = LocalTime.parse(start);
|
||||
shift.endTime = LocalTime.parse(end);
|
||||
shift.wage = 10000;
|
||||
|
||||
Reference in New Issue
Block a user