-
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.
Merge pull request #326 from DeveloperAcademy-POSTECH/main
[Release] main -> release
- Loading branch information
Showing
268 changed files
with
11,821 additions
and
4,319 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,14 @@ | ||
// | ||
// FolderData+CoreDataClass.swift | ||
// Reazy | ||
// | ||
// Created by 유지수 on 11/19/24. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
|
||
@objc(FolderData) | ||
public class FolderData: NSManagedObject { | ||
|
||
} |
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,25 @@ | ||
// | ||
// FolderData+CoreDataProperties.swift | ||
// Reazy | ||
// | ||
// Created by 유지수 on 11/19/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import CoreData | ||
|
||
extension FolderData { | ||
|
||
@nonobjc public class func fetchRequest() -> NSFetchRequest<FolderData> { | ||
return NSFetchRequest<FolderData>(entityName: "FolderData") | ||
} | ||
|
||
@NSManaged public var id: UUID | ||
@NSManaged public var title: String | ||
@NSManaged public var createdAt: Date | ||
@NSManaged public var color: String | ||
@NSManaged public var memo: String? | ||
@NSManaged public var isFavorite: Bool | ||
@NSManaged public var parentFolderID: UUID? | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
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
103 changes: 103 additions & 0 deletions
103
Data/CoreData/Repositories/FolderDataRepositoryImpl.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,103 @@ | ||
// | ||
// FolderDataRepositoryImpl.swift | ||
// Reazy | ||
// | ||
// Created by 유지수 on 11/19/24. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
import SwiftUI | ||
import UIKit | ||
|
||
class FolderDataRepositoryImpl: FolderDataRepository { | ||
private let container: NSPersistentContainer = PersistantContainer.shared.container | ||
|
||
func loadFolders() -> Result<[Folder], any Error> { | ||
let dataContext = container.viewContext | ||
let fetchRequest: NSFetchRequest<FolderData> = FolderData.fetchRequest() | ||
|
||
do { | ||
let fetchedDataList = try dataContext.fetch(fetchRequest) | ||
let folderList = fetchedDataList.map { folderData -> Folder in | ||
|
||
return Folder( | ||
id: folderData.id, | ||
title: folderData.title, | ||
createdAt: folderData.createdAt, | ||
color: folderData.color, | ||
memo: folderData.memo, | ||
isFavorite: folderData.isFavorite, | ||
parentFolderID: folderData.parentFolderID ?? nil | ||
) | ||
} | ||
|
||
return .success(folderList) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
|
||
func saveFolder(_ folder: Folder) -> Result<VoidResponse, any Error> { | ||
let dataContext = container.viewContext | ||
|
||
do { | ||
let folderData = FolderData(context: dataContext) | ||
folderData.id = folder.id | ||
folderData.title = folder.title | ||
folderData.createdAt = folder.createdAt | ||
folderData.color = folder.color | ||
folderData.memo = folder.memo | ||
folderData.isFavorite = folder.isFavorite | ||
folderData.parentFolderID = folder.parentFolderID | ||
|
||
try dataContext.save() | ||
return .success(VoidResponse()) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
|
||
func editFolder(_ folder: Folder) -> Result<VoidResponse, any Error> { | ||
let dataContext = container.viewContext | ||
let fetchRequest: NSFetchRequest<FolderData> = FolderData.fetchRequest() | ||
fetchRequest.predicate = NSPredicate(format: "id == %@", folder.id as CVarArg) | ||
|
||
do { | ||
guard let folderData = try dataContext.fetch(fetchRequest).first else { | ||
return .failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Folder not found"])) | ||
} | ||
|
||
folderData.title = folder.title | ||
folderData.color = folder.color | ||
folderData.memo = folder.memo | ||
folderData.isFavorite = folder.isFavorite | ||
folderData.parentFolderID = folder.parentFolderID | ||
|
||
try dataContext.save() | ||
return .success(VoidResponse()) | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
|
||
func deleteFolder(id: UUID) -> Result<VoidResponse, any Error> { | ||
let dataContext = container.viewContext | ||
let fetchRequest: NSFetchRequest<FolderData> = FolderData.fetchRequest() | ||
fetchRequest.predicate = NSPredicate(format: "id == %@", id as CVarArg) | ||
|
||
do { | ||
let results = try dataContext.fetch(fetchRequest) | ||
if let folderToDelete = results.first { | ||
dataContext.delete(folderToDelete) | ||
|
||
try dataContext.save() | ||
return .success(VoidResponse()) | ||
} else { | ||
return .failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Folder not found"])) | ||
} | ||
} catch { | ||
return .failure(error) | ||
} | ||
} | ||
} |
Oops, something went wrong.