base creada

This commit is contained in:
Abraham
2026-01-10 21:12:17 -08:00
parent 8bfc7d60c3
commit 9adadbd354
62 changed files with 5392 additions and 22447 deletions

View File

@@ -0,0 +1,58 @@
class MediaCategoryModel {
final int mediaCategoriesId;
final DateTime? createdAt;
final String? createdBy;
final String categoryName;
final String? categoryDescription;
final int? mediaFileFk;
MediaCategoryModel({
required this.mediaCategoriesId,
this.createdAt,
this.createdBy,
required this.categoryName,
this.categoryDescription,
this.mediaFileFk,
});
factory MediaCategoryModel.fromMap(Map<String, dynamic> map) {
return MediaCategoryModel(
mediaCategoriesId: map['media_categories_id'] ?? 0,
createdAt:
map['created_at'] != null ? DateTime.parse(map['created_at']) : null,
createdBy: map['created_by'],
categoryName: map['category_name'] ?? '',
categoryDescription: map['category_description'],
mediaFileFk: map['media_file_fk'],
);
}
Map<String, dynamic> toMap() {
return {
'media_categories_id': mediaCategoriesId,
'created_at': createdAt?.toIso8601String(),
'created_by': createdBy,
'category_name': categoryName,
'category_description': categoryDescription,
'media_file_fk': mediaFileFk,
};
}
MediaCategoryModel copyWith({
int? mediaCategoriesId,
DateTime? createdAt,
String? createdBy,
String? categoryName,
String? categoryDescription,
int? mediaFileFk,
}) {
return MediaCategoryModel(
mediaCategoriesId: mediaCategoriesId ?? this.mediaCategoriesId,
createdAt: createdAt ?? this.createdAt,
createdBy: createdBy ?? this.createdBy,
categoryName: categoryName ?? this.categoryName,
categoryDescription: categoryDescription ?? this.categoryDescription,
mediaFileFk: mediaFileFk ?? this.mediaFileFk,
);
}
}

View File

@@ -0,0 +1,156 @@
import 'dart:convert';
class MediaFileModel {
final int mediaFileId;
final String fileName;
final String? title;
final String? fileDescription;
final String? fileType;
final String? mimeType;
final String? fileExtension;
final int? fileSizeBytes;
final String? fileUrl;
final String? storagePath;
final DateTime? createdAt;
final DateTime? updatedAt;
final String? uploadedByUserId;
final bool? isPublicFile;
final Map<String, dynamic>? metadataJson;
final int? seconds;
final int? mediaCategoryFk;
final int organizationFk;
MediaFileModel({
required this.mediaFileId,
required this.fileName,
this.title,
this.fileDescription,
this.fileType,
this.mimeType,
this.fileExtension,
this.fileSizeBytes,
this.fileUrl,
this.storagePath,
this.createdAt,
this.updatedAt,
this.uploadedByUserId,
this.isPublicFile,
this.metadataJson,
this.seconds,
this.mediaCategoryFk,
required this.organizationFk,
});
factory MediaFileModel.fromMap(Map<String, dynamic> map) {
return MediaFileModel(
mediaFileId: map['media_file_id'] ?? 0,
fileName: map['file_name'] ?? '',
title: map['title'],
fileDescription: map['file_description'],
fileType: map['file_type'],
mimeType: map['mime_type'],
fileExtension: map['file_extension'],
fileSizeBytes: map['file_size_bytes'],
fileUrl: map['file_url'],
storagePath: map['storage_path'],
createdAt: map['created_at_timestamp'] != null
? DateTime.parse(map['created_at_timestamp'])
: null,
updatedAt: map['updated_at_timestamp'] != null
? DateTime.parse(map['updated_at_timestamp'])
: null,
uploadedByUserId: map['uploaded_by_user_id'],
isPublicFile: map['is_public_file'],
metadataJson: map['metadata_json'] != null
? (map['metadata_json'] is String
? jsonDecode(map['metadata_json'])
: map['metadata_json'])
: null,
seconds: map['seconds'],
mediaCategoryFk: map['media_category_fk'],
organizationFk: map['organization_fk'] ?? 17,
);
}
Map<String, dynamic> toMap() {
return {
'media_file_id': mediaFileId,
'file_name': fileName,
'title': title,
'file_description': fileDescription,
'file_type': fileType,
'mime_type': mimeType,
'file_extension': fileExtension,
'file_size_bytes': fileSizeBytes,
'file_url': fileUrl,
'storage_path': storagePath,
'created_at_timestamp': createdAt?.toIso8601String(),
'updated_at_timestamp': updatedAt?.toIso8601String(),
'uploaded_by_user_id': uploadedByUserId,
'is_public_file': isPublicFile,
'metadata_json': metadataJson,
'seconds': seconds,
'media_category_fk': mediaCategoryFk,
'organization_fk': organizationFk,
};
}
MediaFileModel copyWith({
int? mediaFileId,
String? fileName,
String? title,
String? fileDescription,
String? fileType,
String? mimeType,
String? fileExtension,
int? fileSizeBytes,
String? fileUrl,
String? storagePath,
DateTime? createdAt,
DateTime? updatedAt,
String? uploadedByUserId,
bool? isPublicFile,
Map<String, dynamic>? metadataJson,
int? seconds,
int? mediaCategoryFk,
int? organizationFk,
}) {
return MediaFileModel(
mediaFileId: mediaFileId ?? this.mediaFileId,
fileName: fileName ?? this.fileName,
title: title ?? this.title,
fileDescription: fileDescription ?? this.fileDescription,
fileType: fileType ?? this.fileType,
mimeType: mimeType ?? this.mimeType,
fileExtension: fileExtension ?? this.fileExtension,
fileSizeBytes: fileSizeBytes ?? this.fileSizeBytes,
fileUrl: fileUrl ?? this.fileUrl,
storagePath: storagePath ?? this.storagePath,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
uploadedByUserId: uploadedByUserId ?? this.uploadedByUserId,
isPublicFile: isPublicFile ?? this.isPublicFile,
metadataJson: metadataJson ?? this.metadataJson,
seconds: seconds ?? this.seconds,
mediaCategoryFk: mediaCategoryFk ?? this.mediaCategoryFk,
organizationFk: organizationFk ?? this.organizationFk,
);
}
// Helper getters for metadata_json
int get reproducciones => metadataJson?['reproducciones'] ?? 0;
DateTime? get uploadedAt => metadataJson?['uploaded_at'] != null
? DateTime.tryParse(metadataJson!['uploaded_at'])
: null;
List<String> get categorias =>
(metadataJson?['categorias'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
[];
String? get originalFileName => metadataJson?['original_file_name'];
int? get durationSeconds => metadataJson?['duration_seconds'];
String? get resolution => metadataJson?['resolution'];
DateTime? get lastViewedAt => metadataJson?['last_viewed_at'] != null
? DateTime.tryParse(metadataJson!['last_viewed_at'])
: null;
}

View File

@@ -0,0 +1,5 @@
// Media models
export 'media_file_model.dart';
export 'media_category_model.dart';
export 'media_poster_model.dart';
export 'media_with_poster_model.dart';

View File

@@ -0,0 +1,47 @@
class MediaPosterModel {
final int mediaPosterId;
final int mediaFileId;
final int posterFileId;
final DateTime? createdAt;
MediaPosterModel({
required this.mediaPosterId,
required this.mediaFileId,
required this.posterFileId,
this.createdAt,
});
factory MediaPosterModel.fromMap(Map<String, dynamic> map) {
return MediaPosterModel(
mediaPosterId: map['media_poster_id'] ?? 0,
mediaFileId: map['media_file_id'] ?? 0,
posterFileId: map['poster_file_id'] ?? 0,
createdAt: map['created_at_timestamp'] != null
? DateTime.parse(map['created_at_timestamp'])
: null,
);
}
Map<String, dynamic> toMap() {
return {
'media_poster_id': mediaPosterId,
'media_file_id': mediaFileId,
'poster_file_id': posterFileId,
'created_at_timestamp': createdAt?.toIso8601String(),
};
}
MediaPosterModel copyWith({
int? mediaPosterId,
int? mediaFileId,
int? posterFileId,
DateTime? createdAt,
}) {
return MediaPosterModel(
mediaPosterId: mediaPosterId ?? this.mediaPosterId,
mediaFileId: mediaFileId ?? this.mediaFileId,
posterFileId: posterFileId ?? this.posterFileId,
createdAt: createdAt ?? this.createdAt,
);
}
}

View File

@@ -0,0 +1,113 @@
/// Model for vw_media_files_with_posters view
class MediaWithPosterModel {
final int mediaFileId;
final String? mediaFileName;
final String? mediaTitle;
final String? fileDescription;
final String? mediaType;
final String? mediaMimeType;
final String? mediaUrl;
final String? mediaStoragePath;
final DateTime? mediaCreatedAt;
final int? categoryId;
final String? categoryName;
final String? categoryDescription;
final DateTime? categoryCreatedAt;
final String? categoryImageUrl;
final String? categoryImageStoragePath;
final int? mediaPosterId;
final int? posterFileId;
final String? posterFileName;
final String? posterTitle;
final String? posterUrl;
final String? posterStoragePath;
final DateTime? posterCreatedAt;
MediaWithPosterModel({
required this.mediaFileId,
this.mediaFileName,
this.mediaTitle,
this.fileDescription,
this.mediaType,
this.mediaMimeType,
this.mediaUrl,
this.mediaStoragePath,
this.mediaCreatedAt,
this.categoryId,
this.categoryName,
this.categoryDescription,
this.categoryCreatedAt,
this.categoryImageUrl,
this.categoryImageStoragePath,
this.mediaPosterId,
this.posterFileId,
this.posterFileName,
this.posterTitle,
this.posterUrl,
this.posterStoragePath,
this.posterCreatedAt,
});
factory MediaWithPosterModel.fromMap(Map<String, dynamic> map) {
return MediaWithPosterModel(
mediaFileId: map['media_file_id'] ?? 0,
mediaFileName: map['media_file_name'],
mediaTitle: map['media_title'],
fileDescription: map['file_description'],
mediaType: map['media_type'],
mediaMimeType: map['media_mime_type'],
mediaUrl: map['media_url'],
mediaStoragePath: map['media_storage_path'],
mediaCreatedAt: map['media_created_at'] != null
? DateTime.parse(map['media_created_at'])
: null,
categoryId: map['category_id'],
categoryName: map['category_name'],
categoryDescription: map['category_description'],
categoryCreatedAt: map['category_created_at'] != null
? DateTime.parse(map['category_created_at'])
: null,
categoryImageUrl: map['category_image_url'],
categoryImageStoragePath: map['category_image_storage_path'],
mediaPosterId: map['media_poster_id'],
posterFileId: map['poster_file_id'],
posterFileName: map['poster_file_name'],
posterTitle: map['poster_title'],
posterUrl: map['poster_url'],
posterStoragePath: map['poster_storage_path'],
posterCreatedAt: map['poster_created_at'] != null
? DateTime.parse(map['poster_created_at'])
: null,
);
}
Map<String, dynamic> toMap() {
return {
'media_file_id': mediaFileId,
'media_file_name': mediaFileName,
'media_title': mediaTitle,
'file_description': fileDescription,
'media_type': mediaType,
'media_mime_type': mediaMimeType,
'media_url': mediaUrl,
'media_storage_path': mediaStoragePath,
'media_created_at': mediaCreatedAt?.toIso8601String(),
'category_id': categoryId,
'category_name': categoryName,
'category_description': categoryDescription,
'category_created_at': categoryCreatedAt?.toIso8601String(),
'category_image_url': categoryImageUrl,
'category_image_storage_path': categoryImageStoragePath,
'media_poster_id': mediaPosterId,
'poster_file_id': posterFileId,
'poster_file_name': posterFileName,
'poster_title': posterTitle,
'poster_url': posterUrl,
'poster_storage_path': posterStoragePath,
'poster_created_at': posterCreatedAt?.toIso8601String(),
};
}
/// Helper getter to get poster or fallback to category image
String? get displayImageUrl => posterUrl ?? categoryImageUrl;
}