Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

레시피 리스트 fetch 데이터 관련 로직 수정 #37

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: 레시피들을 받아오는 데이터 네이밍과 형식 수정
  • Loading branch information
GeonH0 committed Jan 8, 2025
commit 480d5fa86e67deb83990d07007190bb2fe4aa334
24 changes: 9 additions & 15 deletions HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift
Original file line number Diff line number Diff line change
@@ -9,41 +9,35 @@ import Foundation

struct RecipeDTO: Decodable {

let id: Int
let type: String
let ID: Int
let name: String
let description: String
let likesCount: Int
let createdAt: String
let writer: UserDTO
let imageUrls: [RecipeImageDTO]
let recipeImageUrl: String
let isLikedByCurrentUser: Bool

enum CodingKeys: String, CodingKey {
case id = "recipeId"
case type = "recipeType"
case ID = "recipeId"
case name = "recipeName"
case description = "recipeDescription"
case likesCount = "recipeLikesCnt"
case createdAt = "createdAt"
case writer = "writer"
case imageUrls = "recipeImgUrls"
case recipeImageUrl = "recipeImageUrl"
case isLikedByCurrentUser = "isLiked"
}
}

extension RecipeDTO {
func toDomain() -> Recipe {
return Recipe(
id: id,
type: RecipeType(rawValue: type) ?? .coffee,
id: ID,
type: .coffee, // MARK: 임시 값 커피로 설정
name: name,
description: description,
description: "",
writer: writer.toDomain(),
imageUrls: imageUrls.map { $0.recipeImageUrl },
imageUrls: [recipeImageUrl],
isLikedByCurrentUser: isLikedByCurrentUser,
likeCount: likesCount,
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date()
createdAt: Date()
)
}
}
Original file line number Diff line number Diff line change
@@ -8,20 +8,17 @@
import Foundation

struct RecipeDetailDTO: Decodable {

let id: Int
let type: String
let name: String
let description: String
let likesCount: Int
let createdAt: String
let writer: UserDTO
let imageUrls: [RecipeImageDTO]
let imageUrls: [String] // 배열로 수신
let isLikedByCurrentUser: Bool

enum CodingKeys: String, CodingKey {
case id = "recipeId"
case type = "recipeType"
case name = "recipeName"
case description = "recipeDescription"
case likesCount = "recipeLikesCnt"
@@ -35,12 +32,12 @@ struct RecipeDetailDTO: Decodable {
extension RecipeDetailDTO {
func toDomain() -> Recipe {
return Recipe(
id: id,
type: RecipeType(rawValue: type) ?? .coffee,
id: id,
type: .coffee,
name: name,
description: description,
writer: writer.toDomain(),
imageUrls: imageUrls.map { $0.recipeImageUrl },
imageUrls: imageUrls,
isLikedByCurrentUser: isLikedByCurrentUser,
likeCount: likesCount,
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date()
Original file line number Diff line number Diff line change
@@ -10,11 +10,13 @@ import Foundation
struct RecipePageDTO: Decodable {
let totalPageNumber: Int
let pageNumber: Int
let lastBoundaryId: Int
let recipes: [RecipeDTO]

private enum CodingKeys: String, CodingKey {
case totalPageNumber = "totalPageNumber"
case pageNumber = "pageNumber"
case lastBoundaryId = "lastBoundaryId"
case recipes = "recipes"
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ struct RecipeUploadResponseDTO: Decodable {
let likesCount: Int
let createdAt: String
let writer: UserDTO
let imageUrls: [RecipeImageDTO]
let imageUrls: [String]
let isLikedByCurrentUser: Bool

enum CodingKeys: String, CodingKey {
@@ -41,7 +41,7 @@ extension RecipeUploadResponseDTO {
name: name,
description: description,
writer: writer.toDomain(),
imageUrls: imageUrls.map { $0.recipeImageUrl },
imageUrls: imageUrls,
isLikedByCurrentUser: isLikedByCurrentUser,
likeCount: likesCount,
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date()