Skip to content

Commit

Permalink
[iOS/#130] 카테고리 추가 및 수정 기능 구현 (#187)
Browse files Browse the repository at this point in the history
* refactor: Category Repository 함수들의 인자 변경

- Category 타입 인스턴스 전체가 아닌 필요한 내용만 받기로 변경

* feat: Category 타입 변경

- 순수 id가 필요, 따라서 Identifiable이 아닌 id 사용

* refactor: CategoryUseCase 함수 인자 변경

- 레포지토리와 마찬가지로 필요한 값만 받도록 변경, Category 타입에 대한 의존성을 없앰

* refactor: TimeInterval 대신 Int 사용

* refactor: CategorySettingItem을 Category 타입을 받아서 생성

* feat: CategoryViewModel 생성

* feat: 타이머 뷰 컨트롤러와 카테고리 관리 뷰 연결

* feat: 카테고리 추가 버튼 탭 시 하단 시트 present 구현

* refactor: 카테고리 생성 후 생성된 카테고리 ID 반환하도록 수정

* feat: 카테고리 읽어오기 기능 추가

* feat: 새로운 카테고리 추가 기능 구현

feat: 새로운 카테고리 추가 기능 구현

* feat: categoryTitleTextVie의 텍스트 변경할 수 있는 함수 추가

* feat: 카테고리 생성 / 추가를 구분하는 enum 작성

* feat: 카테고리 수정 기능 구현
  • Loading branch information
ericKwon95 authored Nov 23, 2023
1 parent 22cee70 commit 442013c
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,37 @@ final class DefaultCategoryRepository: CategoryRepository {
self.provider = provider
}

func createCategory(_ newCategory: Category) async throws {
func createCategory(name: String, colorCode: String) async throws -> Int {
let categoryDTO = CategoryRequestDTO(
name: newCategory.subject,
colorCode: newCategory.color)
name: name,
colorCode: colorCode)
let endpoint = CategoryEndpoints.createCategory(categoryDTO)
let createdCategory = try await provider.request(with: endpoint)
FMLogger.general.log("카테고리 생성 완료 : \(String(describing: createdCategory))")
FMLogger.general.log("카테고리 생성 완료")
return createdCategory.categoryID
}

func readCategories() async throws -> [Category] {
let endpoint = CategoryEndpoints.fetchCategories()
let categories = try await provider.request(with: endpoint)
FMLogger.general.log("카테고리 읽기 완료")
return categories.map { dto in
Category(id: dto.categoryID, color: dto.colorCode, subject: dto.name, studyTime: 0)
}
}

func updateCategory(id: Int, to newCategory: Category) async throws {
func updateCategory(id: Int, newName: String, newColorCode: String) async throws {
let categoryDTO = CategoryRequestDTO(
name: newCategory.subject,
colorCode: newCategory.color)
name: newName,
colorCode: newColorCode)
let endpoint = CategoryEndpoints.updateCategory(id: id, category: categoryDTO)
let updatedCategory = try await provider.request(with: endpoint)
FMLogger.general.log("카테고리 업데이트 완료 : \(String(describing: updatedCategory))")
FMLogger.general.log("카테고리 업데이트 완료")
}

func deleteCategory(id: Int) async throws {
let endpoint = CategoryEndpoints.deleteCategory(id: id)
let status = try await provider.request(with: endpoint)
FMLogger.general.log("카테고리 삭제 완료 : \(String(describing: status))")
FMLogger.general.log("카테고리 삭제 완료")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import Foundation

protocol CategoryRepository {
func createCategory(_ newCategory: Category) async throws
func createCategory(name: String, colorCode: String) async throws -> Int
func readCategories() async throws -> [Category]
func updateCategory(id: Int, to newCategory: Category) async throws
func updateCategory(id: Int, newName: String, newColorCode: String) async throws
func deleteCategory(id: Int) async throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ class DefaultCategoryUseCase: CategoryUseCase {
self.repository = repository
}

func createCategory(with category: Category) async throws {
try await repository.createCategory(category)
func createCategory(name: String, colorCode: String) async throws -> Int {
try await repository.createCategory(name: name, colorCode: colorCode)
}

func updateCategory(of id: Int, to category: Category) async throws {
try await repository.updateCategory(id: id, to: category)
func readCategory() async throws -> [Category] {
return try await repository.readCategories()
}

func updateCategory(of id: Int, newName: String, newColorCode: String) async throws {
try await repository.updateCategory(id: id, newName: newName, newColorCode: newColorCode)
}

func deleteCategory(of id: Int) async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation

protocol CategoryUseCase {
func createCategory(with category: Category) async throws
func updateCategory(of id: Int, to category: Category) async throws
func createCategory(name: String, colorCode: String) async throws -> Int
func readCategory() async throws -> [Category]
func updateCategory(of id: Int, newName: String, newColorCode: String) async throws
func deleteCategory(of id: Int) async throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ private extension CategoryListCollectionViewCell {
#Preview {
CategoryListCollectionViewCell()
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import Combine

final class CategorySettingFooterView: UICollectionReusableView {
// MARK: - Constant
Expand All @@ -28,15 +29,30 @@ final class CategorySettingFooterView: UICollectionReusableView {
return button
}()

private lazy var tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(footerViewSelected))
private var subject = PassthroughSubject<Void, Never>()
var cancellable: AnyCancellable?

// MARK: - init
override init(frame: CGRect) {
super.init(frame: frame)
configureUI()
configureGestureRecognizers()
}

required init?(coder: NSCoder) {
fatalError("Don't use storyboard")
}

override func prepareForReuse() {
super.prepareForReuse()
cancellable?.cancel()
}

func tapPublisher() -> AnyPublisher<Void, Never> {
return subject
.eraseToAnyPublisher()
}
}

// MARK: - UI Setting
Expand All @@ -52,3 +68,16 @@ private extension CategorySettingFooterView {
])
}
}

private extension CategorySettingFooterView {
func configureGestureRecognizers() {
print("tapgesture added")
tapGestureRecognizer.cancelsTouchesInView = false
self.addGestureRecognizer(tapGestureRecognizer)
}

@objc
func footerViewSelected() {
subject.send()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ private extension CategoryTitleTextView {
textView.text = ""
textView.textColor = .label
}

}

extension CategoryTitleTextView {
func text() -> String? {
guard !isShowPlaceholder else { return nil }
return textView.text
}

func setText(text: String) {
textView.text = text
}
}

@available(iOS 17.0, *)
#Preview {
CategoryTitleTextView(placeholder: "HELLO")
Expand Down
Loading

0 comments on commit 442013c

Please sign in to comment.