Skip to content

Commit

Permalink
FEAT:fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Dec 2, 2024
1 parent 0a13132 commit 697af83
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/pos/app/controller/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public interface AccountController {
@PutMapping("v1/change-password")
BaseResponse changePassword(@RequestBody ReqChangePassword req);

@PatchMapping("v1/inactive-account/{id}")
BaseResponse inactiveAccount(@PathVariable String id);


}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public BaseResponse resetPassword(String id) {
public BaseResponse changePassword(ReqChangePassword req) {
return ResponseHelper.createBaseResponse(accountService.changePassword(req));
}

@Override
public BaseResponse inactiveAccount(String id) {

return ResponseHelper.createBaseResponse(accountService.inActiveAccount(id));
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/pos/app/entities/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class Account implements UserDetails {
@JoinColumn(name = "client_id")
private Client client;

@Column(name = "is_inactive")
private Boolean isInactive;


@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Expand Down Expand Up @@ -100,7 +103,6 @@ public void prePersist() {

@PreUpdate
public void preUpdate() {

this.updatedDate = new Date().getTime();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ResponseListAccount {
private String id;
private String avatar;
private String createdBy;
private Boolean isInactive;
private Long createdDate;
private UserRole role;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/pos/app/service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface AccountService {
ResponsePasswordCreateAccount resetPassword(String id);

ResponseEnum changePassword(ReqChangePassword req);

ResponseEnum inActiveAccount(String id);
}
22 changes: 22 additions & 0 deletions src/main/java/com/pos/app/service/impl/AccountServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public Page<ResponseListAccount> listAccount(Pageable pageable) {
.avatar(account.getAvatar())
.id(account.getId())
.role(account.getRole())
.isInactive(account.getIsInactive())
.createdDate(account.getCreatedDate())
.createdBy(getCurrentAccount(account.getCreatedBy()).getName())
.build();
Expand Down Expand Up @@ -243,4 +244,25 @@ public ResponseEnum changePassword(ReqChangePassword req) {
throw new SystemErrorException(e);
}
}

@Override
public ResponseEnum inActiveAccount(String id) {


try {

Optional<Account> findAccount = accountRepository.findById(id);
if (findAccount.isEmpty()) {
throw new NotFoundException(ResponseEnum.ACCOUNT_NOT_FOUND.name());
}
Account account = findAccount.get();

account.setIsInactive(true);
accountRepository.save(account);
return ResponseEnum.SUCCESS;
} catch (Exception e) {
throw new SystemErrorException(e);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public ResponseAnalyticsSummary getAnalyticsSummary() {
.totalRevenue(getTotalRevenue)
.totalItems(getTotalItems)
.build();

} catch (Exception e) {
throw new SystemErrorException(e);
}
Expand Down Expand Up @@ -78,7 +77,6 @@ public List<ResponseChartOrder> getAnalyticsChartRevenue(Date startDate, Date en
try {
List<Object[]> list = transactionRepository.getChartRevenue(8);
List<ResponseChartOrder> responseCharts = new ArrayList<>();

if (!list.isEmpty()) {
for (Object[] obj : list) {
ResponseChartOrder.ResponseChartOrderBuilder responseOrderChartBuilder = ResponseChartOrder.builder()
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/pos/app/service/impl/AuthServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public ResponseSignIn signInSuperAdmin(RequestSignIn req) {

private ResponseSignIn getSignIn(Account account, String password) {
try {
if (account.getIsInactive()) {
throw new BadRequestException(ResponseEnum.SIGN_IN_FAILED.name());
}
Authentication authentication;
authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(account.getUsername(), password));
SecurityContextHolder.getContext().setAuthentication(authentication);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="1.3.5" author="rivo">
<addColumn tableName="account">
<column name="is_inactive" type="tinyint" defaultValue="0">
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<include file="classpath:db/changelog/1.3.2_add_column_is_payment_order.xml"/>
<include file="classpath:db/changelog/1.3.3_modify_column_order.xml"/>
<include file="classpath:db/changelog/1.3.4_add_client_id_column.xml"/>
<include file="classpath:db/changelog/1.3.5_add_column_is_inactive_account.xml"/>

</databaseChangeLog>

0 comments on commit 697af83

Please sign in to comment.