first commit
This commit is contained in:
84
lib/app/data/models/aset_model.dart
Normal file
84
lib/app/data/models/aset_model.dart
Normal file
@ -0,0 +1,84 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AsetModel {
|
||||
final String id;
|
||||
final String nama;
|
||||
final String deskripsi;
|
||||
final String kategori;
|
||||
final int harga;
|
||||
final int? denda;
|
||||
final String status;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
final int? kuantitas;
|
||||
final int? kuantitasTerpakai;
|
||||
final String? satuanUkur;
|
||||
|
||||
// Untuk menampung URL gambar pertama dari tabel foto_aset
|
||||
String? imageUrl;
|
||||
|
||||
// Menggunakan RxList untuk membuatnya mutable dan reaktif
|
||||
RxList<Map<String, dynamic>> satuanWaktuSewa = <Map<String, dynamic>>[].obs;
|
||||
|
||||
AsetModel({
|
||||
required this.id,
|
||||
required this.nama,
|
||||
required this.deskripsi,
|
||||
required this.kategori,
|
||||
required this.harga,
|
||||
this.denda,
|
||||
required this.status,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.kuantitas,
|
||||
this.kuantitasTerpakai,
|
||||
this.satuanUkur,
|
||||
this.imageUrl,
|
||||
List<Map<String, dynamic>>? initialSatuanWaktuSewa,
|
||||
}) {
|
||||
// Inisialisasi satuanWaktuSewa jika ada data awal
|
||||
if (initialSatuanWaktuSewa != null) {
|
||||
satuanWaktuSewa.addAll(initialSatuanWaktuSewa);
|
||||
}
|
||||
}
|
||||
|
||||
factory AsetModel.fromJson(Map<String, dynamic> json) {
|
||||
return AsetModel(
|
||||
id: json['id'] ?? '',
|
||||
nama: json['nama'] ?? '',
|
||||
deskripsi: json['deskripsi'] ?? '',
|
||||
kategori: json['kategori'] ?? '',
|
||||
harga: json['harga'] ?? 0,
|
||||
denda: json['denda'],
|
||||
status: json['status'] ?? '',
|
||||
createdAt:
|
||||
json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: null,
|
||||
updatedAt:
|
||||
json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
kuantitas: json['kuantitas'],
|
||||
kuantitasTerpakai: json['kuantitas_terpakai'],
|
||||
satuanUkur: json['satuan_ukur'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'nama': nama,
|
||||
'deskripsi': deskripsi,
|
||||
'kategori': kategori,
|
||||
'harga': harga,
|
||||
'denda': denda,
|
||||
'status': status,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
'kuantitas': kuantitas,
|
||||
'kuantitas_terpakai': kuantitasTerpakai,
|
||||
'satuan_ukur': satuanUkur,
|
||||
};
|
||||
}
|
||||
}
|
41
lib/app/data/models/foto_aset_model.dart
Normal file
41
lib/app/data/models/foto_aset_model.dart
Normal file
@ -0,0 +1,41 @@
|
||||
class FotoAsetModel {
|
||||
final String id;
|
||||
final String fotoAset; // URL foto
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
final String idAset;
|
||||
|
||||
FotoAsetModel({
|
||||
required this.id,
|
||||
required this.fotoAset,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
required this.idAset,
|
||||
});
|
||||
|
||||
factory FotoAsetModel.fromJson(Map<String, dynamic> json) {
|
||||
return FotoAsetModel(
|
||||
id: json['id'] ?? '',
|
||||
fotoAset: json['foto_aset'] ?? '',
|
||||
createdAt:
|
||||
json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: null,
|
||||
updatedAt:
|
||||
json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
idAset: json['id_aset'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'foto_aset': fotoAset,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
'id_aset': idAset,
|
||||
};
|
||||
}
|
||||
}
|
54
lib/app/data/models/paket_model.dart
Normal file
54
lib/app/data/models/paket_model.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class PaketModel {
|
||||
final String? id;
|
||||
final String? nama;
|
||||
final String? deskripsi;
|
||||
final int? harga;
|
||||
final int? kuantitas;
|
||||
final String? foto_paket;
|
||||
final List<dynamic>? satuanWaktuSewa;
|
||||
|
||||
PaketModel({
|
||||
this.id,
|
||||
this.nama,
|
||||
this.deskripsi,
|
||||
this.harga,
|
||||
this.kuantitas,
|
||||
this.foto_paket,
|
||||
this.satuanWaktuSewa,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'nama': nama,
|
||||
'deskripsi': deskripsi,
|
||||
'harga': harga,
|
||||
'kuantitas': kuantitas,
|
||||
'foto_paket': foto_paket,
|
||||
'satuanWaktuSewa': satuanWaktuSewa,
|
||||
};
|
||||
}
|
||||
|
||||
factory PaketModel.fromMap(Map<String, dynamic> map) {
|
||||
return PaketModel(
|
||||
id: map['id'],
|
||||
nama: map['nama'],
|
||||
deskripsi: map['deskripsi'],
|
||||
harga: map['harga']?.toInt(),
|
||||
kuantitas: map['kuantitas']?.toInt(),
|
||||
foto_paket: map['foto_paket'],
|
||||
satuanWaktuSewa: map['satuanWaktuSewa'],
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory PaketModel.fromJson(String source) => PaketModel.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaketModel(id: $id, nama: $nama, deskripsi: $deskripsi, harga: $harga, kuantitas: $kuantitas, foto_paket: $foto_paket, satuanWaktuSewa: $satuanWaktuSewa)';
|
||||
}
|
||||
}
|
79
lib/app/data/models/pesanan_model.dart
Normal file
79
lib/app/data/models/pesanan_model.dart
Normal file
@ -0,0 +1,79 @@
|
||||
class PesananModel {
|
||||
final String id;
|
||||
final String asetId;
|
||||
final String satuanWaktuId;
|
||||
final String userId;
|
||||
final String status;
|
||||
final DateTime tanggalPemesanan;
|
||||
final String jamPemesanan;
|
||||
final int durasi;
|
||||
final int totalHarga;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
// Optional fields for joined data from other tables
|
||||
String? namaSatuanWaktu;
|
||||
String? namaAset;
|
||||
String? namaUser;
|
||||
|
||||
PesananModel({
|
||||
required this.id,
|
||||
required this.asetId,
|
||||
required this.satuanWaktuId,
|
||||
required this.userId,
|
||||
required this.status,
|
||||
required this.tanggalPemesanan,
|
||||
required this.jamPemesanan,
|
||||
required this.durasi,
|
||||
required this.totalHarga,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.namaSatuanWaktu,
|
||||
this.namaAset,
|
||||
this.namaUser,
|
||||
});
|
||||
|
||||
factory PesananModel.fromJson(Map<String, dynamic> json) {
|
||||
return PesananModel(
|
||||
id: json['id'] ?? '',
|
||||
asetId: json['aset_id'] ?? '',
|
||||
satuanWaktuId: json['satuan_waktu_id'] ?? '',
|
||||
userId: json['user_id'] ?? '',
|
||||
status: json['status'] ?? 'pending',
|
||||
tanggalPemesanan:
|
||||
json['tanggal_pemesanan'] != null
|
||||
? DateTime.parse(json['tanggal_pemesanan'])
|
||||
: DateTime.now(),
|
||||
jamPemesanan: json['jam_pemesanan'] ?? '00:00',
|
||||
durasi: json['durasi'] ?? 1,
|
||||
totalHarga: json['total_harga'] ?? 0,
|
||||
createdAt:
|
||||
json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: null,
|
||||
updatedAt:
|
||||
json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
namaSatuanWaktu: json['nama_satuan_waktu'],
|
||||
namaAset: json['nama_aset'],
|
||||
namaUser: json['nama_user'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'aset_id': asetId,
|
||||
'satuan_waktu_id': satuanWaktuId,
|
||||
'user_id': userId,
|
||||
'status': status,
|
||||
'tanggal_pemesanan': tanggalPemesanan.toIso8601String().split('T')[0],
|
||||
'jam_pemesanan': jamPemesanan,
|
||||
'durasi': durasi,
|
||||
'total_harga': totalHarga,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
}
|
1
lib/app/data/models/rental_booking_model.dart
Normal file
1
lib/app/data/models/rental_booking_model.dart
Normal file
@ -0,0 +1 @@
|
||||
|
102
lib/app/data/models/rental_item_model.dart
Normal file
102
lib/app/data/models/rental_item_model.dart
Normal file
@ -0,0 +1,102 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class RentalItem {
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final double pricePerDay;
|
||||
final String? imageUrl;
|
||||
final String ownerId;
|
||||
final String category;
|
||||
final List<String>? features;
|
||||
final bool isAvailable;
|
||||
final String? location;
|
||||
final DateTime createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
RentalItem({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.pricePerDay,
|
||||
this.imageUrl,
|
||||
required this.ownerId,
|
||||
required this.category,
|
||||
this.features,
|
||||
required this.isAvailable,
|
||||
this.location,
|
||||
required this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'price_per_day': pricePerDay,
|
||||
'image_url': imageUrl,
|
||||
'owner_id': ownerId,
|
||||
'category': category,
|
||||
'features': features,
|
||||
'is_available': isAvailable,
|
||||
'location': location,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory RentalItem.fromMap(Map<String, dynamic> map) {
|
||||
return RentalItem(
|
||||
id: map['id'] ?? '',
|
||||
title: map['title'] ?? '',
|
||||
description: map['description'] ?? '',
|
||||
pricePerDay: map['price_per_day']?.toDouble() ?? 0.0,
|
||||
imageUrl: map['image_url'],
|
||||
ownerId: map['owner_id'] ?? '',
|
||||
category: map['category'] ?? '',
|
||||
features:
|
||||
map['features'] != null ? List<String>.from(map['features']) : null,
|
||||
isAvailable: map['is_available'] ?? true,
|
||||
location: map['location'],
|
||||
createdAt: DateTime.parse(map['created_at']),
|
||||
updatedAt:
|
||||
map['updated_at'] != null ? DateTime.parse(map['updated_at']) : null,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory RentalItem.fromJson(String source) =>
|
||||
RentalItem.fromMap(json.decode(source));
|
||||
|
||||
RentalItem copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? description,
|
||||
double? pricePerDay,
|
||||
String? imageUrl,
|
||||
String? ownerId,
|
||||
String? category,
|
||||
List<String>? features,
|
||||
bool? isAvailable,
|
||||
String? location,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return RentalItem(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
pricePerDay: pricePerDay ?? this.pricePerDay,
|
||||
imageUrl: imageUrl ?? this.imageUrl,
|
||||
ownerId: ownerId ?? this.ownerId,
|
||||
category: category ?? this.category,
|
||||
features: features ?? this.features,
|
||||
isAvailable: isAvailable ?? this.isAvailable,
|
||||
location: location ?? this.location,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
37
lib/app/data/models/satuan_waktu_model.dart
Normal file
37
lib/app/data/models/satuan_waktu_model.dart
Normal file
@ -0,0 +1,37 @@
|
||||
class SatuanWaktuModel {
|
||||
final String id;
|
||||
final String namaSatuanWaktu;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
SatuanWaktuModel({
|
||||
required this.id,
|
||||
required this.namaSatuanWaktu,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
factory SatuanWaktuModel.fromJson(Map<String, dynamic> json) {
|
||||
return SatuanWaktuModel(
|
||||
id: json['id'] ?? '',
|
||||
namaSatuanWaktu: json['nama_satuan_waktu'] ?? '',
|
||||
createdAt:
|
||||
json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: null,
|
||||
updatedAt:
|
||||
json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'nama_satuan_waktu': namaSatuanWaktu,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
}
|
53
lib/app/data/models/satuan_waktu_sewa_model.dart
Normal file
53
lib/app/data/models/satuan_waktu_sewa_model.dart
Normal file
@ -0,0 +1,53 @@
|
||||
class SatuanWaktuSewaModel {
|
||||
final String id;
|
||||
final String asetId;
|
||||
final String satuanWaktuId;
|
||||
final int harga;
|
||||
final int? denda;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
// Untuk menyimpan nama satuan waktu (jam/hari) dari tabel satuan_waktu
|
||||
String? namaSatuanWaktu;
|
||||
|
||||
SatuanWaktuSewaModel({
|
||||
required this.id,
|
||||
required this.asetId,
|
||||
required this.satuanWaktuId,
|
||||
required this.harga,
|
||||
this.denda,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.namaSatuanWaktu,
|
||||
});
|
||||
|
||||
factory SatuanWaktuSewaModel.fromJson(Map<String, dynamic> json) {
|
||||
return SatuanWaktuSewaModel(
|
||||
id: json['id'] ?? '',
|
||||
asetId: json['aset_id'] ?? '',
|
||||
satuanWaktuId: json['satuan_waktu_id'] ?? '',
|
||||
harga: json['harga'] ?? 0,
|
||||
denda: json['denda'],
|
||||
createdAt:
|
||||
json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: null,
|
||||
updatedAt:
|
||||
json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'aset_id': asetId,
|
||||
'satuan_waktu_id': satuanWaktuId,
|
||||
'harga': harga,
|
||||
'denda': denda,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
}
|
71
lib/app/data/models/user_model.dart
Normal file
71
lib/app/data/models/user_model.dart
Normal file
@ -0,0 +1,71 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class User {
|
||||
final String id;
|
||||
final String email;
|
||||
final String? name;
|
||||
final String? avatarUrl;
|
||||
final String? phoneNumber;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
User({
|
||||
required this.id,
|
||||
required this.email,
|
||||
this.name,
|
||||
this.avatarUrl,
|
||||
this.phoneNumber,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'email': email,
|
||||
'name': name,
|
||||
'avatar_url': avatarUrl,
|
||||
'phone_number': phoneNumber,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromMap(Map<String, dynamic> map) {
|
||||
return User(
|
||||
id: map['id'] ?? '',
|
||||
email: map['email'] ?? '',
|
||||
name: map['name'],
|
||||
avatarUrl: map['avatar_url'],
|
||||
phoneNumber: map['phone_number'],
|
||||
createdAt:
|
||||
map['created_at'] != null ? DateTime.parse(map['created_at']) : null,
|
||||
updatedAt:
|
||||
map['updated_at'] != null ? DateTime.parse(map['updated_at']) : null,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory User.fromJson(String source) => User.fromMap(json.decode(source));
|
||||
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? email,
|
||||
String? name,
|
||||
String? avatarUrl,
|
||||
String? phoneNumber,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
avatarUrl: avatarUrl ?? this.avatarUrl,
|
||||
phoneNumber: phoneNumber ?? this.phoneNumber,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user