Skip to content

Commit e73968b

Browse files
committed
fix create resoure learning
1 parent a488030 commit e73968b

File tree

12 files changed

+255
-351
lines changed

12 files changed

+255
-351
lines changed

src/app/core/models/post.models.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,12 @@ export type PostResponse = {
155155
upvoteCount: number;
156156
downvoteCount: number;
157157
};
158+
159+
//post-create
160+
export interface PostDataCreateRequest {
161+
file: File;
162+
description: string;
163+
tags: string[];
164+
isLectureVideo: boolean;
165+
isTextbook: boolean;
166+
}

src/app/core/services/api-service/resource.service.ts

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../../models/api-response';
99
import { MediaResource, ResourceData, Tag } from '../../models/resource.model';
1010
import { API_CONFIG } from '../config-service/api.enpoints';
11+
import { PostDataCreateRequest } from '../../models/post.models';
1112

1213
@Injectable({
1314
providedIn: 'root',
@@ -52,51 +53,25 @@ export class ResourceService {
5253
API_CONFIG.ENDPOINTS.GET.GET_FILE_BY_ID(id)
5354
);
5455
}
55-
addResource(postData: {
56-
file: File;
57-
category: number;
58-
description: string;
59-
tags: string[];
60-
isLectureVideo: boolean;
61-
isTextbook: boolean;
62-
orgId?: string;
63-
associatedResourceIds?: string[];
64-
thumbnailUrl?: string;
65-
}) {
66-
const formData = new FormData();
67-
68-
if (postData.file) {
69-
formData.append('file', postData.file);
70-
}
71-
72-
if (postData.category !== null) {
73-
formData.append('category', postData.category.toString());
74-
}
75-
76-
formData.append('description', postData.description || '');
77-
formData.append('isLectureVideo', String(postData.isLectureVideo));
78-
formData.append('isTextbook', String(postData.isTextbook));
7956

80-
if (postData.orgId) {
81-
formData.append('orgId', postData.orgId);
82-
}
83-
84-
if (postData.thumbnailUrl) {
85-
formData.append('thumbnailUrl', postData.thumbnailUrl);
86-
}
57+
addResource(postData: PostDataCreateRequest) {
58+
const { file, description, tags, isLectureVideo, isTextbook } = postData;
8759

88-
// Tags array
89-
postData.tags?.forEach((tag, i) => formData.append(`tags[${i}]`, tag));
60+
// data: phần dữ liệu thông thường (không phải file)
61+
const data: Record<string, any> = {
62+
description,
63+
tags: JSON.stringify(tags), // stringify array để backend parse
64+
isLectureVideo: String(isLectureVideo),
65+
isTextbook: String(isTextbook),
66+
};
9067

91-
// Associated resources array
92-
postData.associatedResourceIds?.forEach((id, i) =>
93-
formData.append(`associatedResourceIds[${i}]`, id)
94-
);
68+
// files: phần file
69+
const files: File = file;
9570

96-
return this.api.post<ApiResponse<XuanPresignedUrlResponse>>(
71+
return this.api.postWithFormData<ApiResponse<XuanPresignedUrlResponse>>(
9772
API_CONFIG.ENDPOINTS.POST.ADD_FILE,
98-
formData,
99-
true
73+
data,
74+
files
10075
);
10176
}
10277

src/app/features/resource-learning/pages/resource-create/resource-create.html

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
11
<div class="post-create-container">
22
<div class="general-infor">
3-
<div class="input-info">
4-
<app-dropdown-button
5-
[label]="'Loại tệp'"
6-
[options]="category"
7-
[variant]="'secondary'"
8-
[size]="'small'"
9-
[customDropField]="'main-type'"
10-
[disabled]="false"
11-
[multiSelect]="false"
12-
[isDisplayCheckbox]="false"
13-
(onSelect)="handleSelect('category', $event)"
14-
[isOpen]="activeDropdown === 'category'"
15-
(toggle)="toggleDropdown('category')"
16-
[isDisplaySelectedOpptionLabels]="true"
17-
[isButtonControl]="true"
18-
[isSearchable]="true"
19-
[minHeight]="true"
20-
[needIndexColor]="true"
21-
></app-dropdown-button>
22-
</div>
23-
<div class="input-title">
24-
<app-input
25-
label="Link thumbnail"
26-
placeholder="Nhập link thumbnail..."
27-
[value]="thumbnail"
28-
(valueChange)="handleInputChange($event)"
29-
[minLength]="3"
30-
[variant]="'primary'"
31-
[errorMessage]="thumbnailError"
32-
[isSvg]="false"
33-
></app-input>
34-
</div>
353
<div class="input-title">
364
<!-- Thay bằng input -->
375
<app-input
@@ -54,8 +22,6 @@
5422
[(value)]="editorContent"
5523
[config]="editorConfig"
5624
(onChange)="onContentChange($event)"
57-
(onFocus)="onEditorFocus()"
58-
(onBlur)="onEditorBlur()"
5925
></app-text-editor>
6026
</div>
6127
<div class="post-create-button">
@@ -83,54 +49,6 @@
8349
</div>
8450
</div>
8551
<div class="metric">
86-
<div class="link-section">
87-
<div class="link-header" (click)="startAddLink()">
88-
<span>Thêm link</span>
89-
<button type="button" class="add-link-btn">
90-
<span>+</span>
91-
</button>
92-
</div>
93-
94-
<!-- Ô nhập link khi bấm + -->
95-
<div class="link-input" *ngIf="isAddingLink">
96-
<input
97-
#linkInput
98-
type="text"
99-
[(ngModel)]="newLink"
100-
placeholder="Nhập link..."
101-
(keyup.enter)="addLink()"
102-
/>
103-
<button type="button" (click)="addLink()">OK</button>
104-
</div>
105-
<!-- Danh sách nhiều link -->
106-
<div class="link-list" *ngIf="associatedResourceIds.length > 0">
107-
<div
108-
class="single-link"
109-
*ngFor="let link of associatedResourceIds; let i = index"
110-
>
111-
<svg
112-
xmlns="http://www.w3.org/2000/svg"
113-
width="18"
114-
height="18"
115-
viewBox="0 0 24 24"
116-
fill="none"
117-
stroke="currentColor"
118-
stroke-width="2"
119-
stroke-linecap="round"
120-
stroke-linejoin="round"
121-
class="lucide lucide-link-2"
122-
>
123-
<path d="M9 17H7A5 5 0 0 1 7 7h2" />
124-
<path d="M15 7h2a5 5 0 1 1 0 10h-2" />
125-
<line x1="8" x2="16" y1="12" y2="12" />
126-
</svg>
127-
<a [href]="link" target="_blank">{{ link }}</a>
128-
<button type="button" class="remove-link" (click)="removeLink(i)">
129-
×
130-
</button>
131-
</div>
132-
</div>
133-
</div>
13452
<div class="file-upload">
13553
<label class="upload-label">
13654
<input

0 commit comments

Comments
 (0)