Building an Orders Processing Service with ChatGPT (contribute 70–80% efforts) and Finished in 2 Days

Jacky - Sep 25 - - Dev Community

AI has contributed to changing and increasing efficiency in my daily work

As a developer, building an orders processing service can sometimes feel overwhelming when you have a limited timeframe. However, with the power of AI-driven development tools like ChatGPT, you can significantly speed up the process by generating code, designing entities, and solving problems step by step. In this article, I’ll walk you through how I used ChatGPT to build a fully functional orders processing service in just 2 days, from gathering requirements to completion.

Honestly, there are many small threads and prompts for different small tasks that I can't summarize into a complete project, but overall... it helped me 70 - 80%. Additionally, here is some of the original code, after I reviewed it, it may have been modified by hand, so you may not find this function on github that I shared.

Day 1: Understanding Requirements and Setting Up

Step 1: Gather and Clarify Requirements

The first thing I did was list down the core features required for the service. Here are the primary functionalities I needed:

  1. User Registration: Allow users to register using their mobile number and address.
  2. Franchise Location Search: Enable customers to view and find coffee franchises nearby.
  3. Order Placement: Customers can place an order with multiple items from a menu.
  4. Queue Management: Track a customer’s position in a queue and provide expected wait time.
  5. Order Cancellation: Customers can exit the queue and cancel their order at any time.

Step 2: Generate API Endpoints with ChatGPT

I asked ChatGPT to help me design the API structure for the requirements. Here’s an example of the first prompt I used:

Prompt:

Create API endpoints for a user registration system using Spring Boot, where users can register with their name, mobile number, and address.

Result: ChatGPT generated several endpoints:

  • POST /users/register: To register a new user.
  • GET /franchises/nearby: To find nearby coffee franchises based on latitude and longitude.
  • POST /orders: To place an order with multiple items.
  • GET /orders/{orderId}/queue-position: To check the user’s position in the queue.
  • DELETE /orders/{orderId}: To cancel the order and exit the queue.

Step 3: Entity Design

For the order processing service, we needed entities for User, Franchise, Order, Queue, and OrderItem. I used ChatGPT to define these entities with the necessary fields.

Prompt:

Design the User entity for the system. The user can have a mobile number, address, and a role (like CUSTOMER).

Result: ChatGPT provided a simple User entity using JPA:

@Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private UUID id;

    @Column(nullable = false, unique = true)
    private String username;
    @Column(nullable = false)
    private String password;
    private String mobileNumber;
    private String address;
    private UserRole role; // CUSTOMER, ADMIN
}
Enter fullscreen mode Exit fullscreen mode

I repeated this process for the Franchise, Order, and Queue entities.

Day 2: Implementing Business Logic

Step 4: Order Placement Logic

Once the basic API and entities were set up, I moved on to implementing business logic for order placement. This was the critical part of the service since it needed to handle multiple items from the menu and manage queue positions.

Prompt:

Implement the logic for placing an order with multiple items, where each item is linked to a specific menu in the Franchise.

Result: ChatGPT guided me through designing an OrderService to handle this. Here’s part of the implementation:

public Order createOrder(UUID customerId, UUID franchiseId, List<OrderItemDTO> items) {
    Order order = new Order();
    order.setCustomer(userRepository.findById(customerId).orElseThrow());
    order.setFranchise(franchiseRepository.findById(franchiseId).orElseThrow());

    List<OrderItem> orderItems = items.stream()
        .map(itemDto -> new OrderItem(menuItemRepository.findById(itemDto.getMenuItemId()), itemDto.getQuantity()))
        .collect(Collectors.toList());
    order.setItems(orderItems);
    order.setQueuePosition(findQueuePositionForFranchise(franchiseId));
    return orderRepository.save(order);
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Queue Management

Next, I asked ChatGPT to help me design the logic for placing a customer in the queue and tracking their position.

Prompt:

How can I calculate the queue position and waiting time for an order in a coffee franchise system?

Result: ChatGPT suggested creating a QueueService that tracks orders and assigns them positions based on timestamps. I implemented it as follows:

public int findQueuePositionForFranchise(UUID franchiseId) {
    List<CustomerQueue> queue = customerQueueRepository.findAllByFranchiseId(franchiseId);
    return queue.size() + 1;
}
Enter fullscreen mode Exit fullscreen mode

It also provided guidance on estimating waiting times based on the average order processing time.

Step 6: Order Cancellation

Finally, I implemented the logic for allowing customers to cancel their orders and exit the queue:

public void cancelOrder(UUID orderId) {
    Order order = orderRepository.findById(orderId).orElseThrow();
    queueService.removeFromQueue(order.getQueue().getId(), order.getId());
    orderRepository.delete(order);
}
Enter fullscreen mode Exit fullscreen mode

Finalizing the Project

By the end of Day 2, I had a fully functional service that allowed customers to:

  • Register using their mobile number and address.
  • View nearby franchises.
  • Place orders with multiple items from the menu.
  • Check their queue position and waiting time.
  • Cancel their order at any time.

Key Takeaways

  • Leverage AI for Routine Tasks: ChatGPT sped up repetitive tasks like designing APIs, generating boilerplate code, and implementing common business logic patterns.
  • Divide and Conquer: By breaking the project into small, manageable tasks (such as user registration, queue management, and order placement), I was able to implement each feature sequentially.
  • AI-Assisted Learning: While ChatGPT provided a lot of code, I still had to understand the underlying logic and tweak it to fit my project’s needs, which was a great learning experience.
  • Real-Time Debugging: ChatGPT helped me solve real-time issues by guiding me through errors and exceptions I encountered during implementation, which kept the project on track.

I have a few more steps to create the documentation, use liquidbase and have chatGPT generate sample data for easier testing.

Conclusion

Building an order processing system for a coffee shop in 2 days may sound daunting, but with AI assistance, it’s achievable. ChatGPT acted like a coding assistant, helping me transform abstract requirements into a working system quickly. While AI can provide a foundation, refining and customizing code is still an essential skill. This project taught me how to maximize the value of AI tools without losing control of the development process.

By following the steps I took, you can speed up your own projects and focus on higher-level problem-solving, leaving the routine code generation and guidance to AI.

Full source Github

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .