Selaa lähdekoodia

CORS configuration

ducnt 1 kuukausi sitten
vanhempi
commit
35c7c62eb1

+ 1 - 1
EsimLao/Common/Http/ContentRequest.cs

@@ -28,7 +28,7 @@ namespace Common.Http
         public string customerName { get; set; } = null!;
         public string reviewContent { get; set; } = null!;
         public string? destination { get; set; }
-        public int? rating { get; set; }
+        public int rating { get; set; }
     }
 
     // =============== FAQ ===============

+ 1 - 1
EsimLao/Database/Database/CustomerReview.cs

@@ -11,7 +11,7 @@ public partial class CustomerReview
 
     public string? AvatarUrl { get; set; }
 
-    public int? Rating { get; set; }
+    public int Rating { get; set; }
 
     public string ReviewContent { get; set; } = null!;
 

+ 1 - 1
EsimLao/Esim.Apis/Business/Content/ContentBusinessImpl.cs

@@ -180,7 +180,7 @@ namespace Esim.Apis.Business
                     CustomerName = request.customerName,
                     ReviewContent = request.reviewContent,
                     Destination = request.destination,
-                    Rating = request.rating > 0,
+                    Rating = request.rating > 0 ? request.rating : 1,
                     Status = false, // Pending approval
                     IsFeatured = false,
                     CreatedDate = DateTime.Now

+ 21 - 0
EsimLao/Esim.Apis/Program.cs

@@ -24,6 +24,24 @@ builder.Services.AddScoped<IUserBusiness, UserBusinessImpl>();
 builder.Services.AddScoped<IArticleBusiness, ArticleBusinessImpl>();
 builder.Services.AddScoped<IContentBusiness, ContentBusinessImpl>();
 
+// Configure CORS - Allow frontend to access APIs
+builder.Services.AddCors(options =>
+{
+    options.AddPolicy("AllowFrontend", policy =>
+    {
+        policy.WithOrigins(
+                "http://localhost:3000",      // React development
+                "http://localhost:5173",      // Vite development
+                "http://localhost:4200",      // Angular development
+                "https://infigate.vn",        // Production domain
+                "https://www.infigate.vn"     // Production www domain
+            )
+            .AllowAnyMethod()
+            .AllowAnyHeader()
+            .AllowCredentials();
+    });
+});
+
 // Configure JWT Authentication
 var jwtKey = builder.Configuration["Jwt:Key"] ?? "EsimLaoSecretKey12345678901234567890";
 var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? "EsimLao";
@@ -90,6 +108,9 @@ app.UseSwaggerUI();
 app.UseHttpsRedirection();
 app.UseRouting();
 
+// Enable CORS - MUST be after UseRouting and before UseAuthentication
+app.UseCors("AllowFrontend");
+
 app.UseAuthentication();
 app.UseAuthorization();
 

+ 96 - 0
EsimLao/docs/api_auth_otp.txt

@@ -356,6 +356,25 @@ POST /apis/article/category
 }
 ```
 
+### Response Fields - categories[]
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | ARTICLE_CATEGORY.ID | ID danh mục bài viết (Primary Key) |
+| categoryName | string | ARTICLE_CATEGORY.CATEGORY_NAME<br/>CATEGORY_NAME_EN<br/>CATEGORY_NAME_LO | Tên danh mục (theo ngôn ngữ được chọn) |
+| categorySlug | string | ARTICLE_CATEGORY.CATEGORY_SLUG | URL-friendly slug cho danh mục |
+| description | string | ARTICLE_CATEGORY.DESCRIPTION<br/>DESCRIPTION_EN<br/>DESCRIPTION_LO | Mô tả chi tiết danh mục |
+| iconUrl | string | ARTICLE_CATEGORY.ICON_URL | Đường dẫn icon của danh mục |
+| parentId | int? | ARTICLE_CATEGORY.PARENT_ID | ID danh mục cha (null = danh mục gốc) |
+| displayOrder | int | ARTICLE_CATEGORY.DISPLAY_ORDER | Thứ tự hiển thị (số nhỏ hơn hiển thị trước) |
+
+### Response Fields - pagination
+| Field | Type | Description |
+|-------|------|-------------|
+| pageNumber | int | Trang hiện tại (bắt đầu từ 0) |
+| pageSize | int | Số items trên mỗi trang |
+| totalCount | int | Tổng số items trong database |
+| totalPages | int | Tổng số trang (= ceiling(totalCount / pageSize)) |
+
 ---
 
 ## 4. Article Load
@@ -446,6 +465,30 @@ POST /apis/article/load
 }
 ```
 
+### Response Fields - articles[] (List)
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | ARTICLE.ID | ID bài viết (Primary Key) |
+| title | string | ARTICLE.TITLE<br/>TITLE_EN<br/>TITLE_LO | Tiêu đề bài viết (theo ngôn ngữ) |
+| slug | string | ARTICLE.SLUG | URL-friendly slug (unique) |
+| summary | string | ARTICLE.SUMMARY<br/>SUMMARY_EN<br/>SUMMARY_LO | Tóm tắt ngắn gọn |
+| thumbnailUrl | string | ARTICLE.THUMBNAIL_URL | Ảnh thumbnail (dùng cho list) |
+| categoryId | int | ARTICLE.CATEGORY_ID | ID danh mục (FK → ARTICLE_CATEGORY) |
+| viewCount | int | ARTICLE.VIEW_COUNT | Số lượt xem |
+| isFeatured | bool | ARTICLE.IS_FEATURED | Bài viết nổi bật (true/false) |
+| isPinned | bool | ARTICLE.IS_PINNED | Bài viết được ghim (true/false) |
+| publishedDate | datetime | ARTICLE.PUBLISHED_DATE | Ngày xuất bản |
+
+### Response Fields - article (Detail)
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| *Tất cả fields từ List + thêm:* | | | |
+| content | string | ARTICLE.CONTENT<br/>CONTENT_EN<br/>CONTENT_LO | Nội dung HTML đầy đủ |
+| coverImageUrl | string | ARTICLE.COVER_IMAGE_URL | Ảnh bìa (dùng cho detail page) |
+| metaDescription | string | ARTICLE.META_DESCRIPTION<br/>META_DESCRIPTION_EN<br/>META_DESCRIPTION_LO | SEO meta description |
+| metaKeywords | string | ARTICLE.META_KEYWORDS | SEO keywords (comma-separated) |
+| createdDate | datetime | ARTICLE.CREATED_DATE | Ngày tạo bài viết |
+
 ---
 
 ## 5. Banner Load
@@ -497,6 +540,21 @@ POST /apis/content/banner
 }
 ```
 
+### Response Fields - banners[]
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | BANNER.ID | ID banner (Primary Key) |
+| title | string | BANNER.TITLE<br/>TITLE_EN<br/>TITLE_LO | Tiêu đề banner (theo ngôn ngữ) |
+| subtitle | string | BANNER.SUBTITLE<br/>SUBTITLE_EN<br/>SUBTITLE_LO | Phụ đề banner |
+| imageUrl | string | BANNER.IMAGE_URL | Ảnh banner (desktop) |
+| imageMobileUrl | string | BANNER.IMAGE_MOBILE_URL | Ảnh banner (mobile) |
+| linkUrl | string | BANNER.LINK_URL | URL đích khi click banner |
+| linkTarget | string | BANNER.LINK_TARGET | Target (_self, _blank,...) |
+| position | string | BANNER.POSITION | Vị trí hiển thị (home, category,...) |
+| displayOrder | int | BANNER.DISPLAY_ORDER | Thứ tự hiển thị |
+
+**Lọc tự động**: Chỉ trả về banners với `STATUS = 1` và trong khoảng `START_DATE ≤ now ≤ END_DATE`
+
 ---
 
 ## 6. Customer Review Load
@@ -547,6 +605,20 @@ POST /apis/content/review
 }
 ```
 
+### Response Fields - reviews[]
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | CUSTOMER_REVIEW.ID | ID đánh giá (Primary Key) |
+| customerName | string | CUSTOMER_REVIEW.CUSTOMER_NAME | Tên khách hàng |
+| avatarUrl | string | CUSTOMER_REVIEW.AVATAR_URL | Ảnh đại diện (nullable) |
+| rating | int | CUSTOMER_REVIEW.RATING | Số sao (1-5) |
+| reviewContent | string | CUSTOMER_REVIEW.REVIEW_CONTENT<br/>REVIEW_CONTENT_EN<br/>REVIEW_CONTENT_LO | Nội dung đánh giá (theo ngôn ngữ) |
+| destination | string | CUSTOMER_REVIEW.DESTINATION<br/>DESTINATION_EN<br/>DESTINATION_LO | Địa điểm du lịch |
+| isFeatured | bool | CUSTOMER_REVIEW.IS_FEATURED | Review nổi bật |
+| createdDate | datetime | CUSTOMER_REVIEW.CREATED_DATE | Ngày tạo review |
+
+**Lọc tự động**: Chỉ trả về reviews với `STATUS = 1` (đã duyệt)
+
 ---
 
 ## 6.1 Customer Review Create
@@ -631,6 +703,16 @@ POST /apis/content/faq-category
 }
 ```
 
+### Response Fields - categories[]
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | FAQ_CATEGORY.ID | ID danh mục FAQ (Primary Key) |
+| categoryName | string | FAQ_CATEGORY.CATEGORY_NAME<br/>CATEGORY_NAME_EN<br/>CATEGORY_NAME_LO | Tên danh mục FAQ |
+| categorySlug | string | FAQ_CATEGORY.CATEGORY_SLUG | URL-friendly slug |
+| description | string | FAQ_CATEGORY.DESCRIPTION<br/>DESCRIPTION_EN<br/>DESCRIPTION_LO | Mô tả danh mục |
+| iconUrl | string | FAQ_CATEGORY.ICON_URL | Icon của danh mục |
+| displayOrder | int | FAQ_CATEGORY.DISPLAY_ORDER | Thứ tự hiển thị |
+
 ---
 
 ## 8. FAQ Load
@@ -680,3 +762,17 @@ POST /apis/content/faq
     }
 }
 ```
+
+### Response Fields - faqs[]
+| Field | Type | DB Column | Description |
+|-------|------|-----------|-------------|
+| id | int | FAQ.ID | ID câu hỏi (Primary Key) |
+| question | string | FAQ.QUESTION<br/>QUESTION_EN<br/>QUESTION_LO | Câu hỏi (theo ngôn ngữ) |
+| answer | string | FAQ.ANSWER<br/>ANSWER_EN<br/>ANSWER_LO | Câu trả lời (HTML format) |
+| categoryId | int | FAQ.CATEGORY_ID | ID danh mục (FK → FAQ_CATEGORY) |
+| viewCount | int | FAQ.VIEW_COUNT | Số lượt xem |
+| isFeatured | bool | FAQ.IS_FEATURED | FAQ nổi bật |
+
+**Lọc tự động**: Chỉ trả về FAQs với `STATUS = 1`
+
+---