Skip to content

Commit

Permalink
⏰ Refactors ntp service
Browse files Browse the repository at this point in the history
  • Loading branch information
runeharlyk committed Nov 7, 2024
1 parent 10b0aa3 commit 3a3de53
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 272 deletions.
6 changes: 3 additions & 3 deletions app/src/routes/connections/ntp/NTP.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let ntpStatus: NTPStatus;
async function getNTPStatus() {
const result = await api.get<NTPStatus>('/api/ntpStatus');
const result = await api.get<NTPStatus>('/api/ntp/status');
if (result.isErr()) {
console.error('Error:', result.inner);
return;
Expand All @@ -27,7 +27,7 @@
}
async function getNTPSettings() {
const result = await api.get<NTPSettings>('/api/ntpSettings');
const result = await api.get<NTPSettings>('/api/ntp/settings');
if (result.isErr()) {
console.error('Error:', result.inner);
return;
Expand All @@ -48,7 +48,7 @@
};
async function postNTPSettings(data: NTPSettings) {
const result = await api.post<NTPSettings>('/api/ntpSettings', data);
const result = await api.post<NTPSettings>('/api/ntp/settings', data);
if (result.isErr()) {
notifications.error('User not authorized.', 3000);
console.error('Error:', result.inner);
Expand Down
19 changes: 13 additions & 6 deletions esp32/lib/ESP32-sveltekit/ESP32SvelteKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEnd
_taskManager(),
_featureService(server),
_socket(server),
#if FT_ENABLED(USE_NTP)
_ntpSettingsService(server, &ESPFS),
_ntpStatus(server),
#endif
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
_uploadFirmwareService(server),
#endif
Expand Down Expand Up @@ -97,6 +93,18 @@ void ESP32SvelteKit::setupServer() {
return _apService.endpoint.handleStateUpdate(request, json);
});

// NTP
#if FT_ENABLED(USE_NTP)
_server->on("/api/ntp/status", HTTP_GET, [this](PsychicRequest *r) { return _ntpService.getStatus(r); });
_server->on("/api/ntp/time", HTTP_POST,
[this](PsychicRequest *r, JsonVariant &json) { return _ntpService.handleTime(r, json); });
_server->on("/api/ntp/settings", HTTP_GET,
[this](PsychicRequest *request) { return _ntpService.endpoint.getState(request); });
_server->on("/api/ntp/settings", HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
return _ntpService.endpoint.handleStateUpdate(request, json);
});
#endif

// SYSTEM
_server->on("/api/system/reset", HTTP_POST, system_service::handleReset);
_server->on("/api/system/restart", HTTP_POST, system_service::handleRestart);
Expand Down Expand Up @@ -182,8 +190,7 @@ void ESP32SvelteKit::startServices() {
_downloadFirmwareService.begin();
#endif
#if FT_ENABLED(USE_NTP)
_ntpSettingsService.begin();
_ntpStatus.begin();
_ntpService.begin();
#endif
#if FT_ENABLED(USE_ANALYTICS)
_analyticsService.begin();
Expand Down
10 changes: 2 additions & 8 deletions esp32/lib/ESP32-sveltekit/ESP32SvelteKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
#include <EventSocket.h>
#include <FeaturesService.h>
#include <MotionService.h>
#include <NTPSettingsService.h>
#include <ntp_service.h>
#include <CameraService.h>
#include <CameraSettingsService.h>
#include <NTPStatus.h>
#include <PsychicHttp.h>
#include <TaskManager.h>
#include <UploadFirmwareService.h>
Expand Down Expand Up @@ -74,10 +73,6 @@ class ESP32SvelteKit {

EventSocket *getSocket() { return &_socket; }

#if FT_ENABLED(USE_NTP)
StatefulService<NTPSettings> *getNTPSettingsService() { return &_ntpSettingsService; }
#endif

#if FT_ENABLED(USE_BATTERY)
BatteryService *getBatteryService() { return &_batteryService; }
#endif
Expand Down Expand Up @@ -117,8 +112,7 @@ class ESP32SvelteKit {
APService _apService;
EventSocket _socket;
#if FT_ENABLED(USE_NTP)
NTPSettingsService _ntpSettingsService;
NTPStatus _ntpStatus;
NTPService _ntpService;
#endif
#if FT_ENABLED(USE_UPLOAD_FIRMWARE)
UploadFirmwareService _uploadFirmwareService;
Expand Down
68 changes: 0 additions & 68 deletions esp32/lib/ESP32-sveltekit/NTPSettingsService.cpp

This file was deleted.

86 changes: 0 additions & 86 deletions esp32/lib/ESP32-sveltekit/NTPSettingsService.h

This file was deleted.

63 changes: 0 additions & 63 deletions esp32/lib/ESP32-sveltekit/NTPStatus.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions esp32/lib/ESP32-sveltekit/NTPStatus.h

This file was deleted.

Loading

0 comments on commit 3a3de53

Please sign in to comment.