Skip to content

Commit

Permalink
Merge pull request #120 from phuuthanh-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
phuuthanh-dev committed Jul 7, 2024
2 parents cba03b1 + 03037fe commit 7dbba12
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ public class AuctionController {
public ResponseEntity<Page<Auction>> getAllAuctionsSortedAndPaged(
@RequestParam(defaultValue = "startDate") String sortBy,
@RequestParam(required = false) String auctionName,
@RequestParam(defaultValue = "DELETED") AuctionState state,
@RequestParam(defaultValue = "ALL") String state,
@RequestParam(defaultValue = "0") Integer categoryId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "asc") String sortOrder) {
AuctionState auctionState = resolveAuctionState(state);
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
return ResponseEntity.ok(auctionService.getAllAuctions(state, pageable, auctionName, categoryId));
return ResponseEntity.ok(auctionService.getAllAuctions(auctionState, pageable, auctionName, categoryId));
}

@GetMapping("/get-by-day/{startDate}/{endDate}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import vn.webapp.backend.auction.dto.ManagerRequestApproval;
import vn.webapp.backend.auction.dto.StaffRequestApproval;
import vn.webapp.backend.auction.dto.UserRequestApproval;
import vn.webapp.backend.auction.enums.AuctionState;
import vn.webapp.backend.auction.enums.Role;
import vn.webapp.backend.auction.model.RequestApproval;
import vn.webapp.backend.auction.service.request_approval.RequestApprovalService;
Expand Down Expand Up @@ -59,6 +60,7 @@ public ResponseEntity<Page<RequestApproval>> getRequestByRoleOfSender(
return ResponseEntity.ok(requestApprovalService.getRequestBySenderRole(role,jewelryName,category,pageable));
}


@GetMapping("/confirm-by-member/{memberId}")
public ResponseEntity<Page<RequestApproval>> getRequestNeedMemberConfirm(
@PathVariable Integer memberId,
Expand Down Expand Up @@ -105,7 +107,7 @@ public ResponseEntity<Page<RequestApproval>> getRequestPassed(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(required = false) String jewelryName,
@RequestParam String category,
@RequestParam(required = false) String category,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "asc") String sortOrder) {
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vn.webapp.backend.auction.dto.UserTransactionResponse;
import vn.webapp.backend.auction.enums.AuctionState;
import vn.webapp.backend.auction.enums.TransactionState;
import vn.webapp.backend.auction.enums.TransactionType;
import vn.webapp.backend.auction.model.Transaction;
Expand Down Expand Up @@ -58,11 +59,12 @@ public ResponseEntity<Page<Transaction>> getTransactionByTypeAndState(
@RequestParam(required = false) String userName,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "SUCCEED") TransactionState state,
@RequestParam(defaultValue = "SUCCEED") String state,
@RequestParam(defaultValue = "desc") String sortOrder) {
TransactionState transactionState = resolveTransactionState(state);
Sort.Direction direction = (sortOrder.equalsIgnoreCase("desc")) ? Sort.Direction.DESC : Sort.Direction.ASC;
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
return ResponseEntity.ok(transactionService.getTransactionByTypeAndState(type,userName, state, pageable));
return ResponseEntity.ok(transactionService.getTransactionByTypeAndState(type, userName, transactionState, pageable));
}

@GetMapping("/get-handover")
Expand Down Expand Up @@ -112,4 +114,12 @@ public ResponseEntity<Transaction> setMethod(@PathVariable Integer id, @RequestP
public ResponseEntity<List<Transaction>> createTransactionForWinnerIfNotExist(@PathVariable Integer userId) {
return ResponseEntity.ok(transactionService.createTransactionForWinnerIfNotExists(userId));
}

private TransactionState resolveTransactionState(String state) {
if ("ALL".equalsIgnoreCase(state)) {
return null;
} else {
return TransactionState.valueOf(state);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/vn/webapp/backend/auction/model/Jewelry.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Jewelry {
@Column(name = "weight", nullable = false)
private Double weight;

@Column(name = "is_holding", nullable = false)
@Column(name = "is_holding", nullable = true)
private Boolean isHolding;

@Column(name = "state", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public interface AuctionRepository extends JpaRepository<Auction, Integer> {
List<Auction> findByState(@Param("auctionState") AuctionState auctionState, @Param("auctionName") String auctionName);

@Query("SELECT a FROM Auction a WHERE " +
"((:auctionState = 'DELETED' AND a.state != 'DELETED') " +
"OR (:auctionState != '' AND a.state = :auctionState)) " +
"AND (:categoryId = 0 OR a.jewelry.category.id = :categoryId) AND (:auctionName IS NULL OR a.name LIKE %:auctionName%)")
"(:auctionState IS NULL OR a.state = :auctionState) " +
"AND (:categoryId = 0 OR a.jewelry.category.id = :categoryId) " +
"AND (:auctionName IS NULL OR a.name LIKE %:auctionName%)")
Page<Auction> findByStateAndCategoryNotDeletedOrEmptyState(
@Param("auctionState") AuctionState auctionState,
@Param("auctionName") String auctionName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,32 @@


public interface RequestApprovalRepository extends JpaRepository<RequestApproval, Integer> {
@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = :role AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) AND (:category IS NULL OR ra.jewelry.category.name =:category) AND ra.isConfirm = false AND ra.state = 'ACTIVE'")
Page<RequestApproval> findRequestApprovalBySenderRole(@Param("role") Role role,@Param("jewelryName") String jewelryName,@Param("category") String category, Pageable pageable);
@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = :role " +
"AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) " +
"AND (:category IS NULL OR ra.jewelry.category.name = :category) " +
"AND ra.isConfirm = false AND ra.state = 'ACTIVE'")
Page<RequestApproval> findRequestApprovalBySenderRole(
@Param("role") Role role,
@Param("jewelryName") String jewelryName,
@Param("category") String category,
Pageable pageable
);

@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' AND ra.isConfirm = false AND ra.jewelry.user.id = :memberId AND ra.state = 'ACTIVE'")
Page<RequestApproval> findRequestNeedConfirmByMember(@Param("memberId") Integer memberId, Pageable pageable);

@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.id = :id AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%)")
Page<RequestApproval> findRequestApprovalByUserId(@Param("id") Integer id, @Param("jewelryName") String jewelryName,Pageable pageable);

@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) AND (:category IS NULL OR ra.jewelry.category.name =:category) AND ra.isConfirm = true AND ra.state = 'ACTIVE' AND ra.jewelry.state = 'ACTIVE' AND ra.jewelry.isHolding = true")
Page<RequestApproval> findRequestApprovalPassed(@Param("jewelryName") String jewelryName,@Param("category") String category, Pageable pageable);
@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' " +
"AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) " +
"AND (:category IS NULL OR ra.jewelry.category.name = :category) " +
"AND ra.isConfirm = true AND ra.state = 'ACTIVE' " +
"AND ra.jewelry.state = 'ACTIVE' AND ra.jewelry.isHolding = true")
Page<RequestApproval> findRequestApprovalPassed(
@Param("jewelryName") String jewelryName,
@Param("category") String category,
Pageable pageable
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ public interface TransactionRepository extends JpaRepository<Transaction, Intege
@Query("SELECT t FROM Transaction t WHERE t.user.username = :username")
Page<Transaction> findTransactionsByUsername(@Param("username") String username, Pageable pageable);

@Query("SELECT t FROM Transaction t WHERE t.type = :typename AND (:userName IS NULL OR CONCAT(t.user.firstName, ' ', t.user.lastName) LIKE %:userName%) AND t.state=:state")
Page<Transaction> findTransactionByTypeAndState(@Param("typename") TransactionType typename,@Param("userName") String userName, @Param("state") TransactionState state, Pageable pageable);

@Query("SELECT t FROM Transaction t WHERE t.type = :typename " +
"AND (:userName IS NULL OR CONCAT(t.user.firstName, ' ', t.user.lastName) LIKE %:userName%) " +
"AND (:state IS NULL OR t.state = :state)")
Page<Transaction> findTransactionByTypeAndState(
@Param("typename") TransactionType typename,
@Param("userName") String userName,
@Param("state") TransactionState state,
Pageable pageable
);
@Query("SELECT t FROM Transaction t WHERE t.paymentMethod IS NOT NULL AND t.type = :typename AND (:jewelryName IS NULL OR t.auction.jewelry.name LIKE %:jewelryName%) AND t.auction.jewelry.state = 'AUCTION' AND t.auction.jewelry.isHolding= true")
Page<Transaction> findTransactionHandover(@Param("typename") TransactionType typename , @Param("jewelryName") String jewelryName, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public List<Auction> findAuctionByName(String name) {

@Override
public Page<Auction> getAllAuctions(AuctionState state, Pageable pageable, String auctionName, Integer categoryId) {
System.out.println("state: " + state);
return auctionRepository.findByStateAndCategoryNotDeletedOrEmptyState(state,auctionName, pageable, categoryId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public void cancelRequest(CancelRequestApproval request) {

@Override
public Page<RequestApproval> getRequestBySenderRole(Role role, String jewelryName, String category, Pageable pageable) {
if (category.equals("Tất cả"))
return requestApprovalRepository.findRequestApprovalBySenderRole(role, jewelryName, null, pageable);
return requestApprovalRepository.findRequestApprovalBySenderRole(role, jewelryName, category, pageable);
}

Expand Down Expand Up @@ -159,6 +161,9 @@ public Page<RequestApproval> getRequestApprovalByUserId(Integer id, String jewel

@Override
public Page<RequestApproval> getRequestApprovalPassed(String jewelryName, String category, Pageable pageable) {
if (category.equals("Tất cả")) {
return requestApprovalRepository.findRequestApprovalPassed(jewelryName, null, pageable);
}
return requestApprovalRepository.findRequestApprovalPassed(jewelryName, category, pageable);
}

Expand Down

0 comments on commit 7dbba12

Please sign in to comment.