Methods for editing/deleting audio records

This commit is contained in:
Selim Mustafaev 2025-03-31 17:46:17 +03:00
parent 94e4605af3
commit c7a2234b3f
5 changed files with 54 additions and 15 deletions

View File

@ -148,6 +148,7 @@
7AA514E02D0B75B3001CAC50 /* StorageService+Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA514DF2D0B75B3001CAC50 /* StorageService+Events.swift */; };
7AA515D02D9ABCC800EB3418 /* RecordPlayerService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA515CF2D9ABCC800EB3418 /* RecordPlayerService.swift */; };
7AA515D22D9ABCE600EB3418 /* RecordPlayerServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA515D12D9ABCE600EB3418 /* RecordPlayerServiceProtocol.swift */; };
7AA515DA2D9ADEF000EB3418 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AA515D92D9ADEF000EB3418 /* StorageError.swift */; };
7AA7BC3525A5DFB80053A5D5 /* ExceptionCatcher in Frameworks */ = {isa = PBXBuildFile; productRef = 7A813DC02508C4D900CC93B9 /* ExceptionCatcher */; };
7AA7BC3625A5DFB80053A5D5 /* PKHUD in Frameworks */ = {isa = PBXBuildFile; productRef = 7AABDE1C2532F3EB0041AFC6 /* PKHUD */; };
7AAAFAD32C4D0FD00050410D /* ACImageSliderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AAAFAD22C4D0FD00050410D /* ACImageSliderView.swift */; };
@ -448,6 +449,7 @@
7AA514DF2D0B75B3001CAC50 /* StorageService+Events.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StorageService+Events.swift"; sourceTree = "<group>"; };
7AA515CF2D9ABCC800EB3418 /* RecordPlayerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordPlayerService.swift; sourceTree = "<group>"; };
7AA515D12D9ABCE600EB3418 /* RecordPlayerServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordPlayerServiceProtocol.swift; sourceTree = "<group>"; };
7AA515D92D9ADEF000EB3418 /* StorageError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageError.swift; sourceTree = "<group>"; };
7AAAFAD22C4D0FD00050410D /* ACImageSliderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ACImageSliderView.swift; sourceTree = "<group>"; };
7AAAFAD92C4D1AFE0050410D /* Zoomable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Zoomable.swift; sourceTree = "<group>"; };
7AAAFADB2C4D1E130050410D /* ACImageSliderView+Modifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ACImageSliderView+Modifier.swift"; sourceTree = "<group>"; };
@ -1085,6 +1087,7 @@
7AA514DF2D0B75B3001CAC50 /* StorageService+Events.swift */,
7ABDA80E2D8723F90083C715 /* StorageService+AudioRecords.swift */,
7A54BFD22D43B95E00176D6D /* DbUpdatePolicy.swift */,
7AA515D92D9ADEF000EB3418 /* StorageError.swift */,
);
path = StorageService;
sourceTree = "<group>";
@ -1663,6 +1666,7 @@
7AB4E4382D3D0C5C0006D052 /* VehiclesArchive.swift in Sources */,
7A64A21C2C19E87B00284124 /* OsagoDto.swift in Sources */,
7AA515D22D9ABCE600EB3418 /* RecordPlayerServiceProtocol.swift in Sources */,
7AA515DA2D9ADEF000EB3418 /* StorageError.swift in Sources */,
7A809F392D66755B00CF1B3C /* Error+Canceled.swift in Sources */,
7AF6D21D2677C1680086EA64 /* Osago.swift in Sources */,
7A1CF81629A42117007962DA /* Realm.swift in Sources */,

View File

@ -0,0 +1,26 @@
//
// StorageError.swift
// AutoCatCore
//
// Created by Selim Mustafaev on 31.03.2025.
// Copyright © 2025 Selim Mustafaev. All rights reserved.
//
import Foundation
public enum StorageError: LocalizedError {
case vehicleNotFound
case noteNotFound
case eventNotFound
case recordNotFound
public var errorDescription: String? {
switch self {
case .vehicleNotFound: "Vehicle not found in realm database"
case .noteNotFound: "Vehicle note not found in realm database"
case .eventNotFound: "Event not found in realm database"
case .recordNotFound: "Audio record not found in realm database"
}
}
}

View File

@ -23,4 +23,26 @@ public extension StorageService {
.sorted(byKeyPath: "addedDate", ascending: false)
.map(\.dto)
}
func deleteRecord(id: TimeInterval) async throws {
guard let record = realm.object(ofType: AudioRecord.self, forPrimaryKey: id) else {
throw StorageError.recordNotFound
}
try await realm.asyncWrite {
realm.delete(record)
}
}
func updateRecord(_ record: AudioRecordDto) async throws {
guard let record = realm.object(ofType: AudioRecord.self, forPrimaryKey: record.id) else {
throw StorageError.recordNotFound
}
try await realm.asyncWrite {
realm.add(record, update: .modified)
}
}
}

View File

@ -9,21 +9,6 @@
import Foundation
import RealmSwift
public enum StorageError: LocalizedError {
case vehicleNotFound
case noteNotFound
case eventNotFound
public var errorDescription: String? {
switch self {
case .vehicleNotFound: "Vehicle not found in realm database"
case .noteNotFound: "Vehicle note not found in realm database"
case .eventNotFound: "Event not found in realm database"
}
}
}
public actor StorageService: StorageServiceProtocol {
let settingsService: SettingsServiceProtocol

View File

@ -35,4 +35,6 @@ public protocol StorageServiceProtocol: Sendable {
// Audio records
func add(record: AudioRecordDto) async throws
func loadRecords() async throws -> [AudioRecordDto]
func deleteRecord(id: TimeInterval) async throws
func updateRecord(_ record: AudioRecordDto) async throws
}