top of page

Vibe Coding Online Order System - Version 1.1

  • Writer: Renee Li
    Renee Li
  • Oct 25
  • 3 min read

Reason and ideas around version 1.1 is in this blog. Key idea is to add state/ status in the code, for better data manipulation.


Output of version 1.1 vibe coding is here.



using System;
using System.Collections.Generic;

namespace BookOrderSystemV1_EventState
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("📚 Welcome to RococoBookOrder V1 – Event + State Driven");

            var flow = new OrderFlow();
            flow.Start();
        }
    }

    public class OrderFlow
    {
        private Order order = new();

        public event Action OnLoginCompleted;
        public event Action OnCartValidated;
        public event Action OnProfileCompleted;
        public event Action OnPaymentConfirmed;

        public void Start()
        {
            // Wire up the flow
            OnLoginCompleted += HandleCartStep;
            OnCartValidated += HandleProfileStep;
            OnProfileCompleted += HandlePaymentStep;
            OnPaymentConfirmed += HandleShipment;

            // Start the first step
            HandleLoginStep();
        }

        void HandleLoginStep()
        {
            Console.WriteLine("\n🔐 Step 1: Create Login");
            order.User = User.Create();
            if (order.User != null)
            {
                order.Advance(OrderState.LoginCreated);
                OnLoginCompleted?.Invoke();
            }
        }

        void HandleCartStep()
        {
            Console.WriteLine("\n🛒 Step 2: Select Books");
            order.Cart = Cart.Create();
            if (order.Cart != null)
            {
                order.Advance(OrderState.CartValidated);
                OnCartValidated?.Invoke();
            }
        }

        void HandleProfileStep()
        {
            Console.WriteLine("\n📦 Step 3: Enter Shipping Info");
            order.Profile = UserProfile.Create();
            if (order.Profile != null)
            {
                order.Advance(OrderState.ProfileCompleted);
                OnProfileCompleted?.Invoke();
            }
        }

        void HandlePaymentStep()
        {
            Console.WriteLine("\n💳 Step 4: Enter Payment Details");
            order.Payment = Payment.Create();
            if (order.Payment != null)
            {
                order.Advance(OrderState.PaymentConfirmed);
                OnPaymentConfirmed?.Invoke();
            }
        }

        void HandleShipment()
        {
            Console.WriteLine("\n🚚 Step 5: Prepare Shipment");
            order.Advance(OrderState.ShipmentPrepared);
            Shipment.Prepare(order);
        }
    }

    public enum OrderState
    {
        Created,
        LoginCreated,
        CartValidated,
        ProfileCompleted,
        PaymentConfirmed,
        ShipmentPrepared
    }

    public class Order
    {
        public User User;
        public Cart Cart;
        public UserProfile Profile;
        public Payment Payment;
        public OrderState CurrentState { get; private set; } = OrderState.Created;
        public List<OrderState> History { get; private set; } = new();

        public void Advance(OrderState nextState)
        {
            CurrentState = nextState;
            History.Add(nextState);
            Console.WriteLine($"🔄 Order state updated to: {CurrentState}");
        }
    }

    public class User
    {
        public string Username;
        public string Email;
        public string Password;

        public static User Create()
        {
            Console.Write("Username: ");
            var username = Console.ReadLine();
            Console.Write("Email: ");
            var email = Console.ReadLine();
            Console.Write("Password: ");
            var password = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
            {
                Console.WriteLine("⚠️ All fields are required.");
                return null;
            }

            return new User { Username = username, Email = email, Password = password };
        }
    }

    public class Cart
    {
        public Dictionary<string, int> Items = new();

        public static Cart Create()
        {
            var cart = new Cart();

            while (true)
            {
                Console.Write("Enter book title (or 'done'): ");
                var title = Console.ReadLine();
                if (title.ToLower() == "done") break;

                Console.Write("Quantity: ");
                if (!int.TryParse(Console.ReadLine(), out int qty) || qty < 1)
                {
                    Console.WriteLine("⚠️ Invalid quantity. Book not added.");
                    continue;
                }

                cart.Items[title] = qty;
            }

            if (cart.Items.Count == 0)
            {
                Console.WriteLine("⚠️ Cart cannot be empty.");
                return null;
            }

            return cart;
        }
    }

    public class UserProfile
    {
        public string ShippingAddress;

        public static UserProfile Create()
        {
            Console.Write("Shipping Address: ");
            var address = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(address))
            {
                Console.WriteLine("⚠️ Shipping address is required.");
                return null;
            }

            return new UserProfile { ShippingAddress = address };
        }
    }

    public class Payment
    {
        public string CardNumber;

        public static Payment Create()
        {
            Console.Write("Card Number: ");
            var card = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(card))
            {
                Console.WriteLine("⚠️ Payment details required.");
                return null;
            }

            Console.WriteLine("💳 Payment gateway confirmed.");
            return new Payment { CardNumber = card };
        }
    }

    public class Shipment
    {
        public static void Prepare(Order order)
        {
            Console.WriteLine($"📦 Shipment prepared for {order.User.Username} with {order.Cart.Items.Count} book(s).");
            Console.WriteLine("🛑 Program ends here for V1. Admin system will take over.");
        }
    }
}

🧠 What You’ve Achieved

  • Events drive the flow

  • State tracks progress and history

  • Modular design ready for upgrades

  • Expressive feedback for each step


God, I love the word data manipulation. I hate to manipulate people, but love manipulating data! Even the idea of it excites me! lol


Stay tuned!

Comments


bottom of page