mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-11 07:38:05 +00:00
add the delete api
This commit is contained in:
@ -6,7 +6,7 @@ import 'package:equatable/equatable.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_entry.dart';
|
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_entry.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/water_heater/models/send_schedule.dart';
|
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/water_heater/models/water_heater_status_model.dart';
|
import 'package:syncrow_web/pages/device_managment/water_heater/models/water_heater_status_model.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/format_date_time.dart';
|
import 'package:syncrow_web/utils/format_date_time.dart';
|
||||||
@ -360,7 +360,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
|
|||||||
if (state is WaterHeaterDeviceStatusLoaded) {
|
if (state is WaterHeaterDeviceStatusLoaded) {
|
||||||
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
final currentState = state as WaterHeaterDeviceStatusLoaded;
|
||||||
|
|
||||||
SendSchedule sendSchedule = SendSchedule(
|
ScheduleModel sendSchedule = ScheduleModel(
|
||||||
category: event.category,
|
category: event.category,
|
||||||
time: formatTimeOfDayToISO(event.time),
|
time: formatTimeOfDayToISO(event.time),
|
||||||
function: Status(code: 'switch_1', value: event.functionOn),
|
function: Status(code: 'switch_1', value: event.functionOn),
|
||||||
|
@ -17,26 +17,26 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_sta
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SendSchedule {
|
class ScheduleModel {
|
||||||
final String category;
|
final String category;
|
||||||
final String time;
|
final String time;
|
||||||
final Status function;
|
final Status function;
|
||||||
final List<String> days;
|
final List<String> days;
|
||||||
|
|
||||||
SendSchedule({
|
ScheduleModel({
|
||||||
required this.category,
|
required this.category,
|
||||||
required this.time,
|
required this.time,
|
||||||
required this.function,
|
required this.function,
|
||||||
required this.days,
|
required this.days,
|
||||||
});
|
});
|
||||||
|
|
||||||
SendSchedule copyWith({
|
ScheduleModel copyWith({
|
||||||
String? category,
|
String? category,
|
||||||
String? time,
|
String? time,
|
||||||
Status? function,
|
Status? function,
|
||||||
List<String>? days,
|
List<String>? days,
|
||||||
}) {
|
}) {
|
||||||
return SendSchedule(
|
return ScheduleModel(
|
||||||
category: category ?? this.category,
|
category: category ?? this.category,
|
||||||
time: time ?? this.time,
|
time: time ?? this.time,
|
||||||
function: function ?? this.function,
|
function: function ?? this.function,
|
||||||
@ -53,8 +53,8 @@ class SendSchedule {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
factory SendSchedule.fromMap(Map<String, dynamic> map) {
|
factory ScheduleModel.fromMap(Map<String, dynamic> map) {
|
||||||
return SendSchedule(
|
return ScheduleModel(
|
||||||
category: map['category'] ?? '',
|
category: map['category'] ?? '',
|
||||||
time: map['time'] ?? '',
|
time: map['time'] ?? '',
|
||||||
function: Status.fromMap(map['function']),
|
function: Status.fromMap(map['function']),
|
||||||
@ -64,8 +64,8 @@ class SendSchedule {
|
|||||||
|
|
||||||
String toJson() => json.encode(toMap());
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
factory SendSchedule.fromJson(String source) =>
|
factory ScheduleModel.fromJson(String source) =>
|
||||||
SendSchedule.fromMap(json.decode(source));
|
ScheduleModel.fromMap(json.decode(source));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@ -76,7 +76,7 @@ class SendSchedule {
|
|||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
if (identical(this, other)) return true;
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
return other is SendSchedule &&
|
return other is ScheduleModel &&
|
||||||
other.category == category &&
|
other.category == category &&
|
||||||
other.time == time &&
|
other.time == time &&
|
||||||
other.function == function &&
|
other.function == function &&
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/water_heater/models/send_schedule.dart';
|
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_model.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
@ -177,7 +177,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addScheduleRecord(SendSchedule sendSchedule, String uuid) async {
|
Future<bool> addScheduleRecord(
|
||||||
|
ScheduleModel sendSchedule, String uuid) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
||||||
@ -218,10 +219,12 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteScheduleRecord(String uuid) async {
|
Future<bool> deleteScheduleRecord(String uuid, String scheduleId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().delete(
|
final response = await HTTPService().delete(
|
||||||
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
path: ApiEndpoints.scheduleByDeviceId
|
||||||
|
.replaceAll('{deviceUuid}', uuid)
|
||||||
|
.replaceAll('{scheduleUuid}', scheduleId),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json['success'] ?? false;
|
return json['success'] ?? false;
|
||||||
|
Reference in New Issue
Block a user