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

BookCover 엔티티 & MHBook 뷰 구현 #47

Merged
merged 13 commits into from
Nov 12, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
: HomeViewController()

let navigationController = UINavigationController(rootViewController: initialViewController)
navigationController.navigationBar.isHidden = true
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
Expand Down
24 changes: 24 additions & 0 deletions MemorialHouse/MHDomain/MHDomain/Entity/BookCover.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TODO: 지금 피그잼의 BookCover에서 세분화할 필요성이 느껴짐 (MHBook은 딱 아래 정도만 필요한듯)

Check warning on line 1 in MemorialHouse/MHDomain/MHDomain/Entity/BookCover.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (지금 피그잼의 BookCover에서 세분화할 필요성이 ...) (todo)

Check warning on line 1 in MemorialHouse/MHDomain/MHDomain/Entity/BookCover.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (지금 피그잼의 BookCover에서 세분화할 필요성이 ...) (todo)
public enum BookType {
case beige
case blue
case green
case orange
case pink
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

P2: BookType도 하나의 type이니까 BookCover랑 분리해서 따로 파일을 만들어주는게 좋을 것 같습니당 .ᐟ.ᐟ 엇 그리고 BookType이 아니라 BookColor였던 것 같아요 .ᐟ.ᐟ

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

UIImage에 대한 건데 Color라는 이름을 쓰기가 애매했습니다..!
아래처럼 사용돼도 괜찮나요 ? (개인적) 전 Type이 나을 거 같은데 어떠신가용

extension BookColor {
	var image: UIImage {
		return .pinkColor
	}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

BookColor가 저희의 비즈니스 모델이니까 괜찮지 않을까요?? 전 개인적으로 괜찮아보이긴합니다 .ᐟ.ᐟ

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 struct BookCover {
public let title: String
public let imageURL: String
public let bookType: BookType

public init(
title: String,
imageURL: String,
bookType: BookType
) {
self.title = title
self.imageURL = imageURL
self.bookType = bookType
}
}
8 changes: 0 additions & 8 deletions MemorialHouse/MHDomain/MHDomain/Temp.swift

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class BookCreationViewController: UIViewController {
attributedTitle.font = UIFont.ownglyphBerry(size: 25)

button.setAttributedTitle(NSAttributedString(attributedTitle), for: .normal)
button.setTitleColor(.title, for: .normal)
button.setTitleColor(.mhTitle, for: .normal)
button.contentHorizontalAlignment = .left

return button
Expand All @@ -55,7 +55,7 @@ final class BookCreationViewController: UIViewController {
attributedTitle.font = UIFont.ownglyphBerry(size: 25)

button.setAttributedTitle(NSAttributedString(attributedTitle), for: .normal)
button.setTitleColor(.title, for: .normal)
button.setTitleColor(.mhTitle, for: .normal)

return button
}()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import UIKit
import MHFoundation
import MHDomain

// TODO: 위치 변경 고려해보기

Check warning on line 5 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (위치 변경 고려해보기) (todo)

Check warning on line 5 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (위치 변경 고려해보기) (todo)
extension BookType {
var image: UIImage {
switch self {
case .blue: .blueBook
case .beige: .beigeBook
case .green: .greenBook
case .orange: .orangeBook
case .pink: .pinkBook
@unknown default:
fatalError("등록되지 않은 책 색상입니다.")
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Domain에 있는 모델이지만 Presentation에서 위처럼 연산 프로퍼티 접근이 가능하면 용이할 것 같아 추가해봤습니다
괜찮다면..? 해당 코드가 어디 위치에 있는게 좋을까요

Copy link
Collaborator Author

@Kyxxn Kyxxn Nov 11, 2024

Choose a reason for hiding this comment

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

[추가] 아래 코드는 필수로 구현해줘야 했습니다!
책이 안 보이면 강제종료 되는게 맞다 판단하여 fatalError 그대로 냅뒀는데 다른 아이디어 있으신 분 있으면 알려주세욥

컴파일러가 띄워준 에러에 자동완성 Fix가 @.unkown default였는데
그냥 늘 쓰던 default였군요, 수정했습니당

Copy link
Collaborator

Choose a reason for hiding this comment

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

P3.enum인데 default가 수행되나욤?

  • 저는 처음에 ViewModel에서 대응할까 했는데, 모듈로 분리되어있으니까 Presentation에서 extension을 만들어도 될것같긴합니다.!

Copy link
Collaborator

Choose a reason for hiding this comment

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

�엇 저는 BookColor의 extension으로 구현하기보단 viewModel에서 대응하는게 더 좋아보입니당..! 그럼 default를 따로 만들지 않아도 될 것 같아요 ..

Copy link
Collaborator Author

@Kyxxn Kyxxn Nov 12, 2024

Choose a reason for hiding this comment

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

제 생각에도 default 수행 안될 거 같은데,
다른 모듈에 있는 걸 extension으로 열어서 그런지 @unknown default를 해주지 않으면 에러가 발생했습니다 !

다른 모듈에서 접근 제어자 때문에 해당 extension 못 사용하므로
Domain에 있는 엔티티의 확장을 해도 된다고 판단했습니다..!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@frozen을 사용해 타입을 고정시켜도 @unknown default를 작성해야하는 문제가 발생할까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

컴파일러가 띄워준 에러에 자동완성 Fix가 @.unkown default였는데
그냥 늘 쓰던 default였군요, 제거하고 default로 수정했습니다 !!


final class MHBook: UIView {
// MARK: - Property
private let bookImageView = UIImageView()
private let titleLabel = UILabel(style: .default)
private let targetImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleToFill
imageView.layer.shadowRadius = 4
imageView.layer.shadowOpacity = 0.4
imageView.layer.shadowOffset = CGSize(width: 4, height: 4)

return imageView
}()
private let publisherLabel = UILabel(style: .body2)

// MARK: - Initializer
init() {
super.init(frame: .zero)

configureAddSubView()
configureConstraints()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

configureAddSubView()
configureConstraints()
}

// MARK: - Configuration
func configure(with bookCover: BookCover) {
titleLabel.text = bookCover.title
bookImageView.image = bookCover.bookType.image
Copy link
Collaborator

Choose a reason for hiding this comment

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

저는 여기서 case별로 나눠서 image를 적용해줘도 된다.. 생각합니당.. 뭔가 model의 extension에 computed property가 들어가는게 어색..한 것 같다..? 는 의견입니당..

targetImageView.image = UIImage(systemName: "person") // TODO: Image Loader로 변경

Check warning on line 54 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Image Loader로 변경) (todo)

Check warning on line 54 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Image Loader로 변경) (todo)
if let publisher = UserDefaults.standard.object(forKey: Constant.houseNameUserDefaultKey) as? String {
// TODO: User 모델 만들어지면 파라미터로 출판소 이름 넘겨주기

Check warning on line 56 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (User 모델 만들어지면 파라미터로 출판소 이름 넘겨주...) (todo)

Check warning on line 56 in MemorialHouse/MHPresentation/MHPresentation/Source/Design/MHBook.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (User 모델 만들어지면 파라미터로 출판소 이름 넘겨주...) (todo)
publisherLabel.text = publisher
}
}

private func configureAddSubView() {
addSubview(bookImageView)
addSubview(titleLabel)
addSubview(targetImageView)
addSubview(publisherLabel)
}

private func configureConstraints() {
bookImageView.fillSuperview()
titleLabel.setTop(anchor: topAnchor, constant: 16)
titleLabel.setCenterX(view: self, constant: 8)
targetImageView.setTop(anchor: titleLabel.bottomAnchor, constant: 14)
targetImageView.setCenterX(view: self, constant: 8)
targetImageView.setWidthAndHeight(width: 100, height: 100)
publisherLabel.setBottom(anchor: bottomAnchor, constant: 12)
publisherLabel.setTrailing(anchor: trailingAnchor, constant: 12)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ public extension UILabel {
enum Style {
case `default`
case header
case body
case body1
case body2
}

convenience init(style: Style) {
self.init(frame: .zero)
self.textColor = .title
self.textColor = .mhTitle
self.textAlignment = .center
switch style {
case .default:
self.font = UIFont.ownglyphBerry(size: 25)
case .header:
self.font = UIFont.ownglyphBerry(size: 30)
case .body:
case .body1:
self.font = UIFont.ownglyphBerry(size: 17)
case .body2:
self.font = UIFont.ownglyphBerry(size: 12)
}
}
}
Loading