Skip to content

Commit 1449221

Browse files
Merge pull request #145 from phuuthanh-dev/develop
Develop
2 parents 25b2bd0 + 9e7ec25 commit 1449221

File tree

17 files changed

+237
-36
lines changed

17 files changed

+237
-36
lines changed

src/main/java/vn/webapp/backend/auction/controller/JewelryController.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import org.springframework.data.domain.Sort;
99
import org.springframework.http.ResponseEntity;
1010
import org.springframework.web.bind.annotation.*;
11+
import vn.webapp.backend.auction.dto.JewelryCreateRequest;
12+
import vn.webapp.backend.auction.dto.JewelryUpdateRequest;
1113
import vn.webapp.backend.auction.dto.SendJewelryFromUserRequest;
1214
import vn.webapp.backend.auction.enums.JewelryState;
1315
import vn.webapp.backend.auction.model.Jewelry;
16+
import vn.webapp.backend.auction.model.RequestApproval;
17+
import vn.webapp.backend.auction.model.User;
1418
import vn.webapp.backend.auction.service.jewelry.JewelryService;
1519

1620
import java.util.List;
@@ -43,19 +47,35 @@ public ResponseEntity<Page<Jewelry>> getAllJewelriesSortedAndPaged(
4347
return ResponseEntity.ok(jewelries);
4448
}
4549

50+
@GetMapping("/manager-list")
51+
public ResponseEntity<Page<Jewelry>> getAllJewelriesManager(
52+
@RequestParam(defaultValue = "id") String sortBy,
53+
@RequestParam(defaultValue = "0") int page,
54+
@RequestParam(defaultValue = "5") int size,
55+
@RequestParam(required = false) String jewelryName,
56+
@RequestParam(required = false) String category,
57+
@RequestParam JewelryState state,
58+
@RequestParam(defaultValue = "desc") String sortOrder) {
59+
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
60+
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
61+
Page<Jewelry> jewelries;
62+
jewelries = jewelryService.getJewelriesManager(state,jewelryName, category, pageable);
63+
return ResponseEntity.ok(jewelries);
64+
}
65+
4666
@GetMapping("/get-all")
4767
public ResponseEntity<List<Jewelry>> getAll() {
4868
return ResponseEntity.ok(jewelryService.getAll());
4969
}
5070

5171
@GetMapping("/get-by-category/{id}")
5272
public ResponseEntity<List<Jewelry>> getByCategory(@PathVariable Integer id) {
53-
return ResponseEntity.ok(jewelryService.getJeweriesByCategoryId(id));
73+
return ResponseEntity.ok(jewelryService.getJewelriesByCategoryId(id));
5474
}
5575

5676
@GetMapping("/get-by-name/{key}")
5777
public ResponseEntity<List<Jewelry>> getByCategory(@PathVariable String key) {
58-
return ResponseEntity.ok(jewelryService.getJeweriesByNameContain(key));
78+
return ResponseEntity.ok(jewelryService.getJewelriesByNameContain(key));
5979
}
6080

6181
@GetMapping("/id/{id}")
@@ -100,6 +120,19 @@ public ResponseEntity<Page<Jewelry>> getJewelryByHolding(
100120
return ResponseEntity.ok(jewelryService.getJewelryByStateAndIsHolding(state,isHolding,category,jewelryName,pageable));
101121
}
102122

123+
@GetMapping("/jewelry-passed")
124+
public ResponseEntity<Page<Jewelry>> getRequestPassed(
125+
@RequestParam(defaultValue = "0") int page,
126+
@RequestParam(defaultValue = "id") String sortBy,
127+
@RequestParam(required = false) String jewelryName,
128+
@RequestParam(required = false) String category,
129+
@RequestParam(defaultValue = "5") int size,
130+
@RequestParam(defaultValue = "asc") String sortOrder) {
131+
Sort.Direction direction = (sortOrder.equalsIgnoreCase("asc")) ? Sort.Direction.ASC : Sort.Direction.DESC;
132+
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
133+
return ResponseEntity.ok(jewelryService.getJewelryPassed(jewelryName, category, pageable));
134+
}
135+
103136
@GetMapping("/return-violator")
104137
public ResponseEntity<Page<Jewelry>> getJewelryReturnedViolator(
105138
@RequestParam(required = false) String jewelryName,
@@ -135,12 +168,22 @@ public ResponseEntity<Jewelry> lastJewelry() {
135168
}
136169

137170

138-
@PutMapping("/set-holding/{id}")
139-
public ResponseEntity<Jewelry> setHolding(@PathVariable Integer id, @RequestParam boolean state) throws MessagingException {
140-
jewelryService.setHolding(id,state);
171+
@PutMapping("/set-state-holding/{id}")
172+
public ResponseEntity<Jewelry> setStateWithHolding(@PathVariable Integer id, @RequestParam boolean isHolding, @RequestParam JewelryState state ) throws MessagingException {
173+
jewelryService.setStateWithHolding(id,isHolding,state);
141174
return ResponseEntity.ok().build();
142175
}
143176

177+
@PutMapping("/edit")
178+
public ResponseEntity<Jewelry> updateById(@RequestBody JewelryUpdateRequest jewelry) {
179+
return ResponseEntity.ok(jewelryService.updateJewelry(jewelry));
180+
}
181+
182+
@PostMapping
183+
public ResponseEntity<Jewelry> createJewelry(@RequestBody JewelryCreateRequest jewelry) {
184+
return ResponseEntity.ok(jewelryService.createJewelry(jewelry));
185+
}
186+
144187
@GetMapping("/user-jewelry/{userId}")
145188
public ResponseEntity<Page<Jewelry>> getJewelriesActiveByUserId(
146189
@PathVariable Integer userId,

src/main/java/vn/webapp/backend/auction/controller/TransactionController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import vn.webapp.backend.auction.model.User;
1616
import vn.webapp.backend.auction.service.transaction.TransactionService;
1717

18+
import java.util.Arrays;
1819
import java.util.List;
20+
import java.util.stream.Collectors;
1921

2022
@RestController
2123
@CrossOrigin(origins = {"http://localhost:3000", "http://localhost:3001"})
@@ -63,11 +65,14 @@ public ResponseEntity<Page<Transaction>> getTransactionByTypeAndState(
6365
@RequestParam(defaultValue = "SUCCEED") String state,
6466
@RequestParam(defaultValue = "desc") String sortOrder) {
6567
TransactionState transactionState = resolveTransactionState(state);
66-
Sort.Direction direction = (sortOrder.equalsIgnoreCase("desc")) ? Sort.Direction.DESC : Sort.Direction.ASC;
67-
Pageable pageable = PageRequest.of(page, size, direction, sortBy);
68-
return ResponseEntity.ok(transactionService.getTransactionByTypeAndState(type, userName, transactionState, pageable));
68+
Sort.Direction direction = sortOrder.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC;
69+
Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy));
70+
Page<Transaction> transactions = transactionService.getTransactionByTypeAndState(type, userName, transactionState, pageable);
71+
return ResponseEntity.ok(transactions);
6972
}
7073

74+
75+
7176
@GetMapping("/get-handover")
7277
public ResponseEntity<Page<Transaction>> getTransactionHandOver(
7378
@RequestParam(required = false) String jewelryName,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package vn.webapp.backend.auction.dto;
2+
3+
public record JewelryCreateRequest(
4+
String username,
5+
String name,
6+
String token,
7+
String description,
8+
String category,
9+
Double buyNowPrice,
10+
String material,
11+
String brand,
12+
Double weight
13+
) {
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package vn.webapp.backend.auction.dto;
2+
3+
import vn.webapp.backend.auction.enums.JewelryMaterial;
4+
5+
import java.sql.Timestamp;
6+
7+
public record JewelryUpdateRequest(
8+
Integer id,
9+
String name,
10+
String description,
11+
String category,
12+
Double buyNowPrice,
13+
JewelryMaterial material,
14+
String brand,
15+
Double weight,
16+
Timestamp createDate,
17+
String image,
18+
String state
19+
) {
20+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package vn.webapp.backend.auction.enums;
22

33
public enum AccountState {
4-
VERIFIED, ACTIVE, INACTIVE, DISABLE
4+
VERIFIED, ACTIVE, INACTIVE, DISABLE, BAN_PARTICIPATING
55
}

src/main/java/vn/webapp/backend/auction/enums/JewelryState.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ public enum JewelryState {
44
ACTIVE("Đã duyệt"),
55
APPROVING("Đang chờ duyệt"),
66
HIDDEN("Đã bị ẩn"),
7-
AUCTION("Đang đấu giá");
7+
AUCTION("Có phiên đấu"),
8+
HANDED_OVER("Đã bàn giao"),
9+
RETURNED("Đã hoàn trả");
810

911
private String displayName;
1012

src/main/java/vn/webapp/backend/auction/model/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
public class ErrorMessages {
55
public static final String USER_NOT_FOUND = "Không tìm thấy người dùng.";
6+
public static final String CATEGORY_NOT_FOUND = "Danh mục không tồn tại.";
67
public static final String USER_NOT_VERIFIED = "Người dùng chưa xác thực.";
78
public static final String USER_ALREADY_EXIST = "Người dùng đã tồn tại.";
89
public static final String REQUEST_APPROVAL_NOT_FOUND = "Không tìm thấy yêu cầu.";

src/main/java/vn/webapp/backend/auction/model/Jewelry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
@Entity
1515
@Data
16+
@Builder
1617
@AllArgsConstructor
1718
@NoArgsConstructor
1819
@Table(name = "jewelry")

src/main/java/vn/webapp/backend/auction/repository/JewelryRepository.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.data.repository.query.Param;
88
import vn.webapp.backend.auction.enums.JewelryState;
99
import vn.webapp.backend.auction.model.Jewelry;
10+
import vn.webapp.backend.auction.model.RequestApproval;
1011

1112
import java.util.List;
1213
import java.util.Optional;
@@ -38,6 +39,15 @@ Page<Jewelry> findJewelryByStateAndIsHolding(
3839
@Param("jewelryName") String jewelryName,
3940
Pageable pageable);
4041

42+
@Query("SELECT j FROM Jewelry j WHERE j.state = :state "+
43+
"AND (:jewelryName IS NULL OR j.name LIKE %:jewelryName%) "+
44+
" AND (:category IS NULL OR j.category.name = :category)")
45+
Page<Jewelry> findJewelriesManager(
46+
@Param("state") JewelryState state,
47+
@Param("jewelryName") String jewelryName,
48+
@Param("category") String category,
49+
Pageable pageable);
50+
4151
@Query("SELECT j FROM Jewelry j WHERE j.state = 'ACTIVE' AND j.isHolding = true " +
4252
"AND j.user.state ='DISABLE'" +
4353
"AND (:jewelryName IS NULL OR j.name LIKE %:jewelryName%) " +
@@ -70,10 +80,21 @@ Page<Jewelry> findJewelryByStateAndIsHolding(
7080
Integer countAllJewelriesHasAuction(@Param("month") Integer month, @Param("year") Integer year);
7181

7282
@Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding = false AND " +
73-
"j.state = 'AUCTION' AND j.receivedDate IS NOT NULL AND j.deliveryDate IS NOT NULL " +
83+
"j.state = 'HANDED_OVER' AND j.receivedDate IS NOT NULL AND j.deliveryDate IS NOT NULL " +
7484
"AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year")
7585
Integer countAllJewelriesHandOver(@Param("month") Integer month, @Param("year") Integer year);
7686

87+
@Query("SELECT j FROM Jewelry j " +
88+
"WHERE " +
89+
"(:jewelryName IS NULL OR j.name LIKE %:jewelryName%) " +
90+
"AND (:category IS NULL OR j.category.name = :category) " +
91+
"AND j.state = 'ACTIVE' AND j.isHolding = true AND j.user.state != 'DISABLE'")
92+
Page<Jewelry> getPassedJewelry(
93+
@Param("jewelryName") String jewelryName,
94+
@Param("category") String category,
95+
Pageable pageable
96+
);
97+
7798
@Query("SELECT j FROM Jewelry j WHERE j.user.id = :userId AND (:jewelryName IS NULL OR j.name LIKE %:jewelryName%) AND (j.state = 'ACTIVE' OR j.state = 'AUCTION')")
7899
Page<Jewelry> findJewelryActiveByUserId(@Param("userId") Integer userId,@Param("jewelryName") String jewelryName, Pageable pageable);
79100

src/main/java/vn/webapp/backend/auction/security/Endpoints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ private Endpoints() {
2727
"/api/v1/user/change-password", "/api/v1/auction/update-end-date/**",
2828
"/api/v1/auction/set-state/**", "/api/v1/user","/api/v1/request-approval/set-state/**",
2929
"/api/v1/request-approval/confirm/**", "/api/v1/request-approval/cancel-request",
30-
"/api/v1/transaction/set-method/**", "/api/v1/jewelry/set-holding/**"
30+
"/api/v1/transaction/set-method/**", "/api/v1/jewelry/set-state-holding/**"
3131
};
3232

3333
public static final String[] STAFF_GET_ENDPOINTS = {
3434
"/api/v1/user/get-user-registration/**",
3535
};
3636

3737
public static final String[] MANAGER_GET_ENDPOINTS = {
38-
"/api/v1/transaction/get-handover"
38+
"/api/v1/transaction/get-handover", "/api/v1/jewelry/manager-list"
3939
};
4040

4141
public static final String[] MANAGER_PUT_ENDPOINTS = {

src/main/java/vn/webapp/backend/auction/service/auction/AuctionServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public void deleteAuctionResult(Integer transactionId) throws MessagingException
162162
.orElseThrow(() -> new ResourceNotFoundException(ErrorMessages.USER_NOT_FOUND));
163163

164164
String reason = ReasonMessages.DO_NOT_PAY_ON_TIME;
165-
existingTransaction.setState(TransactionState.HIDDEN);
165+
existingTransaction.setState(TransactionState.FAILED);
166166
existingAuction.setState(AuctionState.FINISHED);
167167
existingJewelry.setState(JewelryState.ACTIVE);
168-
existingUser.setState(AccountState.DISABLE);
168+
existingUser.setState(AccountState.BAN_PARTICIPATING);
169169
existingUser.setBanReason(reason);
170170

171-
emailService.sendBlockAccountEmail(
171+
emailService.sendBanParticipatingAccountEmail(
172172
existingUser.getEmail(),
173173
existingUser.getFullName(),
174174
existingUser.getUsername(),

src/main/java/vn/webapp/backend/auction/service/email/EmailContent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public String setHtmlConfirmHoldingContent(String fullName, String assetName
398398
return content;
399399
}
400400

401-
public String setHtmlBlockAccountContent(String fullName, String userName, String reason
401+
public String setHtmlBanParticipatingAccountContent(String fullName, String userName, String reason
402402
) {
403403
String imageUrl = "https://raw.githubusercontent.com/phuuthanh2003/AuctionWebApp_BE/main/logo.png";
404404
String content = "<!DOCTYPE html>\n" +
@@ -507,7 +507,7 @@ public String setHtmlBlockAccountContent(String fullName, String userName, Strin
507507
" width=\"600\" height=\"10\">\n" +
508508
" <h1\n" +
509509
" style=\"font-family: Helvetica, Arial, sans-serif;font-size: 18px;margin: 0;line-height: 1.5em;color: #ffffff !important;\">\n" +
510-
" Thông báo khóa tài khoản người dùng.</h1>\n" +
510+
" Thông báo tài khoản sẽ không thể tham gia đấu giá.</h1>\n" +
511511
" </td>\n" +
512512
" </tr>\n" +
513513
" <tr>\n" +
@@ -520,7 +520,7 @@ public String setHtmlBlockAccountContent(String fullName, String userName, Strin
520520
" </table>\n" +
521521
" <br class=\"spacer\" style=\"line-height: 20px;\" />\n" +
522522
" <h3>Xin chào, " + fullName + "</h3>\n" +
523-
" <h4>Rất tiếc phải thông báo Tài khoản " + userName + " đã bị khóa.</h4>\n" +
523+
" <h4>Rất tiếc phải thông báo Tài khoản " + userName + " sẽ không thể tiếp tục tham gia đấu giá.</h4>\n" +
524524
" <h4><strong>Lý do: </strong> "+ reason +"</h4>\n" +
525525
" <br class=\"spacer\" style=\"line-height: 20px;\" />\n" +
526526
" <br class=\"spacer\" style=\"line-height: 20px;\" />\n" +

src/main/java/vn/webapp/backend/auction/service/email/EmailService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ public void sendConfirmHoldingEmail(String to, String fullName, String assetName
7777
}
7878

7979
@Async
80-
public void sendBlockAccountEmail(String to, String fullName, String userName, String reason) throws MessagingException {
80+
public void sendBanParticipatingAccountEmail(String to, String fullName, String userName, String reason) throws MessagingException {
8181
MimeMessage message = javaMailSender.createMimeMessage();
8282
MimeMessageHelper helper = new MimeMessageHelper(message, true);
8383

84-
String html = emailContent.setHtmlBlockAccountContent(fullName,userName,reason);
84+
String html = emailContent.setHtmlBanParticipatingAccountContent(fullName,userName,reason);
8585

8686
helper.setFrom(emailUsername);
8787
helper.setTo(to);
88-
helper.setSubject("Tài khoản DGS của bạn sẽ bị khóa!.");
88+
helper.setSubject("Tài khoản DGS của bạn sẽ bị tạm khóa, không thể tham gia đấu giá!.");
8989
helper.setText(html, true);
9090

9191
javaMailSender.send(message);

src/main/java/vn/webapp/backend/auction/service/jewelry/JewelryService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import jakarta.mail.MessagingException;
44
import org.springframework.data.domain.Page;
55
import org.springframework.data.domain.Pageable;
6+
import vn.webapp.backend.auction.dto.JewelryCreateRequest;
7+
import vn.webapp.backend.auction.dto.JewelryUpdateRequest;
68
import vn.webapp.backend.auction.dto.SendJewelryFromUserRequest;
79
import vn.webapp.backend.auction.enums.JewelryState;
810
import vn.webapp.backend.auction.model.Jewelry;
@@ -18,15 +20,19 @@ public interface JewelryService {
1820

1921
void deleteJewelry(Integer id);
2022

21-
List<Jewelry> getJeweriesByCategoryId(Integer id);
23+
List<Jewelry> getJewelriesByCategoryId(Integer id);
2224

23-
List<Jewelry> getJeweriesByNameContain(String key);
25+
Page<Jewelry> getJewelryPassed(String jewelryName, String category, Pageable pageable);
26+
27+
List<Jewelry> getJewelriesByNameContain(String key);
2428

2529
Page<Jewelry> getAllJewelries(Pageable pageable);
2630

31+
Page<Jewelry> getJewelriesManager(JewelryState state, String jewelryName, String category, Pageable pageable);
32+
2733
Page<Jewelry> getJewelriesInWaitList(Pageable pageable);
2834

29-
Page<Jewelry> getJewelryByStateAndIsHolding(JewelryState state, Boolean isHolding,String category, String jewelryName, Pageable pageable);
35+
Page<Jewelry> getJewelryByStateAndIsHolding(JewelryState state, Boolean isHolding, String category, String jewelryName, Pageable pageable);
3036

3137
Page<Jewelry> getJewelryReturnedViolator(String category, String jewelryName, Pageable pageable);
3238

@@ -40,6 +46,10 @@ public interface JewelryService {
4046

4147
Jewelry getLatestJewelry();
4248

43-
Jewelry setHolding(Integer id, boolean state) throws MessagingException;
49+
Jewelry updateJewelry(JewelryUpdateRequest jewelry);
50+
51+
Jewelry createJewelry(JewelryCreateRequest jewelry);
52+
53+
Jewelry setStateWithHolding(Integer id, boolean isHolding, JewelryState state) throws MessagingException;
4454

4555
}

0 commit comments

Comments
 (0)