Skip to content

Commit

Permalink
refactor: 카테고리 CUD 유효성 검증 로그 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyxxn committed Dec 4, 2024
1 parent ced2faa commit ace0be2
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ final class BookCategoryViewModel: ViewModelType {

private func createCategory(name: String) async {
guard validateCategoryName(with: name) else {
MHLogger.error("카테고리 이름이 유효하지 않음: \(name)")
output.send(.failure("카테고리 이름이 유효하지 않습니다"))
MHLogger.error("카테고리 생성 유효성 검증 실패: \(name)" + #function)
output.send(.failure("카테고리 생성 유효성 검증 실패"))
return
}

Expand All @@ -80,7 +80,7 @@ final class BookCategoryViewModel: ViewModelType {
categories.append(category)
output.send(.createdCategory)
} catch {
MHLogger.error("카테고리를 생성하는데 실패했습니다: \(error)")
MHLogger.error("카테고리를 생성하는데 실패했습니다: \(error)" + #function)
output.send(.failure("카테고리를 생성하는데 실패했습니다"))
}
}
Expand All @@ -91,16 +91,16 @@ final class BookCategoryViewModel: ViewModelType {
categories.append(contentsOf: fetchedCategories)
output.send(.fetchCategories)
} catch {
MHLogger.error("카테고리를 불러오는데 실패했습니다: \(error)")
MHLogger.error("카테고리를 불러오는데 실패했습니다: \(error)" + #function)
output.send(.failure("카테고리를 불러오는데 실패했습니다"))
}
}

private func updateCategory(index: Int, name: String) async {
guard validateIndex(index),
validateCategoryName(with: name) else {
MHLogger.error("카테고리 업데이트 실패: \(name)")
output.send(.failure("카테고리를 업데이트하는데 실패했습니다"))
MHLogger.error("카테고리 업데이트 유효성 검증 실패: \(name)" + #function)
output.send(.failure("카테고리 업데이트 유효성 검증 실패"))
return
}

Expand All @@ -111,14 +111,14 @@ final class BookCategoryViewModel: ViewModelType {
categories[index] = category
output.send(.updatedCategory)
} catch {
MHLogger.error("카테고리를 업데이트하는데 실패했습니다: \(error)")
MHLogger.error("카테고리를 업데이트하는데 실패했습니다: \(error)" + #function)
output.send(.failure("카테고리를 업데이트하는데 실패했습니다"))
}
}

private func deleteCategory(index: Int) async {
guard validateIndex(index) else {
MHLogger.error("카테고리를 삭제하는데 실패했습니다: \(index)")
MHLogger.error("카테고리 삭제 유효성 검증 실패: \(index)" + #function)
output.send(.failure("카테고리를 삭제하는데 실패했습니다"))
return
}
Expand All @@ -129,7 +129,7 @@ final class BookCategoryViewModel: ViewModelType {
categories.remove(at: index)
output.send(.deletedCategory)
} catch {
MHLogger.error("카테고리를 삭제하는데 실패했습니다: \(error)")
MHLogger.error("카테고리를 삭제하는데 실패했습니다: \(error)" + #function)
output.send(.failure("카테고리를 삭제하는데 실패했습니다"))
}
}
Expand All @@ -144,8 +144,8 @@ final class BookCategoryViewModel: ViewModelType {
// 인덱스 유효성 검사
private func validateIndex(_ index: Int) -> Bool {
guard index >= 0 && index < categories.count else {
MHLogger.error("유효하지 않은 인덱스: \(index)" + #function)
output.send(.failure("유효하지 않은 인덱스: \(index)"))
MHLogger.error("유효하지 않은 인덱스: \(index)")
return false
}
return true
Expand All @@ -154,8 +154,8 @@ final class BookCategoryViewModel: ViewModelType {
// 공백 또는 빈 문자열 검사
private func validateNonEmptyName(_ name: String) -> Bool {
guard !name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
MHLogger.error("카테고리 이름이 비어있거나 공백만 포함되어 있음: \(name)" + #function)
output.send(.failure("카테고리 이름은 공백일 수 없습니다."))
MHLogger.error("카테고리 이름이 비어있거나 공백만 포함되어 있음: \(name)")
return false
}
return true
Expand All @@ -164,8 +164,8 @@ final class BookCategoryViewModel: ViewModelType {
// 중복 이름 검사
private func validateUniqueName(_ name: String) -> Bool {
guard !categories.contains(where: { $0.name == name }) else {
MHLogger.error("중복된 카테고리 이름: \(name)" + #function)
output.send(.failure("이미 존재하는 카테고리: \(name)"))
MHLogger.error("중복된 카테고리 이름: \(name)")
return false
}
return true
Expand All @@ -174,8 +174,8 @@ final class BookCategoryViewModel: ViewModelType {
// 이름 길이 검사
private func validateNameLength(_ name: String) -> Bool {
guard name.count <= 10 else {
MHLogger.error("카테고리 이름이 너무 깁니다: \(name)" + #function)
output.send(.failure("카테고리 이름은 10자 이하여야 합니다."))
MHLogger.error("카테고리 이름이 너무 깁니다: \(name)")
return false
}
return true
Expand Down

0 comments on commit ace0be2

Please sign in to comment.