Skip to content

Commit

Permalink
rename to payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ski-u committed Oct 30, 2024
1 parent b43e16b commit 0fe098c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Features/Sources/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension APIClient: DependencyKey {

let (data, _) = try await URLSession.shared.data(from: components.url!)
return try AstronomyPicture(
response: JSONDecoder().decode(AstronomyPicture.Response.self, from: data)
payload: JSONDecoder().decode(AstronomyPicture.Payload.self, from: data)
)
}
)
Expand Down
18 changes: 9 additions & 9 deletions Features/Sources/Models/AstronomyPicture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ public struct AstronomyPicture: Equatable, Sendable {
self.url = url
}

public init(response: Response) {
public init(payload: Payload) {
self.init(
copyright: response.copyright,
date: try? LocalDate(from: response.date),
explanation: response.explanation,
hdURL: response.hdURL.map { URL(string: $0)! },
mediaType: MediaType(string: response.mediaType),
title: response.title,
url: URL(string: response.url)
copyright: payload.copyright,
date: try? LocalDate(from: payload.date),
explanation: payload.explanation,
hdURL: payload.hdURL.map { URL(string: $0)! },
mediaType: MediaType(string: payload.mediaType),
title: payload.title,
url: URL(string: payload.url)
)
}
}

extension AstronomyPicture {
public struct Response: Decodable {
public struct Payload: Decodable {
public var copyright: String?
public var date: String
public var explanation: String
Expand Down
6 changes: 3 additions & 3 deletions Features/Tests/ModelsTests/AstronomyPictureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Testing
@MainActor
struct AstronomyPictureTests {
@Test
func initFromResponse() {
let response = AstronomyPicture.Response(
func initFromPayload() {
let payload = AstronomyPicture.Payload(
copyright: "copyright",
date: "2024-01-01",
explanation: "explanation",
Expand All @@ -28,6 +28,6 @@ struct AstronomyPictureTests {
url: URL(string: "https://example.com/url")!
)

#expect(AstronomyPicture(response: response) == model)
#expect(AstronomyPicture(payload: payload) == model)
}
}

0 comments on commit 0fe098c

Please sign in to comment.