Implement complete e-commerce functionality with shipping and order management

Features Added:
- Standard e-commerce properties (Price, Weight, shipping fields)
- Order management with Create/Edit views and shipping information
- ShippingRates system for weight-based shipping calculations
- Comprehensive test coverage with JWT authentication tests
- Sample data seeder with 5 orders demonstrating full workflow
- Photo upload functionality for products
- Multi-cryptocurrency payment support (BTC, XMR, USDT, etc.)

Database Changes:
- Added ShippingRates table
- Added shipping fields to Orders (Name, Address, City, PostCode, Country)
- Renamed properties to standard names (BasePrice to Price, ProductWeight to Weight)
- Added UpdatedAt timestamps to models

UI Improvements:
- Added Create/Edit views for Orders
- Added ShippingRates management UI
- Updated navigation menu with Shipping option
- Enhanced Order Details view with shipping information

Sample Data:
- 3 Categories (Electronics, Clothing, Books)
- 5 Products with various prices
- 5 Shipping rates (Royal Mail options)
- 5 Orders in different statuses (Pending to Delivered)
- 3 Crypto payments demonstrating payment flow

Security:
- All API endpoints secured with JWT authentication
- No public endpoints - client apps must authenticate
- Privacy-focused design with minimal data collection

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sysadmin
2025-08-20 17:37:24 +01:00
parent df71a80eb9
commit a281bb2896
101 changed files with 4874 additions and 159 deletions

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeleBot
{
public class BotScript
{
public string WelcomeText { get; set; }
public Dictionary<Guid, BotOption> Questions { get; internal set; } = new Dictionary<Guid, BotOption>();
public Dictionary<Guid, string> Answers { get; internal set; } = new Dictionary<Guid, string>();
public int Stage { get; set; }
public static BotScript CreateBotScript(string welcomeText)
{
var bs = new BotScript();
bs.WelcomeText = welcomeText;
return bs;
}
public void AddScaledQuestion(string question)
{
AddQuestion(question, ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
}
public void AddQuestion(string question, string[] answers)
{
var q = new BotOption();
q.Order = Questions.Count() + 1;
q.Text = question;
q.Options = answers;
Questions.Add(q.Id,q);
}
}
public class BotOption
{
public Guid Id { get; set; } = Guid.NewGuid();
public int Order { get; set; }
public string Text { get; set; }
public string[] Options { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
namespace TeleBot
{
internal class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello, World!");
var bot = new TelgramBotService();
await bot.Startup();
}
}
}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="22.5.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeleBot
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;
public class TelgramBotService
{
private readonly string BotToken = "7880403661:AAGma1wAyoHsmG45iO6VvHCqzimhJX1pp14";
public BotScript Master { get; set; }
public Dictionary<long, BotScript> Chats { get; set; } = new Dictionary<long, BotScript>();
public async Task Startup()
{
if (Master == null)
{
Master = BotScript.CreateBotScript("Anonymous Feedback Survey for The Sweetshop \r\n\r\nWed love to hear your thoughts so we can improve your experience and keep the shop evolving in the best way possible.");
Master.AddScaledQuestion("How would you rate communication at the shop (including updates, clarity, and friendliness)?\r\n(1 = Poor | 10 = Excellent)");
Master.AddScaledQuestion("How would you rate the quality of the products?\r\n(1 = Poor | 10 = Excellent)");
}
var botClient = new TelegramBotClient(BotToken);
using var cts = new CancellationTokenSource();
var receiverOptions = new ReceiverOptions
{
AllowedUpdates = Array.Empty<UpdateType>() // Receive all updates
};
botClient.StartReceiving(
HandleUpdateAsync,
HandleErrorAsync,
receiverOptions,
cancellationToken: cts.Token
);
var me = await botClient.GetMe();
Console.WriteLine($"Bot started: {me.Username}");
Console.ReadLine();
cts.Cancel();
}
private async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
if (update.Message is { } message)
{
var chatId = message.Chat.Id;
if (!Chats.ContainsKey(chatId))
{
var s = Master;
Chats.Add(chatId, s);
}
//if (message.Text == "/start")
//{
await ProcessMessage(botClient, chatId, cancellationToken);
//var responseText = $"Hello, {message.From?.FirstName}! You said: {message.Text}";
//await botClient.SendMessage(chatId, responseText, cancellationToken: cancellationToken);
}
else if (update.CallbackQuery is { } callbackQuery)
{
var data = callbackQuery.Data?.Split(':');
var chatId = callbackQuery.Message.Chat.Id;
var aID = Guid.Parse(data[0]);
Chats[chatId].Answers.Add(aID, data[1]);
var response = $"Thank for choosing: {data[1]} in response to '{Chats[chatId].Questions.First(x => x.Key == aID).Value.Text}'";
await botClient.SendMessage(callbackQuery.Message.Chat.Id, response, cancellationToken: cancellationToken);
Chats[chatId].Stage++;
if (Chats[chatId].Stage > Chats[chatId].Questions.Count)
{
await botClient.SendMessage(chatId, "Thank you for completing our questions, we appreciete your feedback!", cancellationToken: cancellationToken);
}
else
{
await ProcessMessage(botClient, chatId, cancellationToken);
}
}
}
private async Task ProcessMessage(ITelegramBotClient botClient, long chatId, CancellationToken cancellationToken)
{
if (Chats[chatId].Stage > Chats[chatId].Questions.Count)
{
await botClient.SendMessage(chatId, "You have already completed the questionaire. Thank you for your feedback.", cancellationToken: cancellationToken);
}
else
{
switch (Chats[chatId].Stage)
{
case 0:
await botClient.SendMessage(chatId, Chats[chatId].WelcomeText, cancellationToken: cancellationToken);
Chats[chatId].Stage++;
break;
default:
var q = Chats[chatId].Questions.OrderBy(x => x.Value.Order).Skip(Chats[chatId].Stage - 1).Take(1).FirstOrDefault();
var opts = new InlineKeyboardMarkup(new[]
{
q.Value.Options.Take(5).Select(x => InlineKeyboardButton.WithCallbackData(x, $"{q.Key}:{x}")),
q.Value.Options.Skip(5).Select(x => InlineKeyboardButton.WithCallbackData(x, $"{q.Key}:{x}"))
});
await botClient.SendMessage(chatId, q.Value.Text, replyMarkup: opts, cancellationToken: cancellationToken);
opts = new InlineKeyboardMarkup(q.Value.Options.Skip(5).Select(x => InlineKeyboardButton.WithCallbackData(x, $"{q.Key}:{x}")));
await botClient.SendMessage(chatId, "", replyMarkup: opts, cancellationToken: cancellationToken);
break;
}
}
}
private Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
{
Console.WriteLine($"Error: {exception.Message}");
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,96 @@
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class TelegramClient
{
private static readonly string BotToken = "7330819864:AAHx9GEL-G-WeH2ON5-ncdsbbhV6YaOqZzg";
private static readonly string ApiUrl = $"https://api.telegram.org/bot{BotToken}/";
static async Task Main()
{
Console.WriteLine("Telegram Bot Client Started...");
while (true)
{
await ReceiveMessagesAsync();
await Task.Delay(5000); // Polling delay
}
}
private static async Task SendMessageAsync(string chatId, string message)
{
using HttpClient client = new HttpClient();
var payload = new
{
chat_id = chatId,
text = message
};
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
try
{
var response = await client.PostAsync(ApiUrl + "sendMessage", content);
var responseText = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseText}");
}
catch (Exception ex)
{
Console.WriteLine($"Error sending message: {ex.Message}");
}
}
private static async Task ReceiveMessagesAsync()
{
using HttpClient client = new HttpClient();
try
{
var response = await client.GetAsync(ApiUrl + "getUpdates");
response.EnsureSuccessStatusCode();
var responseText = await response.Content.ReadAsStringAsync();
var updates = JsonSerializer.Deserialize<TelegramUpdateResponse>(responseText);
if (updates?.Result != null)
{
foreach (var update in updates.Result)
{
Console.WriteLine($"Received message from {update.Message.Chat.Id}: {update.Message.Text}");
await SendMessageAsync(update.Message.Chat.Id.ToString(), "Message received!");
}
}
}
catch (HttpRequestException httpEx)
{
Console.WriteLine($"HTTP error: {httpEx.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
}
class TelegramUpdateResponse
{
public TelegramUpdate[] Result { get; set; }
}
class TelegramUpdate
{
public TelegramMessage Message { get; set; }
}
class TelegramMessage
{
public TelegramChat Chat { get; set; }
public string Text { get; set; }
}
class TelegramChat
{
public long Id { get; set; }
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>