-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// RecipeDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/10/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipesResponseDTO: Decodable { | ||
let statusCode: Int | ||
let message: String | ||
let data: [RecipeDTO] | ||
} | ||
|
||
struct RecipeDTO: Decodable { | ||
let recipeId: Int | ||
let recipeType: String | ||
let recipeName: String | ||
let recipeDescription: String | ||
let recipeLikesCnt: Int | ||
let createdAt: String | ||
let writer: UserDTO | ||
let recipeImgUrls: [RecipeImageDTO] | ||
} | ||
|
||
struct RecipeImageDTO: Decodable { | ||
let recipeImgId: Int | ||
let recipeImgUrl: String | ||
} | ||
|
||
extension RecipeDTO { | ||
func toDomain() -> Recipe { | ||
return Recipe( | ||
id: recipeId, | ||
type: RecipeType(rawValue: recipeType) ?? .dessert, | ||
name: recipeName, | ||
description: recipeDescription, | ||
writer: writer.toDomain(), | ||
imageUrls: recipeImgUrls.map { $0.recipeImgUrl }, | ||
isLiked: false, | ||
likeCount: recipeLikesCnt, | ||
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date() | ||
) | ||
} | ||
} | ||
|
||
|