From b3d891b2c808a13d33d6076ec22625019e3a1b9c Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 22 Sep 2024 14:51:15 +0300 Subject: [PATCH] add the delete api --- .../water_heater/bloc/water_heater_bloc.dart | 4 ++-- ...{send_schedule.dart => schedule_model.dart} | 18 +++++++++--------- lib/services/devices_mang_api.dart | 11 +++++++---- 3 files changed, 18 insertions(+), 15 deletions(-) rename lib/pages/device_managment/water_heater/models/{send_schedule.dart => schedule_model.dart} (84%) diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart index 07f73569..a96213db 100644 --- a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart +++ b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart @@ -6,7 +6,7 @@ import 'package:equatable/equatable.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/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/services/devices_mang_api.dart'; import 'package:syncrow_web/utils/format_date_time.dart'; @@ -360,7 +360,7 @@ class WaterHeaterBloc extends Bloc { if (state is WaterHeaterDeviceStatusLoaded) { final currentState = state as WaterHeaterDeviceStatusLoaded; - SendSchedule sendSchedule = SendSchedule( + ScheduleModel sendSchedule = ScheduleModel( category: event.category, time: formatTimeOfDayToISO(event.time), function: Status(code: 'switch_1', value: event.functionOn), diff --git a/lib/pages/device_managment/water_heater/models/send_schedule.dart b/lib/pages/device_managment/water_heater/models/schedule_model.dart similarity index 84% rename from lib/pages/device_managment/water_heater/models/send_schedule.dart rename to lib/pages/device_managment/water_heater/models/schedule_model.dart index 650f3a04..57386136 100644 --- a/lib/pages/device_managment/water_heater/models/send_schedule.dart +++ b/lib/pages/device_managment/water_heater/models/schedule_model.dart @@ -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 time; final Status function; final List days; - SendSchedule({ + ScheduleModel({ required this.category, required this.time, required this.function, required this.days, }); - SendSchedule copyWith({ + ScheduleModel copyWith({ String? category, String? time, Status? function, List? days, }) { - return SendSchedule( + return ScheduleModel( category: category ?? this.category, time: time ?? this.time, function: function ?? this.function, @@ -53,8 +53,8 @@ class SendSchedule { }; } - factory SendSchedule.fromMap(Map map) { - return SendSchedule( + factory ScheduleModel.fromMap(Map map) { + return ScheduleModel( category: map['category'] ?? '', time: map['time'] ?? '', function: Status.fromMap(map['function']), @@ -64,8 +64,8 @@ class SendSchedule { String toJson() => json.encode(toMap()); - factory SendSchedule.fromJson(String source) => - SendSchedule.fromMap(json.decode(source)); + factory ScheduleModel.fromJson(String source) => + ScheduleModel.fromMap(json.decode(source)); @override String toString() { @@ -76,7 +76,7 @@ class SendSchedule { bool operator ==(Object other) { if (identical(this, other)) return true; - return other is SendSchedule && + return other is ScheduleModel && other.category == category && other.time == time && other.function == function && diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index 4445d5c1..049538d3 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -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_status.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/services/api/http_service.dart'; import 'package:syncrow_web/utils/constants/api_const.dart'; @@ -177,7 +177,8 @@ class DevicesManagementApi { } } - Future addScheduleRecord(SendSchedule sendSchedule, String uuid) async { + Future addScheduleRecord( + ScheduleModel sendSchedule, String uuid) async { try { final response = await HTTPService().post( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), @@ -218,10 +219,12 @@ class DevicesManagementApi { } } - Future deleteScheduleRecord(String uuid) async { + Future deleteScheduleRecord(String uuid, String scheduleId) async { try { final response = await HTTPService().delete( - path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), + path: ApiEndpoints.scheduleByDeviceId + .replaceAll('{deviceUuid}', uuid) + .replaceAll('{scheduleUuid}', scheduleId), showServerMessage: true, expectedResponseModel: (json) { return json['success'] ?? false;