Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Stream-iOS/Stream-iOS/Core/Networking/APIError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// APIError.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//

import Foundation
enum APIError: Error, Equatable {
case invalidResponse
case httpStatus(Int)
case decodingFailed
}
10 changes: 10 additions & 0 deletions Stream-iOS/Stream-iOS/Core/Networking/CharacterRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// CharacterRepository.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//

protocol CharacterRepository: Sendable {
func fetchCharacters(page: Int) async throws -> PagedResponse<CharacterDTO>
}
26 changes: 26 additions & 0 deletions Stream-iOS/Stream-iOS/Core/Networking/Endpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Endpoint.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//

import Foundation

struct Endpoint{
let path : String
let queryItems : [URLQueryItem]
var url:URL? {
var components = URLComponents()
components.scheme = "https"
components.host = "rickandmortyapi.com"
components.path = "/api" + path
components.queryItems = queryItems.isEmpty ? nil : queryItems
return components.url
}
}
extension Endpoint {
static func characters(page:Int) -> Endpoint{
Endpoint(path: "/character", queryItems: [URLQueryItem(name: "page", value: "\(page)")])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// URLSessionCharacterRepository.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//

import Foundation
16 changes: 16 additions & 0 deletions Stream-iOS/Stream-iOSTests/EndpointTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// EndpointTests.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//
import Testing
import Foundation
@testable import Stream_iOS

struct EndpointTests {
@Test func buildsCharacterPageURL() throws { // <- throws here
let url = try #require(Endpoint.characters(page: 3).url)
#expect(url.absoluteString == "https://rickandmortyapi.com/api/character?page=3")
}
}
19 changes: 19 additions & 0 deletions Stream-iOS/Stream-iOSTests/Mocks/MockCharacterRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MockCharacterRepository.swift
// Stream-iOS
//
// Created by Ullash Podder on 14/07/2026.
//
//import Testing
//import Foundation
@testable import Stream_iOS

final class MockCharacterRepository: CharacterRepository, @unchecked Sendable {
var result: Result<PagedResponse<CharacterDTO>, Error> = .failure(APIError.invalidResponse)
private(set) var requestedPages: [Int] = []

func fetchCharacters(page: Int) async throws -> PagedResponse<CharacterDTO> {
requestedPages.append(page)
return try result.get()
}
}
19 changes: 0 additions & 19 deletions Stream-iOS/Stream-iOSTests/Stream_iOSTests.swift

This file was deleted.

Loading