Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3:55 #86

Merged
merged 8 commits into from
Jun 19, 2024
Merged

3:55 #86

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vn.webapp.backend.auction.dto.SendJewelryFromUserRequest;
import vn.webapp.backend.auction.enums.JewelryState;
import vn.webapp.backend.auction.model.Jewelry;
import vn.webapp.backend.auction.model.Transaction;
import vn.webapp.backend.auction.service.jewelry.JewelryService;

import java.util.List;
Expand Down Expand Up @@ -83,6 +85,19 @@ public ResponseEntity<Page<Jewelry>> getJewelryInWaitlist(
return ResponseEntity.ok(jewelryService.getJewelriesInWaitList(pageable));
}

@GetMapping("/is-holding")
public ResponseEntity<Page<Jewelry>> getJewelryByHolding(
@RequestParam JewelryState state,
@RequestParam Boolean isHolding,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "asc") String sortOrder) {
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
return ResponseEntity.ok(jewelryService.getJewelryByStateAndIsHolding(state,isHolding,pageable));
}

@GetMapping("/in-handover-list")
public ResponseEntity<Page<Jewelry>> getJewelryInHandOver(
@RequestParam(defaultValue = "id") String sortBy,
Expand All @@ -105,4 +120,10 @@ public ResponseEntity<Jewelry> lastJewelry() {
}


@PutMapping("/set-holding/{id}")
public ResponseEntity<Jewelry> setHolding(@PathVariable Integer id) {
jewelryService.setHolding(id);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public ResponseEntity<Page<RequestApproval>> getRequestByRoleOfSender(
return ResponseEntity.ok(requestApprovalService.getRequestBySenderRole(role,pageable));
}

@GetMapping("/confirm-by-member/{memberId}")
public ResponseEntity<Page<RequestApproval>> getRequestNeedMemberConfirm(
@PathVariable Integer memberId,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "asc") String sortOrder) {
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
return ResponseEntity.ok(requestApprovalService.getRequestNeedConfirmByMember(memberId, pageable));
}

@PostMapping("/send-from-user")
public ResponseEntity<RequestApproval> newRequestJewelryFromUser(@RequestBody UserRequestApproval request) {
return ResponseEntity.ok(requestApprovalService.requestFromUser(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public enum JewelryState {
ACTIVE("Đã duyệt"),
APPROVING("Đang chờ duyệt"),
HIDDEN("Đã bị ẩn");
HIDDEN("Đã bị ẩn"),
AUCTION("Đang đấu giá");

private String displayName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface JewelryRepository extends JpaRepository<Jewelry, Integer> {
@Query("SELECT j FROM Jewelry j INNER JOIN Auction a ON j.id = a.jewelry.id WHERE a.state = 'FINISHED'")
Page<Jewelry> findJewelryInHandOver(Pageable pageable);

Page<Jewelry> findJewelryByStateAndIsHolding(JewelryState state, Boolean isHolding, Pageable pageable);

Page<Jewelry> findByUserUsername(String username, Pageable pageable);

@Query("SELECT j FROM Jewelry j ORDER BY j.id DESC")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ public interface RequestApprovalRepository extends JpaRepository<RequestApproval
@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = :role AND ra.isConfirm = false AND ra.state = 'ACTIVE'")
Page<RequestApproval> findRequestApprovalBySenderRole(@Param("role") Role role, 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")
Page<RequestApproval> findRequestApprovalByUserId(@Param("id") Integer id, Pageable pageable);

@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' AND ra.isConfirm = true AND ra.state = 'ACTIVE' AND ra.jewelry.state = 'APPROVING'")
@Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' AND ra.isConfirm = true AND ra.state = 'ACTIVE' AND ra.jewelry.state = 'ACTIVE' AND ra.jewelry.isHolding = true")
Page<RequestApproval> findRequestApprovalPassed( Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private Endpoints() {
public static final String[] PUBLIC_PUT_ENDPOINTS = {
"/api/v1/auction/set-state/**", "/api/v1/user","/api/v1/request-approval/set-state/**",
"/api/v1/request-approval/confirm/**", "/api/v1/request-approval/cancel-request",
"/api/v1/transaction/set-method/**"
"/api/v1/transaction/set-method/**","/api/v1/jewelry/set-holding/**"
};

public static final String[] MANAGER_GET_ENDPOINTS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Auction createNewAuction(AuctionRequest request) {
}
User staff = existStaff.get();
Jewelry jewelry = existJewelry.get();
jewelry.setState(JewelryState.ACTIVE);
jewelry.setState(JewelryState.AUCTION);
Auction auction = new Auction();

auction.setName(request.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import vn.webapp.backend.auction.dto.SendJewelryFromUserRequest;
import vn.webapp.backend.auction.enums.JewelryState;
import vn.webapp.backend.auction.model.Jewelry;

import java.util.List;
Expand All @@ -24,6 +25,8 @@ public interface JewelryService {

Page<Jewelry> getJewelriesInWaitList(Pageable pageable);

Page<Jewelry> getJewelryByStateAndIsHolding(JewelryState state, Boolean isHolding, Pageable pageable);

Page<Jewelry> getJewelriesInHandOver(Pageable pageable);

Page<Jewelry> getJewelriesByUsername(String username, Pageable pageable);
Expand All @@ -32,4 +35,6 @@ public interface JewelryService {

Jewelry getLatestJewelry();

Jewelry setHolding(Integer id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public Jewelry getLatestJewelry() {
return jewelryRepository.findLatestJewelry().get(0);
}

@Override
public Jewelry setHolding(Integer id) {
var existingJewelry = jewelryRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.JEWELRY_NOT_FOUND));
existingJewelry.setIsHolding(true);
return existingJewelry;
}

@Override
public List<Jewelry> getJewelryByUsername(String username) {
List<Jewelry> jewelryList = jewelryRepository.findJewelryByUsername(username);
Expand Down Expand Up @@ -119,6 +127,11 @@ public Page<Jewelry> getJewelriesInWaitList(Pageable pageable) {
return jewelryRepository.findJewelryInWaitlist(pageable);
}

@Override
public Page<Jewelry> getJewelryByStateAndIsHolding(JewelryState state, Boolean isHolding, Pageable pageable) {
return jewelryRepository.findJewelryByStateAndIsHolding(state,isHolding,pageable);
}

@Override
public Page<Jewelry> getJewelriesInHandOver(Pageable pageable) {
return jewelryRepository.findJewelryInHandOver(pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,32 @@ public void setRequestState(Integer id, Integer responderId, String state) {
if(existUser.getRole().equals(Role.STAFF)) {
existingRequest.setStaff(existUser);
}
if(existUser.getRole().equals(Role.MEMBER)) {
existingRequest.getJewelry().setState(JewelryState.HIDDEN);
}
existingRequest.setResponder(existUser);
existingRequest.setState(RequestApprovalState.valueOf(state));
existingRequest.setConfirm(false);
existingRequest.setResponseTime(Timestamp.from(Instant.now()));
}

@Override
public void confirmRequest(Integer id, Integer responderId) {
var existingRequest = requestApprovalRepository.findById(id)
public void confirmRequest(Integer requestId, Integer responderId) {
var request = requestApprovalRepository.findById(requestId)
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.REQUEST_APPROVAL_NOT_FOUND));
var existUser = userRepository.findById(responderId)

var responder = userRepository.findById(responderId)
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.USER_NOT_FOUND));
if(existUser.getRole().equals(Role.STAFF)) {
existingRequest.setStaff(existUser);

if (responder.getRole().equals(Role.STAFF)) {
request.setStaff(responder);
} else if (responder.getRole().equals(Role.MEMBER)) {
request.getJewelry().setState(JewelryState.ACTIVE);
}
existingRequest.setConfirm(true);
existingRequest.setResponder(existUser);
existingRequest.setResponseTime(Timestamp.from(Instant.now()));

request.setConfirm(true);
request.setResponder(responder);
request.setResponseTime(Timestamp.from(Instant.now()));
}

@Override
Expand Down Expand Up @@ -169,4 +177,9 @@ public Page<RequestApproval> getRequestApprovalByUserId(Integer id, Pageable pag
public Page<RequestApproval> getRequestApprovalPassed( Pageable pageable) {
return requestApprovalRepository.findRequestApprovalPassed(pageable);
}

@Override
public Page<RequestApproval> getRequestNeedConfirmByMember(Integer memberId, Pageable pageable) {
return requestApprovalRepository.findRequestNeedConfirmByMember(memberId,pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public interface RequestApprovalService {
RequestApproval requestFromManager(ManagerRequestApproval request);
Page<RequestApproval> getRequestApprovalByUserId(Integer id, Pageable pageable);
Page<RequestApproval> getRequestApprovalPassed(Pageable pageable);
Page<RequestApproval> getRequestNeedConfirmByMember(Integer memberId, Pageable pageable);
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spring.banner.location=banner.txt
# Config db
spring.datasource.url=jdbc:sqlserver://localhost:1433;encrypt=true;trustServerCertificate=true;databaseName=DB_AUCTION;
spring.datasource.username=sa
spring.datasource.password=Thanhth@nh1
spring.datasource.password=12345

# Config create table automatically
spring.jpa.hibernate.ddl-auto=update
Expand Down
Loading