Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Created by 최윤진 on 2/27/26.
//

import FirebaseFirestore
import Foundation

struct PushNotificationCursorDTO {
let receivedAt: Timestamp
let receivedAt: Date
let documentID: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// Created by 최윤진 on 2/10/26.
//

import FirebaseFirestore
import Foundation

struct PushNotificationResponse: Decodable {
@DocumentID var id: String?
struct PushNotificationResponse {
let id: String
let title: String
let body: String
let receivedAt: Timestamp
let receivedAt: Date
let isRead: Bool
let todoID: String
let todoKind: String
Expand Down
13 changes: 13 additions & 0 deletions DevLog/Data/DTO/TodoCursorDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TodoCursorDTO.swift
// DevLog
//
// Created by opfic on 2/21/26.
//

import Foundation

struct TodoCursorDTO {
let createdAt: Date
let documentID: String
}
37 changes: 37 additions & 0 deletions DevLog/Data/DTO/TodoDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// TodoDTO.swift
// DevLog
//
// Created by 최윤진 on 12/14/25.
//

import Foundation

struct TodoRequest: Encodable {
let id: String
let isPinned: Bool
let isCompleted: Bool
let isChecked: Bool
let title: String
let content: String
let createdAt: Date
let updatedAt: Date
let dueDate: Date?
let tags: [String]
let kind: TodoKind

}
Comment on lines +10 to +23

Choose a reason for hiding this comment

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

medium

TodoRequest를 인코딩할 때 id 프로퍼티가 인코딩에서 제외되도록 CodingKeys를 명시적으로 정의하는 것을 고려해 보세요. id는 Firestore 문서의 ID로 사용되며, 데이터 페이로드에는 포함되지 않는 것이 일반적입니다. CodingKeys를 사용하면 TodoService에서 수동으로 id 키를 제거하는 로직을 없앨 수 있어, DTO의 역할이 더 명확해지고 코드가 간결해집니다.

이 변경을 적용하려면 TodoServiceupsertTodo 메서드에서 data.removeValue(forKey: TodoFieldKey.id.rawValue) 라인도 함께 제거해야 합니다.

struct TodoRequest: Encodable {
    let id: String
    let isPinned: Bool
    let isCompleted: Bool
    let isChecked: Bool
    let title: String
    let content: String
    let createdAt: Date
    let updatedAt: Date
    let dueDate: Date?
    let tags: [String]
    let kind: TodoKind

    enum CodingKeys: String, CodingKey {
        case isPinned, isCompleted, isChecked, title, content, createdAt, updatedAt, dueDate, tags, kind
    }
}


struct TodoResponse {
let id: String
let isPinned: Bool
let isCompleted: Bool
let isChecked: Bool
let title: String
let content: String
let createdAt: Date
let updatedAt: Date
let dueDate: Date?
let tags: [String]
let kind: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

struct TodoPageResponse {
let items: [TodoResponse]
let nextCursor: TodoCursorResponse?
let nextCursor: TodoCursorDTO?
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 최윤진 on 2/9/26.
//

import FirebaseFirestore
import Foundation

struct WebPageRequest: Encodable {
let title: String
Expand All @@ -14,8 +14,8 @@ struct WebPageRequest: Encodable {
let imageURL: String
}

struct WebPageResponse: Decodable {
@DocumentID var id: String?
struct WebPageResponse {
let id: String
let title: String
let url: String
let displayURL: String
Expand Down
11 changes: 3 additions & 8 deletions DevLog/Data/Mapper/PushNotificationMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
// Created by 최윤진 on 2/27/26.
//

import FirebaseFirestore

extension PushNotificationResponse {
func toDomain() throws -> PushNotification {
guard let id = self.id else {
throw DataError.invalidData("PushNotificationResponse.id is nil")
}
guard let todoKind = TodoKind(rawValue: self.todoKind) else {
throw DataError.invalidData("PushNotificationResponse.todoKind is invalid: \(self.todoKind)")
}
Expand All @@ -20,7 +15,7 @@ extension PushNotificationResponse {
id: id,
title: self.title,
body: self.body,
receivedAt: self.receivedAt.dateValue(),
receivedAt: self.receivedAt,
isRead: self.isRead,
todoID: self.todoID,
todoKind: todoKind
Expand All @@ -31,14 +26,14 @@ extension PushNotificationResponse {
extension PushNotificationCursorDTO {
func toDomain() -> PushNotificationCursor {
PushNotificationCursor(
receivedAt: self.receivedAt.dateValue(),
receivedAt: self.receivedAt,
documentID: self.documentID
)
}

static func fromDomain(_ cursor: PushNotificationCursor) -> Self {
PushNotificationCursorDTO(
receivedAt: Timestamp(date: cursor.receivedAt),
receivedAt: cursor.receivedAt,
documentID: cursor.documentID
)
}
Expand Down
13 changes: 4 additions & 9 deletions DevLog/Data/Mapper/TodoMapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by 최윤진 on 2/19/26.
//

import FirebaseFirestore

extension TodoRequest {
static func fromDomain(_ entity: Todo) -> Self {
TodoRequest(
Expand All @@ -27,9 +25,6 @@ extension TodoRequest {

extension TodoResponse {
func toDomain() throws -> Todo {
guard let id = self.id else {
throw DataError.invalidData("TodoResponse.id is nil")
}
guard let kind = TodoKind(rawValue: self.kind) else {
throw DataError.invalidData("TodoResponse.kind is invalid: \(self.kind)")
}
Expand All @@ -50,17 +45,17 @@ extension TodoResponse {
}
}

extension TodoCursorResponse {
extension TodoCursorDTO {
func toDomain() -> TodoCursor {
TodoCursor(
createdAt: createdAt.dateValue(),
createdAt: createdAt,
documentID: documentID
)
}

static func fromDomain(_ cursor: TodoCursor) -> Self {
TodoCursorResponse(
createdAt: Timestamp(date: cursor.createdAt),
TodoCursorDTO(
createdAt: cursor.createdAt,
documentID: cursor.documentID
)
}
Expand Down
35 changes: 0 additions & 35 deletions DevLog/Data/Protocol/Dictionaryable.swift

This file was deleted.

2 changes: 1 addition & 1 deletion DevLog/Data/Repository/TodoRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class TodoRepositoryImpl: TodoRepository {
}

func fetchTodos(_ query: TodoQuery, cursor: TodoCursor?) async throws -> TodoPage {
let responseCursor = cursor.map { TodoCursorResponse.fromDomain($0) }
let responseCursor = cursor.map { TodoCursorDTO.fromDomain($0) }
let response = try await todoService.fetchTodos(query, cursor: responseCursor)
return try response.toDomain()
}
Expand Down
13 changes: 0 additions & 13 deletions DevLog/Infra/DTO/TodoCursorResponse.swift

This file was deleted.

79 changes: 0 additions & 79 deletions DevLog/Infra/DTO/TodoDTO.swift

This file was deleted.

2 changes: 1 addition & 1 deletion DevLog/Infra/Extension/FirebaseAuthUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import FirebaseAuth

extension FirebaseAuth.User {
func toResponse(
func makeResponse(
providerID: AuthProviderID,
fcmToken: String,
accessToken: String? = nil
Expand Down
Loading