Fix admin route access and backend configuration
- Added /admin redirect to login page in nginx config - Fixed backend server.js route ordering for proper admin handling - Updated authentication middleware and routes - Added user management routes - Configured PostgreSQL integration - Updated environment configuration
This commit is contained in:
64
Sky_Art_shop/Services/MongoDBService.cs
Normal file
64
Sky_Art_shop/Services/MongoDBService.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using MongoDB.Driver;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SkyArtShop.Services
|
||||
{
|
||||
public class MongoDBSettings
|
||||
{
|
||||
public string ConnectionString { get; set; } = string.Empty;
|
||||
public string DatabaseName { get; set; } = string.Empty;
|
||||
public Dictionary<string, string> Collections { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public class MongoDBService
|
||||
{
|
||||
private readonly IMongoDatabase _database;
|
||||
private readonly MongoDBSettings _settings;
|
||||
|
||||
public MongoDBService(IOptions<MongoDBSettings> settings)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
var client = new MongoClient(_settings.ConnectionString);
|
||||
_database = client.GetDatabase(_settings.DatabaseName);
|
||||
}
|
||||
|
||||
public IMongoCollection<T> GetCollection<T>(string collectionName)
|
||||
{
|
||||
return _database.GetCollection<T>(collectionName);
|
||||
}
|
||||
|
||||
// Helper methods for common operations
|
||||
public async Task<List<T>> GetAllAsync<T>(string collectionName)
|
||||
{
|
||||
var collection = GetCollection<T>(collectionName);
|
||||
return await collection.Find(_ => true).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<T> GetByIdAsync<T>(string collectionName, string id)
|
||||
{
|
||||
var collection = GetCollection<T>(collectionName);
|
||||
var filter = Builders<T>.Filter.Eq("_id", MongoDB.Bson.ObjectId.Parse(id));
|
||||
return await collection.Find(filter).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task InsertAsync<T>(string collectionName, T document)
|
||||
{
|
||||
var collection = GetCollection<T>(collectionName);
|
||||
await collection.InsertOneAsync(document);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync<T>(string collectionName, string id, T document)
|
||||
{
|
||||
var collection = GetCollection<T>(collectionName);
|
||||
var filter = Builders<T>.Filter.Eq("_id", MongoDB.Bson.ObjectId.Parse(id));
|
||||
await collection.ReplaceOneAsync(filter, document);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync<T>(string collectionName, string id)
|
||||
{
|
||||
var collection = GetCollection<T>(collectionName);
|
||||
var filter = Builders<T>.Filter.Eq("_id", MongoDB.Bson.ObjectId.Parse(id));
|
||||
await collection.DeleteOneAsync(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Sky_Art_shop/Services/SlugService.cs
Normal file
33
Sky_Art_shop/Services/SlugService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SkyArtShop.Services
|
||||
{
|
||||
public class SlugService
|
||||
{
|
||||
public string GenerateSlug(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return string.Empty;
|
||||
|
||||
// Convert to lowercase
|
||||
var slug = text.ToLowerInvariant();
|
||||
|
||||
// Replace spaces with hyphens
|
||||
slug = slug.Replace(" ", "-");
|
||||
|
||||
// Replace & with "and"
|
||||
slug = slug.Replace("&", "and");
|
||||
|
||||
// Remove invalid characters
|
||||
slug = Regex.Replace(slug, @"[^a-z0-9\-]", "");
|
||||
|
||||
// Replace multiple hyphens with single hyphen
|
||||
slug = Regex.Replace(slug, @"-+", "-");
|
||||
|
||||
// Trim hyphens from start and end
|
||||
slug = slug.Trim('-');
|
||||
|
||||
return slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user