Skip to content

Conversation

@Ahattalla
Copy link
Contributor

Proposed Changes

Created Meal details API request

Related Issues

List any related issues or pull requests.
N/A

Additional Information

N/A

Screenshot

N/A

Checklist

  • I have tested these changes locally.
  • I have added appropriate documentation or updated existing documentation.
  • I have added appropriate test coverage or updated existing test coverage.
  • I have updated the changelog (if applicable).
  • I have followed the project's code style and formatting guidelines.
  • I have reviewed and adhered to the project's contributing guidelines.

@Ahattalla Ahattalla self-assigned this Jul 20, 2023
@Ahattalla Ahattalla changed the title Feat: Meal details by id api 🍔 feat: [HL-80] Meal details by id api 🍔 Jul 20, 2023
@Ahattalla Ahattalla changed the title feat: [HL-80] Meal details by id api 🍔 feat: [HL-80] Meal details by id API 🍔 Jul 20, 2023
Comment on lines +10 to +11
var ingredients: [String] = []
var measures: [String] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var ingredients: [String] = []
var measures: [String] = []
let ingredients: [String] = []
let measures: [String] = []


// MARK: - Meal Details
public struct MealDetails: Decodable {
let id, name, drinkAlternate, category, area, instructions, thumbnail, tags: String?
Copy link
Contributor

Choose a reason for hiding this comment

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

Id should never be optional

@@ -0,0 +1,57 @@
// MARK: - MealDetailsResponse
public struct MealDetailsResponse: Decodable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public struct MealDetailsResponse: Decodable {
struct MealDetailsResponse: Decodable {

No need to make this public, just return a list of meals.

var ingredients: [String] = []
var measures: [String] = []

enum CodingKeys: String, CodingKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
enum CodingKeys: String, CodingKey {
private enum CodingKeys: String, CodingKey {

.compactMap { $0.isEmpty ? nil : $0}
}

private func dynamicValuesFor(dynamicKey: String, with decoder: Decoder) throws -> [String] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this. A good practice when adding a code that the others in the might might not be aware of is to write comments. Documentation helps your future self understand why ou added this in the first place.

@@ -0,0 +1,12 @@
struct DynamicCodingKeys: CodingKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding it, I like the idea 🙏🏼

Comment on lines +2 to +11
var intValue: Int?
init?(intValue: Int) {
self.intValue = intValue
self.stringValue = "\(intValue)"
}

var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var intValue: Int?
init?(intValue: Int) {
self.intValue = intValue
self.stringValue = "\(intValue)"
}
var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
let intValue: Int?
init?(intValue: Int) {
self.intValue = intValue
self.stringValue = "\(intValue)"
}
let stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}

To avoid duplication, you might consider making it generic, or at least have two versions for both Int and String.

Comment on lines +4 to +5
var ingredients: [String] = []
var measures: [String] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var ingredients: [String] = []
var measures: [String] = []
let ingredients: [String] = []
let measures: [String] = []

Mutability is a big source of bugs. Avoid it.

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.

3 participants