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 8f19cf7 commit 21dc83b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/pos/app/entities/QrCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import lombok.NoArgsConstructor;
import org.hibernate.type.format.jakartajson.JakartaJsonIntegration;

import java.util.Date;
import java.util.UUID;

@Data
@Entity
@Builder
Expand Down Expand Up @@ -42,4 +45,22 @@ public class QrCode {
@Column(name = "updated_by")
private String updatedBy;


@PrePersist
public void prePersist() {
if (this.id == null) {
this.id = UUID.randomUUID().toString();
}
this.createdDate = new Date().getTime();
this.updatedDate = new Date().getTime();
}

@PreUpdate
public void preUpdate() {


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


}
2 changes: 1 addition & 1 deletion src/main/java/com/pos/app/enums/OrderStatusEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.pos.app.enums;

public enum OrderStatusEnum {
COMPLETED, CREATED, IN_PROGRESS, READY
COMPLETED, CREATED, IN_PROGRESS, READY, PENDING
}
7 changes: 7 additions & 0 deletions src/main/java/com/pos/app/repositories/QrCodeRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pos.app.repositories;

import com.pos.app.entities.QrCode;
import org.springframework.data.jpa.repository.JpaRepository;

public interface QrCodeRepository extends JpaRepository<QrCode, String> {
}
41 changes: 31 additions & 10 deletions src/main/java/com/pos/app/service/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.pos.app.service.impl;

import com.pos.app.entities.Order;
import com.pos.app.entities.OrderProduct;
import com.pos.app.entities.Product;
import com.pos.app.entities.Transaction;
import com.pos.app.controller.OrderController;
import com.pos.app.entities.*;
import com.pos.app.enums.OrderStatusEnum;
import com.pos.app.enums.ResponseEnum;
import com.pos.app.exception.BadRequestException;
Expand All @@ -12,13 +10,9 @@
import com.pos.app.model.request.ReqCreateOrder;
import com.pos.app.model.response.ResListOrder;
import com.pos.app.model.response.ResponseIdQr;
import com.pos.app.repositories.OrderProductRepository;
import com.pos.app.repositories.OrderRepository;
import com.pos.app.repositories.ProductRepository;
import com.pos.app.repositories.TransactionRepository;
import com.pos.app.repositories.*;
import com.pos.app.service.AccountService;
import com.pos.app.service.OrderService;
import com.pos.app.service.WebSocketService;
import com.pos.app.utils.NumberHelper;
import com.pos.app.utils.UtilsHelper;
import lombok.RequiredArgsConstructor;
Expand All @@ -30,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Service
@RequiredArgsConstructor
Expand All @@ -41,6 +36,8 @@ public class OrderServiceImpl implements OrderService {
private final OrderProductRepository orderProductRepository;
private final TransactionRepository transactionRepository;
private final SimpMessagingTemplate simpMessagingTemplate;
private final ClientRepository clientRepository;
private final QrCodeRepository qrCodeRepository;

@Override
public ResponseEnum createOrder(ReqCreateOrder req) {
Expand Down Expand Up @@ -198,8 +195,32 @@ public List<ResListOrder> getLiveOrderList(OrderStatusEnum status) {

@Override
public ResponseIdQr generateQROrder() {
String clientId = accountService.getCurrentClientIdOrNull();
BigInteger getLatestCode = orderRepository.findLatestCode(clientId);
Optional<Client> client = clientRepository.findById(clientId);
String currentAccountId = accountService.getCurrentAccountId();
if (client.isEmpty()) {
throw new NotFoundException(ResponseEnum.CLIENT_NOT_FOUND.name());
}

try {
return null;
Order order = Order.builder()
.status(OrderStatusEnum.IN_PROGRESS)
.isPayment(false)
.orderCode(UtilsHelper.generateOrderCode(getLatestCode))
.clientId(clientId)
.createdBy(accountService.getCurrentAccountId())
.build();
order = orderRepository.save(order);
QrCode qrCode = QrCode.builder()
.code(UUID.randomUUID().toString())
.order(order)
.client(client.get())
.createdBy(currentAccountId)
.updatedBy(currentAccountId)
.build();
qrCode = qrCodeRepository.save(qrCode);
return ResponseIdQr.builder().id(qrCode.getCode()).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/db/changelog/1.4.1_add_column_updated_by.xml
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.4.1" author="rivo">
<addColumn tableName="qr_code">
<column name="updated_by" type="varchar(255)">
<constraints nullable="true"/>
</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 @@ -20,5 +20,6 @@
<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"/>
<include file="classpath:db/changelog/1.4.0_add_table_qr_code.xml"/>
<include file="classpath:db/changelog/1.4.1_add_column_updated_by.xml"/>

</databaseChangeLog>

0 comments on commit 21dc83b

Please sign in to comment.