Skip to content

Commit

Permalink
last fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phuuthanh-dev committed Jul 21, 2024
2 parents b142158 + f905302 commit 1d3708a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public ResponseEntity<Transaction> setState(@PathVariable Integer id, @RequestPa
return ResponseEntity.ok().build();
}

@PutMapping("/set-state-with-code/{id}")
public ResponseEntity<Transaction> setStateTransactionWithCode(
@PathVariable Integer id,
@RequestParam String state,
@RequestParam String transactionCode,
@RequestParam String bankCode) {
transactionService.setTransactionStateWithCode(id, state, transactionCode, bankCode);
return ResponseEntity.ok().build();
}

@PutMapping("/set-method/{id}")
public ResponseEntity<Transaction> setMethod(@PathVariable Integer id, @RequestParam String method) {
transactionService.setTransactionMethod(id, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vn.webapp.backend.auction.dto.DisableUserRequest;
import vn.webapp.backend.auction.dto.RegisterAccountRequest;
import vn.webapp.backend.auction.dto.UserSpentResponse;
import vn.webapp.backend.auction.enums.AccountState;
Expand Down Expand Up @@ -72,6 +73,11 @@ public ResponseEntity<User> setState(@PathVariable Integer id, @RequestBody Acco
return ResponseEntity.ok().build();
}

@PutMapping("/set-disable/{id}")
public ResponseEntity<User> setDisable(@PathVariable Integer id, @RequestBody DisableUserRequest disableUserRequest) {
userService.setDisableAccount(id, disableUserRequest);
return ResponseEntity.ok().build();
}
@PostMapping("/staff/register")
public ResponseEntity<User> addStaff(
@RequestBody RegisterAccountRequest user) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package vn.webapp.backend.auction.dto;

import vn.webapp.backend.auction.enums.AccountState;

public record DisableUserRequest(
AccountState state,
String reason
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface UserRepository extends JpaRepository<User, Integer> {
"AND ah.time = (SELECT MAX(ah2.time) FROM AuctionHistory ah2 WHERE ah2.auction.id = :auctionId AND ah2.state='ACTIVE')")
Optional<User> findLatestUserInAuctionHistoryByAuctionId(@Param("auctionId") Integer auctionId);

@Query("SELECT a.user " +
@Query("SELECT a.jewelry.user " +
"FROM Auction a " +
"WHERE a.id = :auctionId ")
Optional<User> findOwnerByAuctionId(@Param("auctionId") Integer auctionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void confirmRequest(Integer requestId, Integer responderId) {
request.setStaff(responder);
} else if (responder.getRole().equals(Role.MEMBER)) {
request.getJewelry().setState(JewelryState.ACTIVE);
request.getJewelry().setIsHolding(false);
}

request.setConfirm(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface TransactionService {

void setTransactionState(Integer id, String state);

void setTransactionStateWithCode(Integer id, String state, String transactionCode, String bankCode);


void setTransactionMethod(Integer id, String method);

Page<Transaction> getTransactionsByUsername (String username, String assetName, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public void setTransactionState(Integer id, String state) {
existingTransaction.setPaymentTime(Timestamp.from(Instant.now()));
}

@Override
@Transactional
public void setTransactionStateWithCode(Integer id, String state, String transactionCode, String bankCode) {
var existingTransaction = transactionRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.AUCTION_NOT_FOUND));
existingTransaction.setState(TransactionState.valueOf(state));
existingTransaction.setPaymentTime(Timestamp.from(Instant.now()));
existingTransaction.setTransactionCode(transactionCode);
existingTransaction.setBankCode(bankCode);
}

@Override
@Transactional
public void setTransactionMethod(Integer id, String method) {
Expand Down Expand Up @@ -169,8 +180,8 @@ public User createTransactionForSeller(Integer auctionId) {
.feesIncurred(0.0)
.createDate(Timestamp.from(Instant.now()))
.type(TransactionType.PAYMENT_TO_SELLER)
.paymentMethod(PaymentMethod.BANKING)
.build();

transactionRepository.save(sellerTransaction);
}
return userSeller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import vn.webapp.backend.auction.dto.DisableUserRequest;
import vn.webapp.backend.auction.dto.RegisterAccountRequest;
import vn.webapp.backend.auction.dto.UserSpentResponse;
import vn.webapp.backend.auction.enums.AccountState;
Expand All @@ -19,6 +20,7 @@ public interface UserService {
List<User> getAllStaff();
User registerStaff(RegisterAccountRequest request);
void setAccountState(Integer id, AccountState state);
void setDisableAccount(Integer id, DisableUserRequest request);
User updateUser(User user);
Page<User> getMemberByFullNameContainingAndState(String fullName ,AccountState state, Pageable pageable);
Page<User> getStaffByFullNameContainingAndRoleAndState(String fullName, Role role, AccountState state , Pageable page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import vn.webapp.backend.auction.dto.DisableUserRequest;
import vn.webapp.backend.auction.dto.RegisterAccountRequest;
import vn.webapp.backend.auction.dto.UserSpentResponse;
import vn.webapp.backend.auction.enums.AccountState;
Expand Down Expand Up @@ -77,6 +78,14 @@ public void setAccountState(Integer id, AccountState state) {
existingUser.setState(state);
}

@Override
public void setDisableAccount(Integer id, DisableUserRequest request) {
var existingUser = userRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.USER_NOT_FOUND));
existingUser.setState(AccountState.DISABLE);
existingUser.setBanReason(request.reason());
}

@Override
public User updateUser(User user) {
var existingUser = userRepository.findById(user.getId())
Expand Down

0 comments on commit 1d3708a

Please sign in to comment.