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

책 수정 화면 로직 구현 #113

Merged
merged 69 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d57ec45
Merge branch 'develop' into feature/edit-book-logic
iceHood Nov 25, 2024
071f402
feat: MediaAttachment 구현
iceHood Nov 25, 2024
3a59a31
feat: View의 Snapshot편의용 함수 구현
iceHood Nov 25, 2024
b6e6d83
feat: EditPageCell에 TextView관련 구현 추가
iceHood Nov 25, 2024
977d300
feat: Page로직 구현을 위한 엔티티 추가
iceHood Nov 25, 2024
0e5cae0
Merge branch 'develop' into feature/edit-book-logic
iceHood Nov 26, 2024
c9a5465
Merge branch 'develop' into feature/edit-book-logic
iceHood Nov 27, 2024
b86d39d
feat: media 타입 설정
iceHood Nov 28, 2024
24fc2dd
feat: book usecase 생성
iceHood Nov 28, 2024
9d8fb5f
feat: media usecase 생성
iceHood Nov 28, 2024
c6571b9
feat: bookViewModel Usecase와 연결
iceHood Nov 28, 2024
6627556
feat: Media 보여주기 진행...
iceHood Nov 28, 2024
08e4eea
feat: sceneDelegate에서 의존성 주입
iceHood Nov 29, 2024
5637107
refactor: Public및 Sendable하게 설정
iceHood Nov 29, 2024
1478723
feat: EditBookViewModel 이 PageVIewModel관리
iceHood Nov 29, 2024
d9407a2
feat: PageViewModel 생성
iceHood Nov 29, 2024
218cba7
feat: EditBookViewModelFactory 구현
iceHood Nov 29, 2024
e3c1865
feat: EditBook과 ViewModel 연결 조정
iceHood Nov 29, 2024
a50363d
feat: Cell과 ViewModel연결, ContentView기준 뷰 추가
iceHood Nov 29, 2024
533a457
feat: PolaroidView가 받은 데이터를 처리하도록 설정
iceHood Nov 29, 2024
b13a005
refactor: MediaAttachment 수정
iceHood Nov 29, 2024
84c8220
refactor: default attribute 정의
iceHood Nov 29, 2024
40438b5
chore: 주석 제거
iceHood Nov 29, 2024
0aa8f67
refactor: TODO작성, 함수 위치 조정
iceHood Nov 30, 2024
230d7bc
refactor: 이름 수정
iceHood Nov 30, 2024
1ff40f2
refactor: 필요없는 함수 수정
iceHood Nov 30, 2024
3d43247
Merge branch 'develop' into feature/edit-book-logic
iceHood Nov 30, 2024
bd0f4b4
Merge branch 'develop' into feature/edit-book-logic
iceHood Nov 30, 2024
667b01c
feat: 에러 유형 추가
iceHood Dec 1, 2024
56ddcf1
feat: Snapshot 기반으로 파일 관리
iceHood Dec 1, 2024
3bb9487
feat: storeMedia로 이름 구체화
iceHood Dec 1, 2024
6f334c5
refactor: 현재페이지 기준으로 처리하도록 설정, 에러 output 추가
iceHood Dec 1, 2024
e98544d
feat: 페이지 추가기능 추가
iceHood Dec 1, 2024
acfa79f
feat: 미디어가 높이 초과시 삭제토록 설정
iceHood Dec 1, 2024
e4f2f0e
feat: 로딩 실패 및 페이지 수정시 메모리 저장 처리
iceHood Dec 1, 2024
2c6e872
Merge branch 'develop' into feature/edit-book-logic
iceHood Dec 1, 2024
2aad98f
refactor: BookID를 ViewModel안으로 넣음
iceHood Dec 1, 2024
d8ae689
refactor: 키보드 내리는 로직 tableView로 넘김
iceHood Dec 1, 2024
2aa3cdc
feat: 없어질 때 구독 취소하도록 설정
iceHood Dec 1, 2024
fefb2e3
feat: Delegate로 현재 선택된 페이지 index 설정
iceHood Dec 1, 2024
73cf917
refactor: combine에서 preconcurrency 제거
iceHood Dec 1, 2024
165df54
chore: indention수정
iceHood Dec 1, 2024
09e3f66
feat: attachment 삭제전에 드래그
iceHood Dec 1, 2024
961e538
chore: indention 설정
iceHood Dec 1, 2024
2bc516a
refactor: reloading 최적화
iceHood Dec 1, 2024
43c4a1a
feat: attachment 전/후에서 입력시 자동 개행
iceHood Dec 1, 2024
7cefd53
Merge branch 'develop' into feature/edit-book-logic
iceHood Dec 1, 2024
878ebf3
refactor: 오류 안나게 수정
iceHood Dec 1, 2024
b63dede
Merge branch 'develop' into feature/edit-book-logic
iceHood Dec 1, 2024
4e6f1e0
feat: BookCreation시 editbook 생성
iceHood Dec 1, 2024
6c475ec
refactor: guard 문 제거
iceHood Dec 2, 2024
47ead38
refactor: fileManager register 위치 조정
iceHood Dec 2, 2024
54358d3
chore: 없어질 로직에 todo 작성
iceHood Dec 2, 2024
340a3cf
refactor: mediaRepository read -> fetch 이름 변경
iceHood Dec 2, 2024
9a136aa
chore: 없어질 로직에 todo 표시
iceHood Dec 2, 2024
d60becb
refactor: BookCreationVC -> CreatBookVC로 이름 변경
iceHood Dec 2, 2024
68a2b0d
refactor: Combine의 @preconcurrency 제거
iceHood Dec 2, 2024
ad14f84
chore: 필요없는 주석 제거
iceHood Dec 2, 2024
d019cfe
chore: 설명용 주석 추가
iceHood Dec 2, 2024
bb0924c
chore: case let 구문 위치 조정
iceHood Dec 2, 2024
3f66fd0
refactor: if문 guard로 수정
iceHood Dec 2, 2024
4159dc3
refactor: 로직 동작은 하게끔 수정
iceHood Dec 2, 2024
7a2a84a
refactor: 함수 위치 직관적이게 수정
iceHood Dec 2, 2024
201c1cf
refactor: MediaAttachment 파일 분리
iceHood Dec 2, 2024
61a2d60
refactor: 로직 잠재적 위험 위치 수정
iceHood Dec 2, 2024
2b6bfb6
feat: 취소시 지우는 기능 추가
iceHood Dec 2, 2024
260a00e
Merge branch 'develop' into feature/edit-book-logic
iceHood Dec 2, 2024
604cbc9
chore: conflict 버그 해결
iceHood Dec 2, 2024
8b263d2
chore: todo 남기기
iceHood Dec 2, 2024
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 @@ -80,11 +80,18 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
MHLogger.error("\(error.localizedDescription)")
}
}

private func registerStorageDepedency() throws {
DIContainer.shared.register(CoreDataStorage.self, object: CoreDataStorage())

let coreDataStorage = try DIContainer.shared.resolve(CoreDataStorage.self)
DIContainer.shared.register(
CoreDataBookCoverStorage.self,
object: CoreDataBookCoverStorage(coreDataStorage: coreDataStorage)
)
DIContainer.shared.register(
CoreDataBookStorage.self,
object: CoreDataBookStorage(coreDataStorage: coreDataStorage)
)
DIContainer.shared.register(
BookCategoryStorage.self,
object: CoreDataBookCategoryStorage(coreDataStorage: coreDataStorage)
Expand All @@ -101,6 +108,10 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
MemorialHouseNameStorage.self,
object: UserDefaultsMemorialHouseNameStorage()
)
DIContainer.shared.register(
MHFileManager.self,
object: MHFileManager(directoryType: .documentDirectory)
)
}

private func registerRepositoryDependency() throws {
Expand All @@ -125,6 +136,11 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
BookRepository.self,
object: LocalBookRepository(storage: bookStorage)
)
let fileManager = try DIContainer.shared.resolve(MHFileManager.self)
DIContainer.shared.register(
MediaRepository.self,
object: LocalMediaRepository(storage: fileManager)
)
}

private func registerUseCaseDependency() throws {
Expand Down Expand Up @@ -160,9 +176,11 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {

// MARK: - Book UseCase
let bookRepository = try DIContainer.shared.resolve(BookRepository.self)
let mediaRepository = try DIContainer.shared.resolve(MediaRepository.self)
DIContainer.shared.register(
CreateBookUseCase.self,
object: DefaultCreateBookUseCase(repository: bookRepository)
object: DefaultCreateBookUseCase(repository: bookRepository,
mediaRepository: mediaRepository)
)
DIContainer.shared.register(
FetchBookUseCase.self,
Expand Down Expand Up @@ -191,6 +209,23 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DeleteBookCoverUseCase.self,
object: DefaultDeleteBookCoverUseCase(repository: bookCoverRepository)
)
// MARK: - EditBook UseCase
DIContainer.shared.register(
PersistentlyStoreMediaUseCase.self,
object: DefaultPersistentlyStoreMediaUseCase(repository: mediaRepository)
)
DIContainer.shared.register(
CreateMediaUseCase.self,
object: DefaultCreateMediaUseCase(repository: mediaRepository)
)
DIContainer.shared.register(
FetchMediaUseCase.self,
object: DefaultFetchMediaUseCase(repository: mediaRepository)
)
DIContainer.shared.register(
DeleteMediaUseCase.self,
object: DefaultDeleteMediaUseCase(repository: mediaRepository)
)
}

private func registerViewModelFactoryDependency() throws {
Expand Down Expand Up @@ -243,5 +278,23 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
ReadPageViewModelFactory.self,
object: ReadPageViewModelFactory()
)

// MARK: - EditBook ViewModel
let updateBookUseCase = try DIContainer.shared.resolve(UpdateBookUseCase.self)
let storeMediaUseCase = try DIContainer.shared.resolve(PersistentlyStoreMediaUseCase.self)
let createMediaUseCase = try DIContainer.shared.resolve(CreateMediaUseCase.self)
let fetchMediaUseCase = try DIContainer.shared.resolve(FetchMediaUseCase.self)
let deleteMediaUseCase = try DIContainer.shared.resolve(DeleteMediaUseCase.self)
DIContainer.shared.register(
EditBookViewModelFactory.self,
object: EditBookViewModelFactory(
fetchBookUseCase: fetchBookUseCase,
updateBookUseCase: updateBookUseCase,
storeMediaUseCase: storeMediaUseCase,
createMediaUseCase: createMediaUseCase,
fetchMediaUseCase: fetchMediaUseCase,
deleteMediaUseCase: deleteMediaUseCase
)
)
}
}
6 changes: 6 additions & 0 deletions MemorialHouse/MHCore/MHCore/MHDataError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum MHDataError: Error, CustomStringConvertible, Equatable {
case fileDeletionFailure
case fileMovingFailure
case fileNotExists
case snapshotEncodingFailure
case snapshotDecodingFailure
case generalFailure
case setUserDefaultFailure

Expand Down Expand Up @@ -48,6 +50,10 @@ public enum MHDataError: Error, CustomStringConvertible, Equatable {
"파일 이동 실패"
case .fileNotExists:
"파일이 존재하지 않습니다"
case .snapshotEncodingFailure:
"Snapshot 인코딩 실패"
case .snapshotDecodingFailure:
"Snapshot 디코딩 실패"
case .generalFailure:
"알 수 없는 에러입니다."
case .setUserDefaultFailure:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import MHFoundation
import MHCore

struct MHFileManager {
private let fileManager = FileManager.default
public struct MHFileManager: Sendable {
private var fileManager: FileManager { FileManager.default }
Copy link
Collaborator

Choose a reason for hiding this comment

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

연산 프로퍼티로 하신 이유가 있나요 ?
연산 프로퍼티는 접근할 때마다 매번 새로 호출되는 걸로 아는데, 이 경우 private let fileManager = FileManager.default가 더 괜찮지 않은지 질문 드립니다 !!

만약 테스트를 할 거면 생성자 시점에서 주입 받아도 괜찮구요

private let directoryType: FileManager.SearchPathDirectory

init(directoryType: FileManager.SearchPathDirectory) {
public init(directoryType: FileManager.SearchPathDirectory) {
self.directoryType = directoryType
}
}

extension MHFileManager: FileStorage {
func create(at path: String, fileName name: String, data: Data) async -> Result<Void, MHDataError> {
public func create(at path: String, fileName name: String, data: Data) async -> Result<Void, MHDataError> {
guard let directory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand All @@ -22,13 +22,13 @@

do {
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
try data.write(to: dataPath)
try data.write(to: dataPath, options: .atomic)
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3: 해당 option은 어떤걸 뜻하는 것인가욥??

Copy link
Collaborator Author

@iceHood iceHood Dec 1, 2024

Choose a reason for hiding this comment

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

저장할 때 임시파일 만들었다가 저장이 완료되면 실제 파일로 바뀌는 옵션입니다!
더 많은 옵션 보기

return .success(())
} catch {
return .failure(.fileCreationFailure)
}
}
func read(at path: String, fileName name: String) async -> Result<Data, MHDataError> {
public func read(at path: String, fileName name: String) async -> Result<Data, MHDataError> {
guard let directory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand All @@ -47,7 +47,7 @@
return .failure(.fileReadingFailure)
}
}
func delete(at path: String, fileName name: String) async -> Result<Void, MHDataError> {
public func delete(at path: String, fileName name: String) async -> Result<Void, MHDataError> {
guard let directory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand All @@ -63,7 +63,7 @@
return .failure(.fileDeletionFailure)
}
}
func copy(at url: URL, to newPath: String, newFileName name: String) async -> Result<Void, MHDataError> {
public func copy(at url: URL, to newPath: String, newFileName name: String) async -> Result<Void, MHDataError> {
let originDataPath = url

guard fileManager.fileExists(atPath: originDataPath.path) else {
Expand All @@ -86,7 +86,7 @@
return .failure(.fileMovingFailure)
}
}
func copy(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
public func copy(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand Down Expand Up @@ -115,7 +115,7 @@
return .failure(.fileMovingFailure)
}
}
func move(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
public func move(at path: String, fileName name: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand Down Expand Up @@ -144,7 +144,7 @@
return .failure(.fileMovingFailure)
}
}
func moveAll(in path: String, to newPath: String) async -> Result<Void, MHDataError> {
public func moveAll(in path: String, to newPath: String) async -> Result<Void, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand Down Expand Up @@ -174,7 +174,7 @@
return .failure(.fileMovingFailure)
}
}
func getURL(at path: String, fileName name: String) async -> Result<URL, MHDataError> {
public func getURL(at path: String, fileName name: String) async -> Result<URL, MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
in: .userDomainMask
Expand All @@ -185,5 +185,19 @@

return .success(originDataPath)
}
public func getFileNames(at path: String) async -> Result<[String], MHDataError> {
guard let originDirectory = fileManager.urls(
for: directoryType,
in: .userDomainMask
).first?.appending(path: path)
Comment on lines +189 to +192
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 메서드는 어떤뜻인지 궁금합니다 ! userDomainMask는 어떤 옵션인지 궁금해요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

urls(for:in:)메스드에서
for:은 저희가 찾고자 하는 디렉토리(폴더)입니다.
in:은 해당 디렉토리를 찾고자 하는 영역입니다.
맥을 기준으로 설명드리면 ~/Document라든지 ~/Downloads 등이 있는데, ~가 in:에 해당하고, Downloads, Document가 for:에 해당합니다., 즉, in은 영역(사용자 영역, 로컬 영역-가끔 "앱을 전체 사용자가 사용할 수 있게 하겠습니까?" 그런것 있죠?, 네트워크 영역-공유 폴더 등)을 나타내고, for:는 실제 디렉토리를 의미합니다.

저희는 ~/Document를 사용한다고 코딩해놓은 것입니다!

문서가 더 잘 설명되어있으니 한번 보셔도 좋을 것같아요!

공식크문서

else { return .failure(.directorySettingFailure) }

do {
let files = try fileManager.contentsOfDirectory(atPath: originDirectory.path)
return .success(files)
} catch {
return .failure(.fileNotExists)
}
}
}

Check warning on line 203 in MemorialHouse/MHData/MHData/LocalStorage/FileManager/MHFileManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)

Check warning on line 203 in MemorialHouse/MHData/MHData/LocalStorage/FileManager/MHFileManager.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
10 changes: 9 additions & 1 deletion MemorialHouse/MHData/MHData/LocalStorage/FileStorage.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MHFoundation
import MHCore

public protocol FileStorage {
public protocol FileStorage: Sendable {
/// 지정된 경로에 파일을 생성합니다.
/// Documents폴더에 파일을 생성합니다.
/// 중간 경로 폴더를 자동으로 생성합니다.
Expand Down Expand Up @@ -69,4 +69,12 @@ public protocol FileStorage {
/// - name: Documents/{path}/{name} 이 파일 URL을 반환합니다. (확장자 명시 필요)
/// - Returns: 파일 URL을 반환합니다.
func getURL(at path: String, fileName name: String) async -> Result<URL, MHDataError>

/// 지정된 경로의 파일 목록을 반환합니다.
/// Documents폴더를 기준으로 파일 이름 목록을 반환합니다.
/// path는 디렉토리여야 합니다.
/// - Parameters:
/// - path: Documents/{path} 이런식으로 들어갑니다
/// - Returns: 파일 이름 목록을 반환합니다
func getFileNames(at path: String) async -> Result<[String], MHDataError>
}
62 changes: 48 additions & 14 deletions MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import MHCore
import AVFoundation

// TODO: nil이라면 바로 error를 return하도록 수정

Check warning on line 7 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (nil이라면 바로 error를 return하도록 수정) (todo)

Check warning on line 7 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (nil이라면 바로 error를 return하도록 수정) (todo)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

나중에 해도 될까요...하하하....ㅠ

Copy link
Collaborator

Choose a reason for hiding this comment

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

당근이져.. 여기서 더 추가되는건...저도 원치 않아요......

public struct LocalMediaRepository: MediaRepository {
public struct LocalMediaRepository: MediaRepository, Sendable {
private let storage: FileStorage
private let temporaryPath = "temp" // TODO: - 지워질 것임!

Check warning on line 10 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (- 지워질 것임!) (todo)

Check warning on line 10 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (- 지워질 것임!) (todo)
private let snapshotFileName = ".snapshot"

public init(storage: FileStorage) {
self.storage = storage
Expand All @@ -18,34 +20,33 @@
to bookID: UUID?
) async -> Result<Void, MHDataError> {
let path = bookID == nil
? "temp"
? temporaryPath
: bookID!.uuidString
let fileName = mediaDescription.id.uuidString
let fileName = fileName(of: mediaDescription)

return await storage.create(at: path, fileName: fileName, data: data)
}

public func create(
media mediaDescription: MediaDescription,
from: URL,
to bookID: UUID?
) async -> Result<Void, MHDataError> {
let path = bookID == nil
? "temp"
? temporaryPath
: bookID!.uuidString
let fileName = mediaDescription.id.uuidString
let fileName = fileName(of: mediaDescription)

return await storage.copy(at: from, to: path, newFileName: fileName)
}

public func read(
public func fetch(
media mediaDescription: MediaDescription,
from bookID: UUID?
) async -> Result<Data, MHDataError> {
let path = bookID == nil
? "temp"
? temporaryPath
: bookID!.uuidString
let fileName = mediaDescription.id.uuidString
let fileName = fileName(of: mediaDescription)

return await storage.read(at: path, fileName: fileName)
}
Expand All @@ -55,9 +56,9 @@
at bookID: UUID?
) async -> Result<Void, MHDataError> {
let path = bookID == nil
? "temp"
? temporaryPath
: bookID!.uuidString
let fileName = mediaDescription.id.uuidString
let fileName = fileName(of: mediaDescription)

return await storage.delete(at: path, fileName: fileName)
}
Expand All @@ -77,16 +78,49 @@
from bookID: UUID?
) async -> Result<URL, MHDataError> {
let path = bookID == nil
? "temp"
? temporaryPath
: bookID!.uuidString
let fileName = mediaDescription.id.uuidString
let fileName = fileName(of: mediaDescription)

return await storage.getURL(at: path, fileName: fileName)
}

public func moveAllTemporaryMedia(to bookID: UUID) async -> Result<Void, MHDataError> {
let path = bookID.uuidString

return await storage.moveAll(in: "temp", to: path)
return await storage.moveAll(in: temporaryPath, to: path)
}

// MARK: - Snpashot
public func createSnapshot(for media: [MediaDescription], in bookID: UUID) async -> Result<Void, MHDataError> {
let path = bookID.uuidString
let mediaList = media.map { fileName(of: $0) }
guard let snapshot = try? JSONEncoder().encode(mediaList)
else { return .failure(.snapshotEncodingFailure) }

return await storage.create(at: path, fileName: snapshotFileName, data: snapshot)
}
Comment on lines +95 to +102
Copy link
Collaborator

Choose a reason for hiding this comment

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

미디어 데이터를 저장하는 코드로 보이는데
<호출 시점>이 궁금합니다 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

편집뷰에서 수정완려/저장 버튼을 눌렀을 때 호출됩니다!

public func deleteMediaBySnapshot(for bookID: UUID) async -> Result<Void, MHDataError> {
let path = bookID.uuidString

do {
let snapshotData = try await storage.read(at: path, fileName: snapshotFileName).get()
let mediaSet = Set<String>(try JSONDecoder().decode([String].self, from: snapshotData))
// snapshot 파일은 제외
let currentFiles = Set<String>(try await storage.getFileNames(at: path).get()).subtracting([snapshotFileName])

Check warning on line 110 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 122 characters (line_length)

Check warning on line 110 in MemorialHouse/MHData/MHData/Repository/LocalMediaRepository.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 122 characters (line_length)
let shouldDelete = currentFiles.subtracting(mediaSet)
for fileName in shouldDelete {
_ = try await storage.delete(at: path, fileName: fileName).get()
}
return .success(())
} catch let error as MHDataError {
return .failure(error)
} catch {
return .failure(.generalFailure)
}
}
// MARK: - Helper
private func fileName(of media: MediaDescription) -> String {
return media.id.uuidString + media.type.defaultFileExtension
}
}
13 changes: 13 additions & 0 deletions MemorialHouse/MHDomain/MHDomain/Entity/MediaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ public enum MediaType: String, Sendable {
case image
case video
case audio

/// 기본 파일 확장자를 반환합니다.
/// 사진은 .png, 비디오는 .mp4, 오디오는 .m4a를 반환합니다.
public var defaultFileExtension: String {
switch self {
case .image:
return ".png"
case .video:
return ".mp4"
case .audio:
return ".m4a"
}
}
}
Loading
Loading