Initial commit of LittleShop project (excluding large archives)

- BTCPay Server integration
- TeleBot Telegram bot
- Review system
- Admin area
- Docker deployment configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-17 15:07:38 +01:00
parent bcca00ab39
commit e1b377a042
140 changed files with 32166 additions and 21089 deletions

View File

@@ -0,0 +1,236 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using LittleShop.Services;
using LittleShop.DTOs;
using System.Security.Claims;
namespace LittleShop.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ReviewsController : ControllerBase
{
private readonly IReviewService _reviewService;
private readonly ILogger<ReviewsController> _logger;
public ReviewsController(IReviewService reviewService, ILogger<ReviewsController> logger)
{
_reviewService = reviewService;
_logger = logger;
}
/// <summary>
/// Get reviews for a specific product (public - approved reviews only)
/// </summary>
[HttpGet("product/{productId}")]
public async Task<ActionResult<IEnumerable<ReviewDto>>> GetProductReviews(Guid productId)
{
try
{
var reviews = await _reviewService.GetReviewsByProductAsync(productId, approvedOnly: true);
return Ok(reviews);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting reviews for product {ProductId}", productId);
return StatusCode(500, new { Error = "Error retrieving product reviews" });
}
}
/// <summary>
/// Get review summary statistics for a product (public)
/// </summary>
[HttpGet("product/{productId}/summary")]
public async Task<ActionResult<ReviewSummaryDto>> GetProductReviewSummary(Guid productId)
{
try
{
var summary = await _reviewService.GetProductReviewSummaryAsync(productId);
if (summary == null)
{
return NotFound(new { Error = "Product not found" });
}
return Ok(summary);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting review summary for product {ProductId}", productId);
return StatusCode(500, new { Error = "Error retrieving review summary" });
}
}
/// <summary>
/// Check if customer can review a product (public)
/// </summary>
[HttpGet("eligibility/customer/{customerId}/product/{productId}")]
public async Task<ActionResult<CustomerReviewEligibilityDto>> CheckReviewEligibility(Guid customerId, Guid productId)
{
try
{
var eligibility = await _reviewService.CheckReviewEligibilityAsync(customerId, productId);
return Ok(eligibility);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error checking review eligibility for customer {CustomerId} and product {ProductId}",
customerId, productId);
return StatusCode(500, new { Error = "Error checking review eligibility" });
}
}
/// <summary>
/// Create a new review (public - for customers via TeleBot)
/// </summary>
[HttpPost]
public async Task<ActionResult<ReviewDto>> CreateReview([FromBody] CreateReviewDto createReviewDto)
{
try
{
var review = await _reviewService.CreateReviewAsync(createReviewDto);
return CreatedAtAction(nameof(GetReview), new { id = review.Id }, review);
}
catch (InvalidOperationException ex)
{
return BadRequest(new { Error = ex.Message });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error creating review for product {ProductId}", createReviewDto.ProductId);
return StatusCode(500, new { Error = "Error creating review" });
}
}
/// <summary>
/// Get specific review by ID
/// </summary>
[HttpGet("{id}")]
public async Task<ActionResult<ReviewDto>> GetReview(Guid id)
{
try
{
var review = await _reviewService.GetReviewByIdAsync(id);
if (review == null)
{
return NotFound(new { Error = "Review not found" });
}
return Ok(review);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting review {ReviewId}", id);
return StatusCode(500, new { Error = "Error retrieving review" });
}
}
/// <summary>
/// Get customer's reviews (public - for TeleBot)
/// </summary>
[HttpGet("customer/{customerId}")]
public async Task<ActionResult<IEnumerable<ReviewDto>>> GetCustomerReviews(Guid customerId)
{
try
{
var reviews = await _reviewService.GetReviewsByCustomerAsync(customerId);
return Ok(reviews);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting reviews for customer {CustomerId}", customerId);
return StatusCode(500, new { Error = "Error retrieving customer reviews" });
}
}
/// <summary>
/// Get pending reviews for admin approval
/// </summary>
[HttpGet("pending")]
[Authorize(AuthenticationSchemes = "Bearer", Roles = "Admin")]
public async Task<ActionResult<IEnumerable<ReviewDto>>> GetPendingReviews()
{
try
{
var reviews = await _reviewService.GetPendingReviewsAsync();
return Ok(reviews);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting pending reviews");
return StatusCode(500, new { Error = "Error retrieving pending reviews" });
}
}
/// <summary>
/// Update a review (admin only)
/// </summary>
[HttpPut("{id}")]
[Authorize(AuthenticationSchemes = "Bearer", Roles = "Admin")]
public async Task<IActionResult> UpdateReview(Guid id, [FromBody] UpdateReviewDto updateReviewDto)
{
try
{
var success = await _reviewService.UpdateReviewAsync(id, updateReviewDto);
if (!success)
{
return NotFound(new { Error = "Review not found" });
}
return NoContent();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error updating review {ReviewId}", id);
return StatusCode(500, new { Error = "Error updating review" });
}
}
/// <summary>
/// Approve a review (admin only)
/// </summary>
[HttpPost("{id}/approve")]
[Authorize(AuthenticationSchemes = "Bearer", Roles = "Admin")]
public async Task<IActionResult> ApproveReview(Guid id)
{
try
{
var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (!Guid.TryParse(userIdClaim, out var userId))
{
return BadRequest(new { Error = "Invalid user ID" });
}
var success = await _reviewService.ApproveReviewAsync(id, userId);
if (!success)
{
return NotFound(new { Error = "Review not found" });
}
return Ok(new { Message = "Review approved successfully" });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error approving review {ReviewId}", id);
return StatusCode(500, new { Error = "Error approving review" });
}
}
/// <summary>
/// Delete a review (admin only - soft delete)
/// </summary>
[HttpDelete("{id}")]
[Authorize(AuthenticationSchemes = "Bearer", Roles = "Admin")]
public async Task<IActionResult> DeleteReview(Guid id)
{
try
{
var success = await _reviewService.DeleteReviewAsync(id);
if (!success)
{
return NotFound(new { Error = "Review not found" });
}
return Ok(new { Message = "Review deleted successfully" });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error deleting review {ReviewId}", id);
return StatusCode(500, new { Error = "Error deleting review" });
}
}
}

View File

@@ -1,141 +1,141 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using LittleShop.Services;
using LittleShop.DTOs;
using LittleShop.Data;
namespace LittleShop.Controllers;
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
private readonly ICategoryService _categoryService;
private readonly IProductService _productService;
private readonly LittleShopContext _context;
public TestController(ICategoryService categoryService, IProductService productService, LittleShopContext context)
{
_categoryService = categoryService;
_productService = productService;
_context = context;
}
[HttpPost("create-product")]
public async Task<IActionResult> CreateTestProduct()
{
try
{
// Get the first category
var categories = await _categoryService.GetAllCategoriesAsync();
var firstCategory = categories.FirstOrDefault();
if (firstCategory == null)
{
return BadRequest("No categories found. Create a category first.");
}
var product = await _productService.CreateProductAsync(new CreateProductDto
{
Name = "Test Product via API",
Description = "This product was created via the test API endpoint 🚀",
Price = 49.99m,
Weight = 0.5m,
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
CategoryId = firstCategory.Id
});
return Ok(new {
message = "Product created successfully",
product = product
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
[HttpPost("setup-test-data")]
public async Task<IActionResult> SetupTestData()
{
try
{
// Create test category
var category = await _categoryService.CreateCategoryAsync(new CreateCategoryDto
{
Name = "Electronics",
Description = "Electronic devices and gadgets"
});
// Create test product
var product = await _productService.CreateProductAsync(new CreateProductDto
{
Name = "Sample Product",
Description = "This is a test product with emoji support 📱💻",
Price = 99.99m,
Weight = 1.5m,
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
CategoryId = category.Id
});
return Ok(new {
message = "Test data created successfully",
category = category,
product = product
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
[HttpPost("cleanup-bots")]
public async Task<IActionResult> CleanupBots()
{
try
{
// Get count before cleanup
var totalBots = await _context.Bots.CountAsync();
// Keep only the most recent active bot per platform
var keepBots = await _context.Bots
.Where(b => b.IsActive && b.Status == Enums.BotStatus.Active)
.GroupBy(b => b.PlatformId)
.Select(g => g.OrderByDescending(b => b.LastSeenAt ?? b.CreatedAt).First())
.ToListAsync();
var keepBotIds = keepBots.Select(b => b.Id).ToList();
// Delete old/inactive bots and related data
var botsToDelete = await _context.Bots
.Where(b => !keepBotIds.Contains(b.Id))
.ToListAsync();
_context.Bots.RemoveRange(botsToDelete);
await _context.SaveChangesAsync();
var deletedCount = botsToDelete.Count;
var remainingCount = keepBots.Count;
return Ok(new {
message = "Bot cleanup completed",
totalBots = totalBots,
deletedBots = deletedCount,
remainingBots = remainingCount,
keptBots = keepBots.Select(b => new {
id = b.Id,
name = b.Name,
platformUsername = b.PlatformUsername,
lastSeen = b.LastSeenAt,
created = b.CreatedAt
})
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using LittleShop.Services;
using LittleShop.DTOs;
using LittleShop.Data;
namespace LittleShop.Controllers;
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
private readonly ICategoryService _categoryService;
private readonly IProductService _productService;
private readonly LittleShopContext _context;
public TestController(ICategoryService categoryService, IProductService productService, LittleShopContext context)
{
_categoryService = categoryService;
_productService = productService;
_context = context;
}
[HttpPost("create-product")]
public async Task<IActionResult> CreateTestProduct()
{
try
{
// Get the first category
var categories = await _categoryService.GetAllCategoriesAsync();
var firstCategory = categories.FirstOrDefault();
if (firstCategory == null)
{
return BadRequest("No categories found. Create a category first.");
}
var product = await _productService.CreateProductAsync(new CreateProductDto
{
Name = "Test Product via API",
Description = "This product was created via the test API endpoint 🚀",
Price = 49.99m,
Weight = 0.5m,
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
CategoryId = firstCategory.Id
});
return Ok(new {
message = "Product created successfully",
product = product
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
[HttpPost("setup-test-data")]
public async Task<IActionResult> SetupTestData()
{
try
{
// Create test category
var category = await _categoryService.CreateCategoryAsync(new CreateCategoryDto
{
Name = "Electronics",
Description = "Electronic devices and gadgets"
});
// Create test product
var product = await _productService.CreateProductAsync(new CreateProductDto
{
Name = "Sample Product",
Description = "This is a test product with emoji support 📱💻",
Price = 99.99m,
Weight = 1.5m,
WeightUnit = LittleShop.Enums.ProductWeightUnit.Pounds,
CategoryId = category.Id
});
return Ok(new {
message = "Test data created successfully",
category = category,
product = product
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
[HttpPost("cleanup-bots")]
public async Task<IActionResult> CleanupBots()
{
try
{
// Get count before cleanup
var totalBots = await _context.Bots.CountAsync();
// Keep only the most recent active bot per platform
var keepBots = await _context.Bots
.Where(b => b.IsActive && b.Status == Enums.BotStatus.Active)
.GroupBy(b => b.PlatformId)
.Select(g => g.OrderByDescending(b => b.LastSeenAt ?? b.CreatedAt).First())
.ToListAsync();
var keepBotIds = keepBots.Select(b => b.Id).ToList();
// Delete old/inactive bots and related data
var botsToDelete = await _context.Bots
.Where(b => !keepBotIds.Contains(b.Id))
.ToListAsync();
_context.Bots.RemoveRange(botsToDelete);
await _context.SaveChangesAsync();
var deletedCount = botsToDelete.Count;
var remainingCount = keepBots.Count;
return Ok(new {
message = "Bot cleanup completed",
totalBots = totalBots,
deletedBots = deletedCount,
remainingBots = remainingCount,
keptBots = keepBots.Select(b => new {
id = b.Id,
name = b.Name,
platformUsername = b.PlatformUsername,
lastSeen = b.LastSeenAt,
created = b.CreatedAt
})
});
}
catch (Exception ex)
{
return BadRequest(new { error = ex.Message });
}
}
}