Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:[HL-81]Single Random Meal API #92

Merged
merged 2 commits into from
Jul 13, 2023
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
32 changes: 18 additions & 14 deletions Healthy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
027DDA2B2A0E6A680052818C /* (null) in Resources */ = {isa = PBXBuildFile; };
027DDA402A0E6A680052818C /* HealthyUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027DDA3F2A0E6A680052818C /* HealthyUITests.swift */; };
027DDA422A0E6A680052818C /* HealthyUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027DDA412A0E6A680052818C /* HealthyUITestsLaunchTests.swift */; };
0286F2862A5EEB1800F20478 /* RandomMealEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0286F2852A5EEB1800F20478 /* RandomMealEntity.swift */; };
02892EC82A58575C001A3DB4 /* Networking in Frameworks */ = {isa = PBXBuildFile; productRef = 02892EC72A58575C001A3DB4 /* Networking */; };
02892ECA2A599CBC001A3DB4 /* Container+Networking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02892EC92A599CBC001A3DB4 /* Container+Networking.swift */; };
0296F7932A4342B500DBC86A /* FacebookCore in Frameworks */ = {isa = PBXBuildFile; productRef = 0296F7922A4342B500DBC86A /* FacebookCore */; };
Expand Down Expand Up @@ -129,13 +130,13 @@
B2F799E92A344B9A002F1894 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F799E82A344B9A002F1894 /* MainTabBarController.swift */; };
B85D26A72A3902DF000A463D /* EmailValidatorsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85D26A62A3902DF000A463D /* EmailValidatorsTests.swift */; };
B85D26A92A390331000A463D /* PasswordValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85D26A82A390331000A463D /* PasswordValidatorTests.swift */; };
C21F76E42A4AFBF700E0609C /* Collection+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C21F76E32A4AFBF700E0609C /* Collection+Helpers.swift */; };
C2FE12102A4128D8001A7BE3 /* UIButton+AnimatableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FE120F2A4128D8001A7BE3 /* UIButton+AnimatableView.swift */; };
C2FE12122A412904001A7BE3 /* AnimatableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FE12112A412904001A7BE3 /* AnimatableView.swift */; };
C9057FE62A48AC78002E4459 /* SliderDishesView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9057FE42A48AC78002E4459 /* SliderDishesView.xib */; };
C9057FE72A48AC78002E4459 /* SliderDishesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9057FE52A48AC78002E4459 /* SliderDishesView.swift */; };
C9057FEB2A48AC8F002E4459 /* SliderCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9057FE92A48AC8F002E4459 /* SliderCollectionViewCell.swift */; };
C9057FEC2A48AC8F002E4459 /* SliderCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9057FEA2A48AC8F002E4459 /* SliderCollectionViewCell.xib */; };
C21F76E42A4AFBF700E0609C /* Collection+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C21F76E32A4AFBF700E0609C /* Collection+Helpers.swift */; };
C2FE12102A4128D8001A7BE3 /* UIButton+AnimatableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FE120F2A4128D8001A7BE3 /* UIButton+AnimatableView.swift */; };
C2FE12122A412904001A7BE3 /* AnimatableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FE12112A412904001A7BE3 /* AnimatableView.swift */; };
C9E6BBE92A38D7EA0073E51A /* SplashViewControllerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E6BBE82A38D7EA0073E51A /* SplashViewControllerTest.swift */; };
C9EF41102A34656800E859AD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9EF410E2A34656800E859AD /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -213,6 +214,7 @@
027DDA3B2A0E6A680052818C /* HealthyUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HealthyUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
027DDA3F2A0E6A680052818C /* HealthyUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthyUITests.swift; sourceTree = "<group>"; };
027DDA412A0E6A680052818C /* HealthyUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthyUITestsLaunchTests.swift; sourceTree = "<group>"; };
0286F2852A5EEB1800F20478 /* RandomMealEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomMealEntity.swift; sourceTree = "<group>"; };
02892EC52A585558001A3DB4 /* Networking */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Networking; sourceTree = "<group>"; };
02892EC92A599CBC001A3DB4 /* Container+Networking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Container+Networking.swift"; sourceTree = "<group>"; };
0296F7962A43491B00DBC86A /* FacebookAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FacebookAuthenticator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,13 +279,13 @@
B2F799E82A344B9A002F1894 /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; };
B85D26A62A3902DF000A463D /* EmailValidatorsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailValidatorsTests.swift; sourceTree = "<group>"; };
B85D26A82A390331000A463D /* PasswordValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordValidatorTests.swift; sourceTree = "<group>"; };
C21F76E32A4AFBF700E0609C /* Collection+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Helpers.swift"; sourceTree = "<group>"; };
C2FE120F2A4128D8001A7BE3 /* UIButton+AnimatableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+AnimatableView.swift"; sourceTree = "<group>"; };
C2FE12112A412904001A7BE3 /* AnimatableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatableView.swift; sourceTree = "<group>"; };
C9057FE42A48AC78002E4459 /* SliderDishesView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SliderDishesView.xib; sourceTree = "<group>"; };
C9057FE52A48AC78002E4459 /* SliderDishesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderDishesView.swift; sourceTree = "<group>"; };
C9057FE92A48AC8F002E4459 /* SliderCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderCollectionViewCell.swift; sourceTree = "<group>"; };
C9057FEA2A48AC8F002E4459 /* SliderCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SliderCollectionViewCell.xib; sourceTree = "<group>"; };
C21F76E32A4AFBF700E0609C /* Collection+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Helpers.swift"; sourceTree = "<group>"; };
C2FE120F2A4128D8001A7BE3 /* UIButton+AnimatableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+AnimatableView.swift"; sourceTree = "<group>"; };
C2FE12112A412904001A7BE3 /* AnimatableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatableView.swift; sourceTree = "<group>"; };
C9D16A452A3C64A5008C7732 /* UIImage.Generated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImage.Generated.swift; sourceTree = "<group>"; };
C9E6BBE82A38D7EA0073E51A /* SplashViewControllerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewControllerTest.swift; sourceTree = "<group>"; };
C9EF410F2A34656800E859AD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -391,6 +393,7 @@
children = (
025511BC2A3C656300295B91 /* Recipe.swift */,
025511BA2A3C655200295B91 /* SavedRecipe.swift */,
0286F2852A5EEB1800F20478 /* RandomMealEntity.swift */,
);
path = Entities;
sourceTree = "<group>";
Expand Down Expand Up @@ -977,6 +980,14 @@
path = Validators;
sourceTree = "<group>";
};
C2FE120E2A4128BA001A7BE3 /* AnimatableView */ = {
isa = PBXGroup;
children = (
C2FE12112A412904001A7BE3 /* AnimatableView.swift */,
);
path = AnimatableView;
sourceTree = "<group>";
};
C9057FE32A48AC68002E4459 /* SliderDishesView */ = {
isa = PBXGroup;
children = (
Expand All @@ -996,14 +1007,6 @@
path = SliderCollectionViewCell;
sourceTree = "<group>";
};
C2FE120E2A4128BA001A7BE3 /* AnimatableView */ = {
isa = PBXGroup;
children = (
C2FE12112A412904001A7BE3 /* AnimatableView.swift */,
);
path = AnimatableView;
sourceTree = "<group>";
};
C96520C82A2B72B800FACCC0 /* Logger */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1269,6 +1272,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0286F2862A5EEB1800F20478 /* RandomMealEntity.swift in Sources */,
0266E7E62A56372500D5ABC4 /* UINavigationBar+Appearance.swift in Sources */,
C2FE12122A412904001A7BE3 /* AnimatableView.swift in Sources */,
025511C42A3D058800295B91 /* AppCoordinator.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions Healthy/Classes/Entities/RandomMealEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

// MARK: - RandomMealEntity
struct RandomMealEntity {
let mealId: String
let mealName: String
let mealCategory: String
let mealArea: String
let mealThumb: String
let mealTags: String
let mealYoutube: String
}
38 changes: 38 additions & 0 deletions Networking/Sources/Networking/Requests/RandomMealsRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Foundation

// MARK: - RandomMealsResponse
public struct RandomMealsResponse: Codable {
public let meals: [RandomMeal]
}

// MARK: - RandomMeal
public struct RandomMeal: Codable {
public let mealId: String
public let mealName: String
public let mealCategory: String
public let mealArea: String
public let mealThumb: String
public let mealTags: String
public let mealYoutube: String

private enum CodingKeys: String, CodingKey {
case mealId = "idMeal"
case mealName = "strMeal"
case mealCategory = "strCategory"
case mealArea = "strArea"
case mealThumb = "strMealThumb"
case mealTags = "strTags"
case mealYoutube = "strYoutube"
}
}

// MARK: - RandomMealsRequest
public struct RandomMealsRequest: RequestType {
public typealias ResponseType = RandomMealsResponse

public init() {}

public var baseUrl: URL { Constants.theMealDB }
public var path: String { "random.php" }
public var method: String { "GET" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import XCTest
@testable import Networking

final class RandomMealsRequestTests: XCTestCase {

// MARK: Properties

private var sut: RandomMealsRequest!

// MARK: - Lifecycle

override func setUp() {
sut = RandomMealsRequest()
}

// MARK: - Tests

func testRandomMealsRequestProperties() {
// Then
XCTAssertEqual(sut.baseUrl, Constants.theMealDB)
XCTAssertEqual(sut.path, "random.php")
XCTAssertEqual(sut.method, "GET")
}

func testRandomMealsResponseDecoder() throws {
// Given
let randomMealsResponseAsString = """
{
"meals": [
{
"idMeal": "52793",
"strMeal": "Sticky Toffee Pudding Ultimate",
"strCategory": "Dessert",
"strArea": "British",
"strMealThumb": "https://www.themealdb.com/images/media/meals/xrptpq1483909204.jpg",
"strTags": "Pudding,Desert,Cake,Dairy",
"strYoutube": "https://www.youtube.com/watch?v=hKq6RbxJHBo",
}
]
}
"""

// When
let randomMealsResponseData = try XCTUnwrap(randomMealsResponseAsString.data(using: .utf8))
let randomMealsResponse = try? sut.responseDecoder(randomMealsResponseData)

// Then
XCTAssertNotNil(randomMealsResponse)
XCTAssertEqual(randomMealsResponse?.meals.count, 1)
XCTAssertEqual(randomMealsResponse?.meals[0].mealId, "52793")
}

}