Skip to content

Commit

Permalink
Merge branch 'develop' into feature/audioplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
yuncheol-AHN authored Dec 3, 2024
2 parents a532d6f + cb9aec0 commit 2972f41
Show file tree
Hide file tree
Showing 44 changed files with 1,966 additions and 717 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

private func createInitialViewController() -> UIViewController {
if isUserRegistered() {
return createHomeViewController()
} else {
return createRegisterViewController()
}
isUserRegistered()
? createHomeViewController()
: createRegisterViewController()
}

private func isUserRegistered() -> Bool {
return UserDefaults.standard.object(forKey: Constant.houseNameUserDefaultKey) != nil
UserDefaults.standard.object(forKey: Constant.houseNameUserDefaultKey) != nil
}

private func createHomeViewController() -> UIViewController {
Expand Down Expand Up @@ -205,6 +203,10 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
FetchAllBookCoverUseCase.self,
object: DefaultFetchAllBookCoverUseCase(repository: bookCoverRepository)
)
DIContainer.shared.register(
FetchBookCoverUseCase.self,
object: DefaultFetchBookCoverUseCase(repository: bookCoverRepository)
)
DIContainer.shared.register(
UpdateBookCoverUseCase.self,
object: DefaultUpdateBookCoverUseCase(repository: bookCoverRepository)
Expand Down Expand Up @@ -271,19 +273,39 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
)
)

// MARK: - Create BookCover ViewModel
let createBookCoverUseCase = try DIContainer.shared.resolve(CreateBookCoverUseCase.self)
let createBookUseCase = try DIContainer.shared.resolve(CreateBookUseCase.self)
let deleteBookUseCase = try DIContainer.shared.resolve(DeleteBookUseCase.self)
DIContainer.shared.register(
CreateBookCoverViewModelFactory.self,
object: CreateBookCoverViewModelFactory(
fetchMemorialHouseNameUseCase: fetchMemorialHouseNameUseCase,
createBookCoverUseCase: createBookCoverUseCase,
deleteBookCoverUseCase: deleteBookCoverUseCase,
createBookUseCase: createBookUseCase,
deleteBookUseCase: deleteBookUseCase
)
)

// MARK: - Modify BookCover ViewModel
let fetchBookCoverUseCase = try DIContainer.shared.resolve(FetchBookCoverUseCase.self)
DIContainer.shared.register(
ModifyBookCoverViewModelFactory.self,
object: ModifyBookCoverViewModelFactory(
fetchMemorialHouseNameUseCase: fetchMemorialHouseNameUseCase,
fetchBookCoverUseCase: fetchBookCoverUseCase,
updateBookCoverUseCase: updateBookCoverUseCase
)
)

// MARK: - Book ViewModel
let fetchBookUseCase = try DIContainer.shared.resolve(FetchBookUseCase.self)
DIContainer.shared.register(
BookViewModelFactory.self,
object: BookViewModelFactory(fetchBookUseCase: fetchBookUseCase)
)

// MARK: - Page ViewModel
DIContainer.shared.register(
ReadPageViewModelFactory.self,
object: ReadPageViewModelFactory()
)

// MARK: - EditBook ViewModel
let updateBookUseCase = try DIContainer.shared.resolve(UpdateBookUseCase.self)
let storeMediaUseCase = try DIContainer.shared.resolve(PersistentlyStoreMediaUseCase.self)
Expand All @@ -301,5 +323,11 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
deleteMediaUseCase: deleteMediaUseCase
)
)

// MARK: - Page ViewModel
DIContainer.shared.register(
ReadPageViewModelFactory.self,
object: ReadPageViewModelFactory(fetchMediaUseCase: fetchMediaUseCase)
)
}
}
8 changes: 4 additions & 4 deletions MemorialHouse/MHData/MHData/DTO/BookCoverDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public struct BookCoverDTO {
let id: UUID
let order: Int
let title: String
let imageURL: String?
let imageData: Data?
let color: String
let category: String?
let favorite: Bool
Expand All @@ -14,15 +14,15 @@ public struct BookCoverDTO {
id: UUID,
order: Int,
title: String,
imageURL: String?,
imageData: Data?,
color: String,
category: String?,
favorite: Bool
) {
self.id = id
self.order = order
self.title = title
self.imageURL = imageURL
self.imageData = imageData
self.color = color
self.category = category
self.favorite = favorite
Expand All @@ -35,7 +35,7 @@ public struct BookCoverDTO {
id: self.id,
order: self.order,
title: self.title,
imageURL: self.imageURL,
imageData: self.imageData,
color: color,
category: self.category,
favorite: self.favorite
Expand Down
5 changes: 4 additions & 1 deletion MemorialHouse/MHData/MHData/DTO/MediaDescriptionDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public struct MediaDescriptionDTO {

func convertToMediaDescription() -> MediaDescription? {
guard let type = MediaType(rawValue: self.type) else { return nil }
let attributes = try? JSONSerialization.jsonObject(with: attributes ?? Data(), options: []) as? [String: any Sendable]
let attributes = try? JSONSerialization.jsonObject(
with: attributes ?? Data(),
options: []
) as? [String: any Sendable]

return MediaDescription(
id: self.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension CoreDataBookCoverStorage: BookCoverStorage {
bookCover.setValue(data.title, forKey: "title")
bookCover.setValue(data.category, forKey: "category")
bookCover.setValue(data.color, forKey: "color")
bookCover.setValue(data.imageURL, forKey: "imageURL")
bookCover.setValue(data.imageData, forKey: "imageData")
bookCover.setValue(data.favorite, forKey: "favorite")

try context.save()
Expand All @@ -45,7 +45,7 @@ extension CoreDataBookCoverStorage: BookCoverStorage {
newEntity.setValue(data.title, forKey: "title")
newEntity.setValue(data.category, forKey: "category")
newEntity.setValue(data.color, forKey: "color")
newEntity.setValue(data.imageURL, forKey: "imageURL")
newEntity.setValue(data.imageData, forKey: "imageData")
newEntity.setValue(data.favorite, forKey: "favorite")

try context.save()
Expand Down Expand Up @@ -83,7 +83,7 @@ extension CoreDataBookCoverStorage {
id: id,
order: Int(bookCover.order),
title: title,
imageURL: bookCover.imageURL,
imageData: bookCover.imageData,
color: color,
category: bookCover.category,
favorite: bookCover.favorite
Expand Down
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="24B2091" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24A348" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="BookCategoryEntity" representedClassName="BookCategoryEntity" syncable="YES" codeGenerationType="class">
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="order" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
Expand All @@ -9,7 +9,7 @@
<attribute name="color" optional="YES" attributeType="String" customClassName="BookColor"/>
<attribute name="favorite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="imageURL" optional="YES" attributeType="String"/>
<attribute name="imageData" optional="YES" attributeType="Binary"/>
<attribute name="order" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="title" optional="YES" attributeType="String"/>
</entity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileCreationFailure)
}
}

public func read(at path: String, fileName name: String) async -> Result<Data, MHDataError> {
guard let directory = fileManager.urls(
for: directoryType,
Expand All @@ -47,6 +48,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileReadingFailure)
}
}

public func delete(at path: String, fileName name: String) async -> Result<Void, MHDataError> {
guard let directory = fileManager.urls(
for: directoryType,
Expand All @@ -63,6 +65,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileDeletionFailure)
}
}

public func copy(at url: URL, to newPath: String, newFileName name: String) async -> Result<Void, MHDataError> {
let originDataPath = url

Expand All @@ -86,6 +89,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileMovingFailure)
}
}

public func copy(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
Expand Down Expand Up @@ -115,6 +119,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileMovingFailure)
}
}

public func move(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
Expand Down Expand Up @@ -144,6 +149,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileMovingFailure)
}
}

public func moveAll(in path: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
Expand Down Expand Up @@ -174,6 +180,7 @@ extension MHFileManager: FileStorage {
return .failure(.fileMovingFailure)
}
}

public func getURL(at path: String, fileName name: String) async -> Result<URL, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
Expand All @@ -185,6 +192,7 @@ extension MHFileManager: FileStorage {

return .success(originDataPath)
}

public func getFileNames(at path: String) async -> Result<[String], MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
Expand All @@ -200,4 +208,3 @@ extension MHFileManager: FileStorage {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct LocalBookCoverRepository: BookCoverRepository {
id: bookCover.id,
order: bookCover.order,
title: bookCover.title,
imageURL: bookCover.imageURL,
imageData: bookCover.imageData,
color: bookCover.color.rawValue,
category: bookCover.category,
favorite: bookCover.favorite
Expand Down Expand Up @@ -52,7 +52,7 @@ public struct LocalBookCoverRepository: BookCoverRepository {
id: bookCover.id,
order: bookCover.order,
title: bookCover.title,
imageURL: bookCover.imageURL,
imageData: bookCover.imageData,
color: bookCover.color.rawValue,
category: bookCover.category,
favorite: bookCover.favorite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public struct LocalBookRepository: BookRepository {
return await storage.delete(with: id)
}

// MARK: - Mapping
private func mappingBookToDTO(_ book: Book) -> BookDTO {
let pages = book.pages.map { mappingPageToDTO($0) }
return BookDTO(
Expand Down
26 changes: 23 additions & 3 deletions MemorialHouse/MHDomain/MHDomain/Entity/BookColor.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
public enum BookColor: String, Sendable {
case beige
case blue
case pink
case green
case blue
case orange
case pink
case beige

public var index: Int {
switch self {
case .pink:
return 0
case .green:
return 1
case .blue:
return 2
case .orange:
return 3
case .beige:
return 4
}
}

public static func indexToColor(index: Int) -> BookColor {
let colors: [BookColor] = [.pink, .green, .blue, .orange, .beige]
return colors[index]
}
}
6 changes: 3 additions & 3 deletions MemorialHouse/MHDomain/MHDomain/Entity/BookCover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public struct BookCover: Identifiable, Equatable, Sendable {
public let id: UUID
public let order: Int
public let title: String
public let imageURL: String?
public let imageData: Data?
public let color: BookColor
public let category: String?
public let favorite: Bool
Expand All @@ -13,15 +13,15 @@ public struct BookCover: Identifiable, Equatable, Sendable {
id: UUID = .init(),
order: Int,
title: String,
imageURL: String?,
imageData: Data?,
color: BookColor,
category: String?,
favorite: Bool = false
) {
self.id = id
self.order = order
self.title = title
self.imageURL = imageURL
self.imageData = imageData
self.color = color
self.category = category
self.favorite = favorite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct MediaDescription: Identifiable, Sendable {
public let attributes: [String: any Sendable]?

public init(
id: UUID,
id: UUID = .init(),
type: MediaType,
attributes: [String: any Sendable]? = nil
) {
Expand Down
4 changes: 2 additions & 2 deletions MemorialHouse/MHDomain/MHDomain/Entity/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public struct Page: Identifiable, Sendable {

public init(
id: UUID = .init(),
metadata: [Int: MediaDescription],
text: String
metadata: [Int: MediaDescription] = [:],
text: String = ""
) {
self.id = id
self.metadata = metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MHFoundation
import MHCore
import Photos

public protocol MediaRepository: Sendable {
func create(media mediaDescription: MediaDescription, data: Data, to bookID: UUID?) async -> Result<Void, MHDataError>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct DefaultFetchMemorialHouseNameUseCase: FetchMemorialHouseNameUseCas
switch fetchMemorialHouseResult {
case .success(let memorialHouseName):
let transformedName = transformHouseName(with: memorialHouseName)
MHLogger.info("Memorial house fetched: \(transformedName)")
MHLogger.info("저장된 기록소 이름: \(transformedName)")

return transformedName
case .failure(let failure):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public enum Constant {
public static let houseNameUserDefaultKey = "houseName"
public static let navigationBarHeight: CGFloat = 60
public static let photoCaption: String = "photoCaption"
public static let photoCreationDate: String = "photoCreationDate"
}
Loading

0 comments on commit 2972f41

Please sign in to comment.