>  기사  >  Java  >  ChatGPT를 사용하여 주문 처리 서비스 구축(기여) 및 무사히 완료

ChatGPT를 사용하여 주문 처리 서비스 구축(기여) 및 무사히 완료

DDD
DDD원래의
2024-09-25 17:50:02588검색

Building an Orders Processing Service with ChatGPT (contribute  efforts) and Finished in ays

AI는 나의 일상 업무를 변화시키고 효율성을 높이는 데 기여했습니다

개발자로서 제한된 시간 내에 주문 처리 서비스를 구축하는 것이 때로는 부담스러울 수 있습니다. 그러나 ChatGPT와 같은 AI 기반 개발 도구의 강력한 기능을 사용하면 코드를 생성하고, 엔터티를 설계하고, 문제를 단계별로 해결하여 프로세스 속도를 크게 높일 수 있습니다. 이 기사에서는 ChatGPT를 사용하여 요구 사항 수집부터 완료까지 단 2일 만에 완전한 기능을 갖춘 주문 처리 서비스를 구축한 방법을 안내해 드리겠습니다.

솔직히 완전한 프로젝트로 요약할 수 없는 다양한 작은 작업에 대한 작은 스레드와 프롬프트가 많이 있지만 전체적으로... 70~80% 도움이 되었습니다. 또한 원본 코드 중 일부는 다음과 같습니다. 검토한 후 직접 수정했을 수 있으므로 제가 공유한 github에서 이 기능을 찾지 못할 수도 있습니다.

1일차: 요구사항 이해 및 설정

1단계: 요구 사항 수집 및 명확화

가장 먼저 서비스에 필요한 핵심 기능을 나열했습니다. 필요한 주요 기능은 다음과 같습니다.

  1. 사용자 등록: 사용자가 자신의 휴대폰 번호와 주소를 사용하여 등록하도록 허용합니다.
  2. 가맹점 위치 검색: 고객이 근처의 커피 프랜차이즈를 확인하고 찾을 수 있습니다.
  3. 주문: 고객은 메뉴에서 여러 항목을 주문할 수 있습니다.
  4. 대기열 관리: 대기열에서 고객의 위치를 ​​추적하고 예상 대기 시간을 제공합니다.
  5. 주문 취소: 고객은 언제든지 대기열을 종료하고 주문을 취소할 수 있습니다.

2단계: ChatGPT를 사용하여 API 엔드포인트 생성

저는 ChatGPT에게 요구사항에 맞는 API 구조를 설계하는 데 도움을 달라고 요청했습니다. 다음은 제가 사용한 첫 번째 프롬프트의 예입니다.

프롬프트:

Spring Boot를 사용하여 사용자가 이름, 휴대폰 번호, 주소로 등록할 수 있는 사용자 등록 시스템용 API 엔드포인트를 만듭니다.

결과: ChatGPT가 여러 엔드포인트를 생성했습니다.

  • POST /users/register: 새로운 사용자를 등록합니다.
  • GET /franchises/nearby: 위도와 경도를 기준으로 근처 커피 프랜차이즈를 찾습니다.
  • POST /orders: 여러 품목을 주문합니다.
  • GET /orders/{orderId}/queue-position: 대기열에서 사용자의 위치를 ​​확인합니다.
  • DELETE /orders/{orderId}: 주문을 취소하고 대기열을 종료합니다.

3단계: 엔터티 디자인

주문 처리 서비스를 위해서는 User, Franchise, Order, Queue 및 OrderItem에 대한 엔터티가 필요했습니다. ChatGPT를 사용하여 필요한 필드로 이러한 엔터티를 정의했습니다.

프롬프트:

시스템의 사용자 엔터티를 디자인합니다. 사용자는 휴대폰 번호, 주소 및 역할(예: CUSTOMER)을 가질 수 있습니다.

결과: ChatGPT는 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
}

프랜차이즈, 주문, 대기열 엔터티에 대해 이 프로세스를 반복했습니다.

2일차: 비즈니스 로직 구현

4단계: 주문 배치 논리

기본 API와 엔터티가 설정되면 주문 배치를 위한 비즈니스 로직을 구현하는 단계로 넘어갔습니다. 메뉴의 여러 항목을 처리하고 대기열 위치를 관리해야 했기 때문에 이는 서비스의 중요한 부분이었습니다.

프롬프트:

여러 품목을 주문하는 논리를 구현합니다. 여기서 각 품목은 프랜차이즈의 특정 메뉴에 연결됩니다.

결과: ChatGPT는 이를 처리하기 위한 OrderService 설계 과정을 안내해 주었습니다. 구현의 일부는 다음과 같습니다.

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);
}

5단계: 대기열 관리

다음으로 고객을 대기열에 배치하고 위치를 추적하는 논리를 설계하는 데 도움을 주기 위해 ChatGPT에 요청했습니다.

프롬프트:

커피 프랜차이즈 시스템에서 주문 대기 시간과 대기열 위치는 어떻게 계산하나요?

결과: ChatGPT는 주문을 추적하고 타임스탬프에 따라 위치를 할당하는 QueueService 생성을 제안했습니다. 다음과 같이 구현했습니다.

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

평균 주문 처리 시간을 기준으로 대기 시간을 추정하는 방법도 안내했습니다.

6단계: 주문 취소

마지막으로 고객이 주문을 취소하고 대기열에서 나갈 수 있는 논리를 구현했습니다.

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

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

위 내용은 ChatGPT를 사용하여 주문 처리 서비스 구축(기여) 및 무사히 완료의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.