From e9d4af2cb4fb46ea4507d929513246ffa9a64ea6 Mon Sep 17 00:00:00 2001 From: GeonH0 Date: Mon, 10 Jun 2024 17:44:47 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20RecipeDTO=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Network/DTO/RecipeDTO.swift | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift new file mode 100644 index 0000000..5cf8bff --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift @@ -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() + ) + } +} + +