Skip to content

Commit 8b7f5dd

Browse files
committed
wordpress detail
1 parent e013751 commit 8b7f5dd

33 files changed

+646
-316
lines changed

Controllers/CatalogController.cs

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public async Task<IActionResult> DeleteAsync([FromRoute] Guid id)
9696
}));
9797
}
9898

99+
var tags = await _context.WorkItems.Where(x => x.WorkId == id).ToListAsync();
100+
_context.WorkItems.RemoveRange(tags);
101+
99102
_context.Catalogs.Remove(catalog);
100103
await _context.SaveChangesAsync();
101104
return Ok(IdentityResult.Success);

Controllers/UserController.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ public async Task<IActionResult> ListAsync([FromQuery] BasicFilterOptions filter
4646
}
4747

4848
[HttpGet("{id}")]
49-
public async Task<IActionResult> FindByIdAsync([FromRoute] Guid id) => Ok(await _userService.GetCurrentUserAsync(id));
49+
public async Task<IActionResult> FindByIdAsync([FromRoute] Guid id)
50+
{
51+
var user = await _userService.GetCurrentUserAsync(id);
52+
if (user is null) return BadRequest("User not found!");
53+
return Ok(user);
54+
}
5055

51-
[HttpGet("")]
56+
[HttpGet]
5257
public async Task<IActionResult> GetCurrentUserAsync() => Ok(await _userService.GetCurrentUserAsync(User.GetId()));
5358

5459
[HttpGet("users-in-role/{roleName}")]
@@ -72,6 +77,7 @@ public async Task<IActionResult> PasswordSignInAsync([FromBody] LoginModel login
7277
var authClaims = new List<Claim>
7378
{
7479
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(), ClaimValueTypes.String),
80+
new Claim(ClaimTypes.Name, user.UserName, ClaimValueTypes.String),
7581
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
7682
};
7783

@@ -110,13 +116,7 @@ public async Task<IActionResult> PasswordSignInAsync([FromBody] LoginModel login
110116
public async Task<IActionResult> DeleteAsync([FromRoute] string id)
111117
{
112118
var user = await _userManager.FindByIdAsync(id);
113-
if (user is null)
114-
{
115-
return Ok(IdentityResult.Failed(new IdentityError
116-
{
117-
Description = "User not found"
118-
}));
119-
}
119+
if (user is null) return BadRequest("User not found!");
120120
return Ok(await _userManager.DeleteAsync(user));
121121
}
122122

Core/Foundations/DynamicPageModel.cs

+29-11
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,41 @@ public DynamicPageModel(ICatalogService catalogService)
1313
_catalogService = catalogService;
1414
}
1515

16-
public Catalog PageData { private set; get; } = new();
16+
public Catalog PageData { protected set; get; } = new();
17+
public Catalog? Category { private set; get; }
1718

1819
public override async Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
1920
{
21+
context.RouteData.Values.TryGetValue("category", out var category);
2022
context.RouteData.Values.TryGetValue("normalizedName", out var normalizedName);
21-
var catalog = await _catalogService.GetByNameAsync(normalizedName?.ToString());
22-
if (catalog is null)
23+
if (!string.IsNullOrEmpty(category?.ToString()))
2324
{
24-
context.HttpContext.Response.StatusCode = 404;
25-
context.HttpContext.Response.Redirect("/exception/notfound");
26-
return;
25+
Category = await _catalogService.GetByNameAsync(category?.ToString());
26+
RouteData.Values.TryAdd("Parent", Category);
27+
if (Category != null && CatalogType.WordPress == Category.Type)
28+
{
29+
PageData = new Catalog
30+
{
31+
NormalizedName = normalizedName?.ToString() ?? string.Empty
32+
};
33+
}
2734
}
28-
PageData = catalog;
29-
ViewData["Title"] = catalog.Name;
30-
ViewData["Description"] = catalog.Description;
31-
ViewData["Image"] = catalog.Thumbnail;
32-
RouteData.Values.TryAdd(nameof(Catalog), catalog);
35+
else
36+
{
37+
38+
var catalog = await _catalogService.GetByNameAsync(normalizedName?.ToString());
39+
if (catalog is null)
40+
{
41+
context.HttpContext.Response.StatusCode = 404;
42+
context.HttpContext.Response.Redirect("/exception/notfound");
43+
return;
44+
}
45+
PageData = catalog;
46+
ViewData["Title"] = catalog.Name;
47+
ViewData["Description"] = catalog.Description;
48+
ViewData["Image"] = catalog.Thumbnail;
49+
}
50+
RouteData.Values.TryAdd(nameof(Catalog), PageData);
3351
}
3452
}
3553
}

Core/Interfaces/IService/IUserService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IUserService
99
{
1010
Task<IdentityResult> CreateAsync(CreateUserModel model);
1111
Task<IdentityResult> ChangePasswordAsync(ChangePasswordModel model);
12-
Task<CurrentUserViewModel> GetCurrentUserAsync(Guid id);
12+
Task<CurrentUserViewModel?> GetCurrentUserAsync(Guid id);
1313
Task<IdentityResult> AddToRoleAsync(AddToRoleModel model);
1414
Task<dynamic> GetUsersInRoleAsync(string roleName);
1515
Task<IdentityResult> RemoveFromRoleAsync(RemoveFromRoleModel args);

Core/Services/UserService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ public async Task<IdentityResult> CreateAsync(CreateUserModel model)
6767
}, model.Password);
6868
}
6969

70-
public async Task<CurrentUserViewModel> GetCurrentUserAsync(Guid id)
70+
public async Task<CurrentUserViewModel?> GetCurrentUserAsync(Guid id)
7171
{
7272
var user = await FindAsync(id);
73-
if (user is null) return new CurrentUserViewModel();
73+
if (user is null) return default;
7474
return new CurrentUserViewModel
7575
{
7676
Id = user.Id,
7777
Email = user.Email,
7878
PhoneNumber = user.PhoneNumber,
7979
UserName = user.UserName,
80+
Name = user.Name,
8081
Roles = await _userManager.GetRolesAsync(user)
8182
};
8283
}

Data/ContentGenerators/ComponentGenerator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ private static IEnumerable<Component> GetData()
2323
{
2424
var display = AttributeHelper.GetDisplay(cls);
2525
if (display is null) continue;
26+
var filter = display.GetAutoGenerateFilter() ?? false;
27+
if (filter) continue;
2628
yield return new Component
2729
{
2830
Active = true,

Entities/ApplicationUser.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ namespace Waffle.Entities;
44

55
public class ApplicationUser : IdentityUser<Guid>
66
{
7-
7+
public string? Name { get; set; }
8+
public string? Address { get; set; }
9+
public DateTime? DateOfBirth { get; set; }
10+
public bool? Gender { get; set; }
811
}

Entities/Catalog.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Catalog : BaseEntity
2929
public string? Thumbnail { get; set; }
3030
[JsonPropertyName("active")]
3131
public bool Active { get; set; }
32+
[JsonPropertyName("createdBy")]
3233
public Guid? CreatedBy { get; set; }
3334
}
3435

@@ -43,5 +44,6 @@ public enum CatalogType
4344
Album = 8,
4445
Tag = 9,
4546
Video = 10,
46-
Game = 11
47+
Game = 11,
48+
WordPress = 12
4749
}

Entities/Ecommerces/OrderDetail.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
namespace Waffle.Entities.Ecommerces
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace Waffle.Entities.Ecommerces;
4+
5+
public class OrderDetail : BaseEntity
26
{
3-
public class OrderDetail : BaseEntity
4-
{
5-
public Guid OrderId { get; set; }
6-
public Guid ProductId { get; set; }
7-
public decimal Price { get; set; }
8-
public int Quantity { get; set; }
9-
}
7+
public Guid OrderId { get; set; }
8+
public Guid ProductId { get; set; }
9+
[Column(TypeName = "money")]
10+
public decimal Price { get; set; }
11+
public decimal Quantity { get; set; }
1012
}

Entities/Ecommerces/Product.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.ComponentModel.DataAnnotations.Schema;
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
23

34
namespace Waffle.Entities.Ecommerces;
45

@@ -7,6 +8,7 @@ public class Product : BaseEntity
78
public Guid CatalogId { get; set; }
89
[Column(TypeName = "money")]
910
public decimal? Price { get; set; }
11+
[StringLength(50)]
1012
public string? SKU { get; set; }
1113
public decimal? UnitInStock { get; set; }
1214
[Column(TypeName = "money")]

Entities/FileContent.cs

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
using System.ComponentModel.DataAnnotations.Schema;
22
using System.Text.Json.Serialization;
33

4-
namespace Waffle.Entities
4+
namespace Waffle.Entities;
5+
6+
public class FileContent : BaseEntity
57
{
6-
public class FileContent : BaseEntity
8+
public FileContent()
79
{
8-
public FileContent()
9-
{
10-
Name = string.Empty;
11-
Type = string.Empty;
12-
Url = string.Empty;
13-
}
14-
[JsonPropertyName("name")]
15-
public string Name { get; set; }
16-
[JsonPropertyName("size")]
17-
[Column(TypeName = "decimal(18, 2)")]
18-
public decimal Size { get; set; }
19-
[JsonPropertyName("type")]
20-
public string Type { get; set; }
21-
[JsonPropertyName("url")]
22-
public string Url { get; set; }
10+
Name = string.Empty;
11+
Type = string.Empty;
12+
Url = string.Empty;
2313
}
14+
[JsonPropertyName("name")]
15+
public string Name { get; set; }
16+
[JsonPropertyName("size")]
17+
[Column(TypeName = "decimal(18, 2)")]
18+
public decimal Size { get; set; }
19+
[JsonPropertyName("type")]
20+
public string Type { get; set; }
21+
[JsonPropertyName("url")]
22+
public string Url { get; set; }
2423
}
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using Waffle.ExternalAPI.Models;
2+
using Waffle.Models;
23

3-
namespace Waffle.ExternalAPI.Interfaces
4+
namespace Waffle.ExternalAPI.Interfaces;
5+
6+
public interface IWordPressService
47
{
5-
public interface IWordPressService
6-
{
7-
Task<WordPressPost?> GetPostAsync(string domain, int id);
8-
}
8+
Task<WordPressPost?> GetPostAsync(string domain, string? postId);
9+
Task<IEnumerable<WordPressPost>?> ListPostAsync(string domain, IFilterOptions filterOptions);
910
}

ExternalAPI/Models/WordPressModel.cs

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
using System.Text.Json.Serialization;
22

3-
namespace Waffle.ExternalAPI.Models
3+
namespace Waffle.ExternalAPI.Models;
4+
5+
public class WordPressPost
46
{
5-
public class WordPressPost
6-
{
7-
[JsonPropertyName("id")]
8-
public int Id { get; set; }
9-
[JsonPropertyName("slug")]
10-
public string? Slug { get; set; }
11-
[JsonPropertyName("title")]
12-
public WordPressTitle Title { get; set; } = new();
13-
[JsonPropertyName("content")]
14-
public WordPressContent Content { get; set; } = new();
15-
}
7+
[JsonPropertyName("id")]
8+
public int Id { get; set; }
9+
[JsonPropertyName("slug")]
10+
public string? Slug { get; set; }
11+
[JsonPropertyName("title")]
12+
public WordPressTitle Title { get; set; } = new();
13+
[JsonPropertyName("content")]
14+
public WordPressContent Content { get; set; } = new();
15+
}
1616

17-
public class WordPressTitle
18-
{
19-
[JsonPropertyName("rendered")]
20-
public string? Rendered { get; set; }
21-
}
17+
public class WordPressTitle
18+
{
19+
[JsonPropertyName("rendered")]
20+
public string? Rendered { get; set; }
21+
}
2222

23-
public class WordPressContent
24-
{
25-
[JsonPropertyName("rendered")]
26-
public string? Rendered { get; set; }
27-
}
23+
public class WordPressContent
24+
{
25+
[JsonPropertyName("rendered")]
26+
public string? Rendered { get; set; }
2827
}
+43-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
using System.Text.Json;
22
using Waffle.ExternalAPI.Interfaces;
33
using Waffle.ExternalAPI.Models;
4+
using Waffle.Models;
45

5-
namespace Waffle.ExternalAPI.Services
6+
namespace Waffle.ExternalAPI.Services;
7+
8+
public class WordPressService : IWordPressService
69
{
7-
public class WordPressService : IWordPressService
10+
private readonly HttpClient _httpClient;
11+
private readonly ILogger<WordPressService> _logger;
12+
13+
public WordPressService(HttpClient httpClient, ILogger<WordPressService> logger)
814
{
9-
private readonly HttpClient _httpClient;
10-
public WordPressService(HttpClient httpClient)
11-
{
12-
_httpClient = httpClient;
13-
}
14-
public async Task<WordPressPost?> GetPostAsync(string domain, int id)
15+
_httpClient = httpClient;
16+
_logger = logger;
17+
}
18+
19+
public async Task<WordPressPost?> GetPostAsync(string domain, string? id)
20+
{
21+
if (string.IsNullOrEmpty(id)) return default;
22+
try
1523
{
16-
try
24+
var url = $"{domain}/wp-json/wp/v2/posts/{id}";
25+
if (domain.EndsWith("/"))
1726
{
18-
var url = $"https://{domain}/wp-json/wp/v2/posts/{id}";
19-
var response = await _httpClient.GetStreamAsync(url);
20-
return await JsonSerializer.DeserializeAsync<WordPressPost>(response);
27+
url = $"{domain}wp-json/wp/v2/posts/{id}";
2128
}
22-
catch (Exception)
29+
var response = await _httpClient.GetStreamAsync(url);
30+
return await JsonSerializer.DeserializeAsync<WordPressPost>(response);
31+
}
32+
catch (Exception ex)
33+
{
34+
_logger.LogError("Exception {Message}", ex.Message);
35+
return default;
36+
}
37+
}
38+
39+
public async Task<IEnumerable<WordPressPost>?> ListPostAsync(string domain, IFilterOptions filterOptions)
40+
{
41+
try
42+
{
43+
var url = $"{domain}/wp-json/wp/v2/posts?page={filterOptions.Current}";
44+
if (domain.EndsWith("/"))
2345
{
24-
return default;
46+
url = $"{domain}wp-json/wp/v2/posts?page={filterOptions.Current}";
2547
}
48+
var response = await _httpClient.GetStreamAsync(url);
49+
return await JsonSerializer.DeserializeAsync<List<WordPressPost>>(response);
50+
}
51+
catch (Exception ex)
52+
{
53+
_logger.LogError("Exception {Message}", ex.Message);
54+
return default;
2655
}
2756
}
2857
}

Models/Components/Common/Button.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Waffle.Models.Components;
77

8-
[Display(Name = "Button", ShortName = "BUTTON", GroupName = GroupName.General)]
8+
[Display(Name = "Button", Prompt = "button", GroupName = GroupName.General)]
99
public class Button : AbstractComponent
1010
{
1111
public Button()

Models/Components/Common/Column.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Waffle.Models.Components;
77

8-
[Display(Name = "Column", ShortName = nameof(Column), GroupName = GroupName.Grid)]
8+
[Display(Name = "Column", GroupName = GroupName.Grid, Prompt = "column")]
99
public class Column : AbstractComponent
1010
{
1111
public Column()

0 commit comments

Comments
 (0)