medmap-ios/medmap/Network/MedMapAPI.swift
Ricardo Araújo d082bf699f login fix
2026-09-15 17:22:42 +01:00

104 lines
3.9 KiB
Swift

//
// FluxReaderAPI.swift
// FluxRead
//
// Created by RSA on 13/01/2026.
//
import Foundation
import Alamofire
import UIKit
class MedMapAPI {
private let apiClient: APIClient = DIContainer.shared.resolve()
private let baseURL: String
init(baseURL: String = "https://fluxreader.desynced.net") {
self.baseURL = baseURL
}
// MARK: - Auth
func login(email: String, password: String) async throws -> LoginResponse {
let url = "\(baseURL)/api/auth/login"
return try await apiClient.request(url, method: .post, parameters: LoginRequest(email: email, password: password))
}
func signup(email: String, password: String, role: Role) async throws -> LoginResponse {
let url = "\(baseURL)/api/auth/signup"
return try await apiClient.request(url, method: .post, parameters: SignupRequest(email: email, password: password, role: role))
}
// MARK: - Companies
func createCompany(request: CreateCompanyRequest) async throws -> CompanyDTO {
let url = "\(baseURL)/api/companies"
return try await apiClient.request(url, method: .post, parameters: request)
}
// MARK: - Professionals
func createProfessional(request: CreateProfessionalRequest) async throws -> ProfessionalResponse {
let url = "\(baseURL)/api/professionals"
return try await apiClient.request(url, method: .post, parameters: request)
}
func listProfessionals(companyId: String) async throws -> [ProfessionalResponse] {
let url = "\(baseURL)/api/professionals/list"
return try await apiClient.request(url, method: .post, parameters: ListProfessionalsRequest(companyId: companyId))
}
// MARK: - Patients
func createPatient(request: CreatePatientRequest) async throws -> PatientDTO {
let url = "\(baseURL)/api/patients"
return try await apiClient.request(url, method: .post, parameters: request)
}
func getPatient(id: String) async throws -> PatientDTO {
let url = "\(baseURL)/api/patients/\(id)"
return try await apiClient.request(url, method: .get)
}
func getMyPatientProfile() async throws -> PatientDTO {
let url = "\(baseURL)/api/patients/me"
return try await apiClient.request(url, method: .get)
}
func listPatients(professionalId: String) async throws -> PatientsByProfessionalResponse {
let url = "\(baseURL)/api/patients/list"
return try await apiClient.request(url, method: .post, parameters: ListPatientsRequest(professionalId: professionalId))
}
// MARK: - Prescriptions
func createPrescription(request: CreatePrescriptionRequest) async throws -> PrescriptionResponse {
let url = "\(baseURL)/api/prescriptions/create"
return try await apiClient.request(url, method: .post, parameters: request)
}
func changePrescriptionSchedule(request: ChangePrescriptionScheduleRequest) async throws -> PrescriptionScheduleResponse {
let url = "\(baseURL)/api/prescriptions/schedule"
return try await apiClient.request(url, method: .put, parameters: request)
}
func listPrescriptions(patientId: String, activeOnly: Bool = false, scheduleFilter: ScheduleFilter = .activeOnly) async throws -> [PrescriptionWithSchedulesResponse] {
let url = "\(baseURL)/api/prescriptions/list"
let request = ListPrescriptionsRequest(patientId: patientId, activeOnly: activeOnly, scheduleFilter: scheduleFilter)
return try await apiClient.request(url, method: .post, parameters: request)
}
func listMyActivePrescriptions() async throws -> [PrescriptionWithSchedulesResponse] {
let url = "\(baseURL)/api/prescriptions/my-active"
return try await apiClient.request(url, method: .get)
}
// MARK: - Medications
func listMedications() async throws -> ListOfMedicationsResponse {
let url = "\(baseURL)/api/medication/list"
return try await apiClient.request(url, method: .get)
}
}