Skip to content

Conversation

@bcooleyfetch
Copy link
Collaborator

@bcooleyfetch bcooleyfetch commented Feb 2, 2025

What is this?

This pull request is for the MVP version of the Fetch iOS Software Engineer take-home assessment. It features the ability to fetch recipes from an API, refresh the list of recipes, and deal with empty and malformed data.

What's included?

This PR includes:

  • First passes at:
    • Recipe model
    • APIService
    • RecipeViewModel
    • RecipeView
      • Each recipe is shown as an entry in a list where an image, name, and cuisine of the recipe is shown.
  • AsyncImage is used for caching and loading images in phases.
    • Includes failure and loading states for images

Overall Testing

  • Ensure app builds without warnings or errors

Testing Data Retrieval From Standard API

Testing for data retrieval from the standard recipes API is straightforward, and it is the currently loaded endpoint is inside of the APIClient.

  • Ensure app loads on device
  • Ensure data loads and populates the list
  • Ensure scrolling to the bottom of the list works
  • Ensure image loading is happening
  • Try pull to refresh and ensure the UI shows a refresh spinner.

Testing Data Retrieval From Malformed Data API

In order to test for this, replace line 12 in APIClient with

private let baseURL: String = "https://d3jbb8n5wk0qxi.cloudfront.net/recipes-malformed.json"
  • Ensure app loads on device
  • Ensure no data loads, but instead the screen displays an error message.

Testing Data Retrieval From Empty Data API

In order to test for this, replace line 12 in APIClient with

private let baseURL: String = "https://d3jbb8n5wk0qxi.cloudfront.net/recipes-empty.json"
  • Ensure app loads on device
  • Ensure no data loads, but instead the screen displays an error message.

Testing Images / Videos

Standard Data API

Light Appearance Dark Appearance
Light Appearance Dark Appearance

Malformed & Empty Data APIs

Light Appearance Dark Appearance
Light Appearance Dark Appearance

@bcooleyfetch bcooleyfetch marked this pull request as ready for review February 2, 2025 03:14

final class APIService: APIServiceProtocol {

private let baseURL: String = "https://d3jbb8n5wk0qxi.cloudfront.net/recipes.json"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future Upgrade

It would be nice to be able to initialize the API with whatever endpoint we want. Might want to find a mechanism in the next version to do this.

Comment on lines +24 to +25
print("Error with HTTP response: \(String(describing: response))")
return []
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future Upgrade

Better error handling here would be nice and would allow for a better UX. Also would probably be nice to see a difference between malformed data and empty data.

private let baseURL: String = "https://d3jbb8n5wk0qxi.cloudfront.net/recipes.json"

func fetchRecipies() async -> [Recipe] {
let url = URL(string: baseURL)!
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stability Improvement

Probably should be using a guard statement here when we allow for any URL to be passed into the client.


init(apiService: APIServiceProtocol = APIService()) {
self.apiService = apiService
Task { await self.fetchRecipies()}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug Exploration

This might not be thread-safe? Should look into this more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stability Improvement

Probably would be better to break this out into some components. I feel like there is some redundant code but also just some clear reusable components that could be made here.

@bcooleyfetch bcooleyfetch merged commit 3b6b493 into main Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants