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

update cccd of user #89

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
7 changes: 5 additions & 2 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ CREATE TABLE [dbo].[user]
(
[id] [int] IDENTITY (1,1) NOT NULL,
[cccd] [varchar](20) NOT NULL,
[cccd_first] [varchar](MAX) NOT NULL,
[cccd_last] [varchar](MAX) NOT NULL,
[cccd_from] [nvarchar](50) NOT NULL,
[address] [nvarchar](50) NOT NULL,
[avatar] [varchar](max) NULL,
[bank_account_name] [varchar](30) NOT NULL,
Expand All @@ -87,12 +90,12 @@ CREATE TABLE [dbo].[user]
-- Insert data into the user table
INSERT INTO [dbo].[user]
([cccd], [address], [avatar], [city], [email], [first_name], [last_name], [password], [phone], [district], [ward],
[state], [username], [year_of_birth], [role], [bank_id], [bank_account_number], [bank_account_name], [register_date])
[state], [username], [year_of_birth], [role], [bank_id], [bank_account_number], [bank_account_name], [register_date], [cccd_first], [cccd_last], [cccd_from])
VALUES ('011234567890', N'1 Lý Thường Kiệt',
'https://scontent.fsgn2-7.fna.fbcdn.net/v/t39.30808-6/438275285_1101091104487039_4035794765477072253_n.jpg?_nc_cat=108&ccb=1-7&_nc_sid=5f2048&_nc_ohc=7MHTOamLKXgQ7kNvgGdad4i&_nc_ht=scontent.fsgn2-7.fna&oh=00_AYDZ0L0Y3_1M_tK5YBX-b1PhjuTPFeLod8Jz1UhW3t_Gkg&oe=6665416E',
N'Lâm Đồng', 'phuuthanh2003@gmail.com', N'Phùng', N'Thành',
'$2a$12$j/1n5Pjv4JgzG76ZG0hyH.MD6ftohJNbjuZjRHQFt31Ta/jViwKQ2', '0912345670', N'Hà Nội', N'Hoang', 'ACTIVE',
'phuuthanh2003', 1985, 'ADMIN', 7, '1030293193991', 'PHUNG HUU THANH', '2024-05-01 17:30:00');
'phuuthanh2003', 1985, 'ADMIN', 7, '1030293193991', 'PHUNG HUU THANH', '2024-05-01 17:30:00', '01', '123456', 'CA NINH');


CREATE TABLE [dbo].[jewelry]
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.ChangePasswordRequest;
import vn.webapp.backend.auction.dto.RegisterAccountRequest;
import vn.webapp.backend.auction.dto.UserSpentDTO;
import vn.webapp.backend.auction.enums.AccountState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ public class DashBoardResponse {
private Integer totalUser;
private Integer totalJewelryActive;
private Integer totalJewelryWaitApproving;
private Integer totalAuctionJewelry;
private Integer totalUsersActive;
private Integer totalUsersInActive;
private Integer totalMembers;
private Integer totalStaffs;
private Integer totalManagers;
private Integer totalAdmins;
private double percentAuctionFailed;
private double percentAuctionSuccess;
private double participationRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public record RegisterAccountRequest(
String ward,
String yob,
String phone,
String CCCD,
String cccd,
String cccdFirst,
String cccdLast,
String cccdFrom,
Role role,
String bankAccountName,
String bankAccountNumber,
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/vn/webapp/backend/auction/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ public class User implements UserDetails {

@Column(name = "CCCD", nullable = false, length = 20)
@NotBlank(message = "The CCCD is required")
private String CCCD;
private String cccd;

@Column(name = "CCCD_first")
@Lob
@NotBlank(message = "The CCCD Frist is required")
private String cccdFirst;

@Column(name = "CCCD_last")
@Lob
@NotBlank(message = "The CCCD Last is required")
private String cccdLast;

@Column(name = "CCCD_from", length = 50)
@NotBlank(message = "The CCCD From is required")
private String cccdFrom;

@Column(name = "register_date")
private Timestamp registerDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public interface JewelryRepository extends JpaRepository<Jewelry, Integer> {
@Query("SELECT j FROM Jewelry j ORDER BY j.id DESC")
List<Jewelry> findLatestJewelry();

@Query("SELECT COUNT(j) FROM Jewelry j WHERE j.state = 'ACTIVE'")
Integer countAllJewelriesActive();

@Query("SELECT COUNT(j) FROM Jewelry j WHERE j.state = 'APPROVING'")
Integer countAllJewelriesWaitApproving();
@Query("SELECT COUNT(j) FROM Jewelry j WHERE j.state = :state")
Integer countAllJewelriesByState(@Param("state") JewelryState state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ 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 COUNT(u) FROM User u WHERE u.state = 'ACTIVE'")
@Query("SELECT COUNT(u) FROM User u WHERE u.state != 'DISABLE'")
Integer getTotalUser();

@Query("SELECT COUNT(u) FROM User u WHERE u.state = :state")
Integer getTotalUserByState(@Param("state") AccountState state);

@Query("SELECT COUNT(u) FROM User u WHERE u.role = :role")
Integer getTotalUserByRole(@Param("role") Role role);

@Query("SELECT COUNT(u) FROM User u WHERE MONTH(u.registerDate) = :month AND YEAR(u.registerDate) = :year")
Integer getTotalUserByMonthAndYear(@Param("month") Integer month, @Param("year") Integer year);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ private Endpoints() {

public static final String[] PUBLIC_POST_ENDPOINTS = {
"/api/v1/auction-history", "/api/v1/jewelry/jewelry-request","/api/v1/image/add-image",
"/api/v1/auth/**",
"/api/v1/request-approval/send-from-user", "/api/v1/request-approval/send-from-staff", "/api/v1/request-approval/send-from-manager",
"/api/v1/transaction/create-transaction-for-winner/**", "/api/v1/transaction/create-transaction-for-winner-if-not-exist/**",
};

public static final String[] PUBLIC_PUT_ENDPOINTS = {
"/api/v1/user/change-password",
"/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/jewelry/set-holding/**"
"/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 @@ -4,6 +4,7 @@
import jakarta.mail.MessagingException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.transaction.Transactional;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand Down Expand Up @@ -32,7 +33,6 @@
import java.time.LocalDateTime;
import java.time.ZoneId;


@Service
@RequiredArgsConstructor
public class AuthenticationServiceImpl implements AuthenticationService {
Expand Down Expand Up @@ -144,6 +144,7 @@ public void activateAccount(ActivateAccountRequest request) throws MessagingExce
userRepository.save(user);
}
}

@Override
public AuthenticationResponse register(RegisterAccountRequest request, HttpServletRequest httpServletRequest) throws MessagingException {
userRepository.findByUsername(request.username())
Expand Down Expand Up @@ -171,7 +172,10 @@ public AuthenticationResponse register(RegisterAccountRequest request, HttpServl
.avatar("https://www.iconpacks.net/icons/2/free-user-icon-3296-thumb.png")
.yob(request.yob())
.role(request.role())
.CCCD(request.CCCD())
.cccd(request.cccd())
.cccdFirst(request.cccdFirst())
.cccdLast(request.cccdLast())
.cccdFrom(request.cccdFrom())
.registerDate(Timestamp.valueOf(LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh"))))
.state(AccountState.INACTIVE)
.bankAccountName(request.bankAccountName())
Expand Down Expand Up @@ -251,6 +255,7 @@ public void refreshToken(
}

@Override
@Transactional
public AuthenticationResponse changePassword(ChangePasswordRequest request) {
var user = userRepository.findByUsername(jwtService.extractUsername(request.token()))
.orElseThrow();
Expand All @@ -260,9 +265,7 @@ public AuthenticationResponse changePassword(ChangePasswordRequest request) {
user.setPassword(passwordEncoder.encode(request.newPassword()));
userRepository.save(user);
var jwtToken = jwtService.generateToken(user);
return AuthenticationResponse.builder()
.accessToken(jwtToken)
.build();
return new AuthenticationResponse(jwtToken);
}

@Override
Expand Down Expand Up @@ -292,4 +295,4 @@ public AuthenticationResponse resetPassword(ResetPasswordRequest request) {
throw new UnauthorizedException("Không có quyền truy cập.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.stereotype.Service;
import vn.webapp.backend.auction.dto.DashBoardResponse;
import vn.webapp.backend.auction.enums.AccountState;
import vn.webapp.backend.auction.enums.JewelryState;
import vn.webapp.backend.auction.enums.Role;
import vn.webapp.backend.auction.repository.*;

import java.time.LocalDateTime;
Expand All @@ -26,13 +28,18 @@ public DashBoardResponse getInformation(Integer yearGetRegisterAccount, Integer
// Total counts
Integer totalUser = userRepository.getTotalUser();
Integer totalAuction = auctionRepository.countAllAuctions();
Integer totalJewelryActive = jewelryRepository.countAllJewelriesActive();
Integer totalJewelryWaitApproving = jewelryRepository.countAllJewelriesWaitApproving();
Integer totalActiveJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.ACTIVE);
Integer totalApprovingJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.APPROVING);
Integer totalAuctionJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.AUCTION);
Integer totalAuctionFailed = auctionRepository.countAllAuctionsFailed();
Integer totalAuctionSuccess = auctionRepository.countAllAuctionsSuccessful();
Integer totalAuctionsFinished = auctionRepository.countAllAuctionsFinished();
Integer totalUsersActive = userRepository.getTotalUserByState(AccountState.ACTIVE);
Integer totalUsersInActive = userRepository.getTotalUserByState(AccountState.INACTIVE);
Integer totalMembers = userRepository.getTotalUserByRole(Role.MEMBER);
Integer totalStaffs = userRepository.getTotalUserByRole(Role.STAFF);
Integer totalManagers = userRepository.getTotalUserByRole(Role.MANAGER);
Integer totalAdmins = userRepository.getTotalUserByRole(Role.ADMIN);
Long totalUsersRegister = auctionRegistrationRepository.countDistinctUsersRegistered();
Long totalUsersNotRegistered = totalUser - totalUsersRegister;

Expand Down Expand Up @@ -70,11 +77,16 @@ public DashBoardResponse getInformation(Integer yearGetRegisterAccount, Integer
return DashBoardResponse.builder()
.totalUser(totalUser)
.totalRevenueToday(totalRevenueToday)
.totalJewelryActive(totalJewelryActive)
.totalJewelryWaitApproving(totalJewelryWaitApproving)
.totalJewelryActive(totalActiveJewelry)
.totalJewelryWaitApproving(totalApprovingJewelry)
.totalAuctionJewelry(totalAuctionJewelry)
.totalAuctions(totalAuction)
.totalUsersActive(totalUsersActive)
.totalUsersInActive(totalUsersInActive)
.totalMembers(totalMembers)
.totalStaffs(totalStaffs)
.totalManagers(totalManagers)
.totalAdmins(totalAdmins)
.totalUsersByMonth(totalUsersRegisterByMonth)
.totalAuctionByMonth(totalAuctionByMonth)
.percentAuctionFailed(percentAuctionFailed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public User updateUser(User user) {
existingUser.setWard(user.getWard());
existingUser.setCity(user.getCity());
existingUser.setAvatar(user.getAvatar());
existingUser.setCccd(user.getCccd());
existingUser.setCccdFirst(user.getCccdFirst());
existingUser.setCccdLast(user.getCccdLast());
existingUser.setCccdFrom(user.getCccdFrom());
existingUser.setPhone(user.getPhone());
existingUser.setYob(user.getYob());
existingUser.setBankAccountNumber(user.getBankAccountNumber());
Expand Down Expand Up @@ -162,7 +166,10 @@ public User registerStaff(RegisterAccountRequest request) {
.registerDate(Timestamp.valueOf(LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh"))))
.phone(request.phone())
.address(request.address())
.CCCD(request.CCCD())
.cccd(request.cccd())
.cccdFirst(request.cccdFirst())
.cccdLast(request.cccdLast())
.cccdFrom(request.cccdFrom())
.build();
return userRepository.save(user);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring.datasource.username=sa
spring.datasource.password=Thanhth@nh1

# Config create table automatically
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.ddl-auto=update

# Config email
spring.mail.host=smtp.gmail.com
Expand Down
Loading