Skip to content

Commit

Permalink
Feat: RecipeDTO 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
GeonH0 committed Jun 10, 2024
1 parent 5fcb880 commit 0c68193
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// RecipeDTO.swift
// HomeCafeRecipes
//
// Created by 김건호 on 6/10/24.
//

import Foundation

struct RecipeDTO: Decodable {
private enum CodingKeys: String, CodingKey {
case recipeId = "recipeId"
case recipeType = "recipeType"
case recipeName = "recipeName"
case recipeDescription = "recipeDescription"
case recipeLikesCnt = "recipeLikesCnt"
case createdAt = "createdAt"
case recipeImgUrls = "recipeImgUrls"
case writer = "writer"
}

let recipeId: Int
let recipeType: String
let recipeName: String
let recipeDescription: String
let recipeLikesCnt: Int
let createdAt: String
let recipeImgUrls: [RecipeImageDTO]
let writer: UserDTO
}

struct RecipeImageDTO: Decodable {
private enum CodingKeys: String, CodingKey {
case recipeImgId = "recipeImgId"
case recipeImgUrl = "recipeImgUrl"
}

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()
)
}
}

extension RecipeImageDTO {
func toDomain() -> String {
return recipeImgUrl
}
}

0 comments on commit 0c68193

Please sign in to comment.