Skip to content

Commit

Permalink
Merge pull request #326 from DeveloperAcademy-POSTECH/main
Browse files Browse the repository at this point in the history
[Release] main -> release
  • Loading branch information
minjung0067 authored Nov 27, 2024
2 parents 733f5cc + 42fe355 commit 2a8e0e9
Show file tree
Hide file tree
Showing 268 changed files with 11,821 additions and 4,319 deletions.
14 changes: 14 additions & 0 deletions Data/CoreData/DTO/FolderData+CoreDataClass.swift
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 {

}
25 changes: 25 additions & 0 deletions Data/CoreData/DTO/FolderData+CoreDataProperties.swift
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?
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ extension PaperData {
@NSManaged public var title: String
@NSManaged public var thumbnail: Data
@NSManaged public var url: Data
@NSManaged public var focusURL: Data?
@NSManaged public var lastModifiedDate: Date
@NSManaged public var isFavorite: Bool
@NSManaged public var memo: String?
@NSManaged public var isFigureSaved: Bool

@NSManaged public var folderID: UUID?

@NSManaged public var figureData: Set<FigureData>?
@NSManaged public var commentData: Set<CommentData>?
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B83" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B91" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="ButtonGroupData" representedClassName="ButtonGroupData" syncable="YES">
<attribute name="buttonPosition" optional="YES" attributeType="Binary" valueTransformerName="CGRectValueTransformer"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
Expand All @@ -26,7 +26,18 @@
<attribute name="label" optional="YES" attributeType="String"/>
<relationship name="paperData" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PaperData" inverseName="figureData" inverseEntity="PaperData"/>
</entity>
<entity name="FolderData" representedClassName="FolderData" syncable="YES">
<attribute name="color" optional="YES" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="isFavorite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="memo" optional="YES" attributeType="String"/>
<attribute name="parentFolderID" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="title" optional="YES" attributeType="String"/>
</entity>
<entity name="PaperData" representedClassName="PaperData" syncable="YES">
<attribute name="focusURL" optional="YES" attributeType="Binary"/>
<attribute name="folderID" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="isFavorite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isFigureSaved" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ButtonGroupDataService.swift
// ButtonGroupDataRepositoryImpl.swift
// Reazy
//
// Created by 유지수 on 11/11/24.
Expand All @@ -9,13 +9,9 @@ import Foundation
import CoreData
import UIKit

class ButtonGroupDataService: ButtonGroupDataInterface {
static let shared = ButtonGroupDataService()

class ButtonGroupDataRepositoryImpl: ButtonGroupDataRepository {
private let container: NSPersistentContainer = PersistantContainer.shared.container

private init() { }

func loadButtonGroup(for pdfID: UUID) -> Result<[ButtonGroup], any Error> {
let dataContext = container.viewContext
let fetchRequest: NSFetchRequest<ButtonGroupData> = ButtonGroupData.fetchRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CommentDataService.swift
// CommentDataRepositoryImpl.swift
// Reazy
//
// Created by 유지수 on 11/11/24.
Expand All @@ -9,13 +9,9 @@ import Foundation
import CoreData
import UIKit

class CommentDataService: CommentDataInterface {
static let shared = CommentDataService()

class CommentDataRepositoryImpl: CommentDataRepository {
private let container: NSPersistentContainer = PersistantContainer.shared.container

private init() { }

func loadCommentData(for pdfID: UUID) -> Result<[Comment], Error> {
let dataContext = container.viewContext
let fetchRequest: NSFetchRequest<CommentData> = CommentData.fetchRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FigureDataService.swift
// FigureDataRepositoryImpl.swift
// Reazy
//
// Created by 유지수 on 11/10/24.
Expand All @@ -9,13 +9,9 @@ import Foundation
import CoreData
import UIKit

class FigureDataService: FigureDataInterface {
static let shared = FigureDataService()

class FigureDataRepositoryImpl: FigureDataRepository {
private let container: NSPersistentContainer = PersistantContainer.shared.container

private init() { }

func loadFigureData(for pdfID: UUID) -> Result<[Figure], any Error> {
let dataContext = container.viewContext
let fetchRequest: NSFetchRequest<FigureData> = FigureData.fetchRequest()
Expand Down Expand Up @@ -131,4 +127,30 @@ class FigureDataService: FigureDataInterface {
return .failure(error)
}
}

func editPaperInfo(info: PaperInfo) -> Result<VoidResponse, any Error> {
let dataContext = container.viewContext
let fetchRequest: NSFetchRequest<PaperData> = PaperData.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "id == %@", info.id as CVarArg)

do {
let results = try dataContext.fetch(fetchRequest)
if let dataToEdit = results.first {
// 기존 데이터 수정
dataToEdit.title = info.title
dataToEdit.url = info.url
dataToEdit.lastModifiedDate = info.lastModifiedDate
dataToEdit.isFavorite = info.isFavorite
dataToEdit.memo = info.memo
dataToEdit.isFigureSaved = info.isFigureSaved

try dataContext.save()
return .success(VoidResponse())
} else {
return .failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Data not found"]))
}
} catch {
return .failure(error)
}
}
}
103 changes: 103 additions & 0 deletions Data/CoreData/Repositories/FolderDataRepositoryImpl.swift
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)
}
}
}
Loading

0 comments on commit 2a8e0e9

Please sign in to comment.