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

Refactor: code convention 통일 #25

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@
1DF0D1992C7B92C500E2C94C /* DateFormatter+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D1972C7B92C500E2C94C /* DateFormatter+Extensions.swift */; };
1DF0D19B2C7B92D600E2C94C /* UserDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19A2C7B92D600E2C94C /* UserDTO.swift */; };
1DF0D19C2C7B92D600E2C94C /* UserDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19A2C7B92D600E2C94C /* UserDTO.swift */; };
1DF0D19F2C7B92F800E2C94C /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19D2C7B92F800E2C94C /* Comment.swift */; };
1DF0D1A02C7B92F800E2C94C /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19D2C7B92F800E2C94C /* Comment.swift */; };
1DF0D1A12C7B92F800E2C94C /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19E2C7B92F800E2C94C /* User.swift */; };
1DF0D1A22C7B92F800E2C94C /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF0D19E2C7B92F800E2C94C /* User.swift */; };
1DF829B42C2A7A7D00C337FC /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DF829B32C2A7A7D00C337FC /* Fonts.swift */; };
Expand Down Expand Up @@ -196,7 +194,6 @@
1DE19EBE2C1B422F0031804A /* RecipeListCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecipeListCell.swift; sourceTree = "<group>"; };
1DF0D1972C7B92C500E2C94C /* DateFormatter+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extensions.swift"; sourceTree = "<group>"; };
1DF0D19A2C7B92D600E2C94C /* UserDTO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDTO.swift; sourceTree = "<group>"; };
1DF0D19D2C7B92F800E2C94C /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
1DF0D19E2C7B92F800E2C94C /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
1DF829B32C2A7A7D00C337FC /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = "<group>"; };
1DF829B62C2A7CDC00C337FC /* UIImageViewImageLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageViewImageLoading.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -236,7 +233,6 @@
1D12839F2C15E7A700C5A870 /* Entities */ = {
isa = PBXGroup;
children = (
1DF0D19D2C7B92F800E2C94C /* Comment.swift */,
1DF0D19E2C7B92F800E2C94C /* User.swift */,
1D1283A12C15E94300C5A870 /* Recipe.swift */,
1D1283A32C15EA8100C5A870 /* RecipeType.swift */,
Expand Down Expand Up @@ -681,7 +677,6 @@
1D5AEE552C592F2600BBD5F0 /* AddRecipeUseCase.swift in Sources */,
1D1283AC2C15EBE600C5A870 /* FetchFeedListUseCase.swift in Sources */,
1DF0D1A12C7B92F800E2C94C /* User.swift in Sources */,
1DF0D19F2C7B92F800E2C94C /* Comment.swift in Sources */,
1D73687A2C32EB18000EF904 /* RecipeUploadDTO.swift in Sources */,
1D2C6F6A2C26AF9F004BB54E /* AddRecipeView.swift in Sources */,
1D2C6F682C246998004BB54E /* AddRecipeViewController.swift in Sources */,
Expand Down Expand Up @@ -758,7 +753,6 @@
1D5AEF362C64791300BBD5F0 /* RecipePageDTO.swift in Sources */,
1D5AEF322C6478FE00BBD5F0 /* RecipePostService.swift in Sources */,
1D6958DB2C3D5C91008604B3 /* Recipe.swift in Sources */,
1DF0D1A02C7B92F800E2C94C /* Comment.swift in Sources */,
1D6958E02C3D5E3D008604B3 /* RecipeDetailError.swift in Sources */,
1D6958DA2C3D5BA4008604B3 /* FetchRecipeDetailUseCase.swift in Sources */,
1D39729E2C46C57A00495014 /* FetchRecipeDetailUseCaseTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ class RecipeFetchServiceImpl: RecipeFetchService {
}

func fetchRecipes(pageNumber: Int) -> Single<[Recipe]> {
guard let URL = makeURL(endpoint: "recipes", queryItems: [URLQueryItem(name: "pageNumber", value: String(pageNumber))]) else {
return Single.error(NSError(domain: "URLComponentsError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
guard let URL = makeURL(
endpoint: "recipes",
queryItems: [URLQueryItem(
name: "pageNumber",
value: String(pageNumber))
]) else {
return Single.error(NSError(
domain: "URLComponentsError",
code: -1,
userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
}
return networkService.getRequest(url: URL, responseType: NetworkResponseDTO<RecipePageDTO>.self)
.map { $0.data.recipes.map{ $0.toDomain() } }
Expand All @@ -38,12 +46,25 @@ class RecipeFetchServiceImpl: RecipeFetchService {

func searchRecipes(title: String, pageNumber: Int) -> Single<[Recipe]> {
guard let URL = makeURL(endpoint: "recipes", queryItems: [
URLQueryItem(name: "keyword", value: title),
URLQueryItem(name: "pageNumber", value: String(pageNumber))
URLQueryItem(
name: "keyword",
value: title
),
URLQueryItem(
name: "pageNumber",
value: String(pageNumber)
)
]) else {
return Single.error(NSError(domain: "URLComponentsError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
return Single.error(
NSError(
domain: "URLComponentsError",
code: -1,
userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
}
return networkService.getRequest(url: URL, responseType: NetworkResponseDTO<RecipePageDTO>.self)
.map { $0.data.recipes.map{ $0.toDomain() } }
return networkService.getRequest(
url: URL, responseType:
NetworkResponseDTO<RecipePageDTO>.self
)
.map { $0.data.recipes.map{ $0.toDomain() } }
}
}
7 changes: 6 additions & 1 deletion HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/Recipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ extension Recipe {
type: RecipeType = .coffee,
name: String = "",
description: String = "",
writer: User = .init(id: 1, profileImage: "", nickname: "", createdAt: Date()),
writer: User = .init(
id: 1,
profileImage: "",
nickname: "",
createdAt: Date()
),
imageUrls: [String] = [],
isLikedByCurrentUser: Bool = false,
likeCount: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
import UIKit

final class CustomNavigationBar: UIView {

private let titleLabel = UILabel()
let backButton = UIButton(type: .system)


private let titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.font = UIFont.systemFont(ofSize: 18, weight: .bold)
titleLabel.textAlignment = .center
return titleLabel
}()

let backButton: UIButton = {
let backButton = UIButton()
backButton.setImage(UIImage(systemName: "chevron.backward"), for: .normal)
backButton.tintColor = .black
return backButton
}()

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
Expand All @@ -22,22 +33,22 @@ final class CustomNavigationBar: UIView {
}

private func setupUI() {

backButton.setImage(UIImage(systemName: "chevron.backward"), for: .normal)
backButton.tintColor = .black
addsubviews()
setupConstraints()
}

private func addsubviews() {
addSubview(backButton)

titleLabel.font = UIFont.systemFont(ofSize: 18, weight: .bold)
titleLabel.textAlignment = .center
addSubview(titleLabel)

}

private func setupConstraints() {
backButton.translatesAutoresizingMaskIntoConstraints = false
titleLabel.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
backButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
backButton.centerYAnchor.constraint(equalTo: centerYAnchor),

titleLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,15 @@ final class RecipeDetailView: UIView {

private func setupScrollViewContent(with recipeImageUrls: [URL]) {
scrollView.subviews.forEach { $0.removeFromSuperview() }

let imageViewWidth = UIScreen.main.bounds.width

recipeImageUrls.enumerated().forEach { index, url in
let imageView = UIImageView()
imageView.kf.setImage(with: url)
imageView.contentMode = .scaleAspectFill

let xPos = CGFloat(index) * imageViewWidth
imageView.frame = CGRect(x: xPos, y: 0, width: imageViewWidth, height: 200)
scrollView.addSubview(imageView)
}

let contentWidth = imageViewWidth * CGFloat(recipeImageUrls.count)
scrollView.contentSize = CGSize(width: contentWidth, height: 200)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,44 @@ import UIKit

final class RecipeListViewCell: UICollectionViewCell {

private let recipeThumbnailView = UIImageView()
private let titleLabel = UILabel()

private let recipeThumbnailView: UIImageView = {
let recipeThumbnail = UIImageView()
recipeThumbnail.contentMode = .scaleAspectFill
recipeThumbnail.clipsToBounds = true
recipeThumbnail.image = UIImage(named: "EmptyImage")
return recipeThumbnail
}()

private let titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.font = Fonts.titleFont
titleLabel.textAlignment = .center
return titleLabel
}()

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupUI() {
addSubviews()
setupConstraints()
}

private func addSubviews() {
contentView.addSubview(recipeThumbnailView)
contentView.addSubview(titleLabel)

}

private func setupConstraints() {
recipeThumbnailView.translatesAutoresizingMaskIntoConstraints = false
titleLabel.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
recipeThumbnailView.topAnchor.constraint(equalTo: topAnchor),
recipeThumbnailView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
Expand All @@ -40,22 +59,14 @@ final class RecipeListViewCell: UICollectionViewCell {
titleLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -10),
titleLabel.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.15)
])

titleLabel.font = Fonts.titleFont
titleLabel.textAlignment = .center

recipeThumbnailView.contentMode = .scaleAspectFill
recipeThumbnailView.clipsToBounds = true
recipeThumbnailView.image = UIImage(named: "EmptyImage")
}

func configure(with viewModel: RecipeListItemViewModel) {
titleLabel.text = viewModel.name
if let imageUrl = viewModel.imageURL {
recipeThumbnailView.loadImage(from: imageUrl)
} else {
recipeThumbnailView.image = UIImage(named: "EmptyImage")
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ protocol RecipeListViewDelegate: AnyObject {
final class RecipeListView: UIView {

private enum Metric {
static let itemSize: CGSize = .init(width: UIScreen.main.bounds.width - 20, height: 200)
static let itemSize: CGSize = .init(
width: UIScreen.main.bounds.width - 20,
height: 200
)
static let minimumLineSpacing: CGFloat = 10.0
static let minimumInteritemSpacing: CGFloat = 10.0
}
Expand All @@ -28,7 +31,6 @@ final class RecipeListView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
setupLayout()
}

required init?(coder: NSCoder) {
Expand All @@ -38,11 +40,15 @@ final class RecipeListView: UIView {
private func setupUI() {
backgroundColor = .white
addSubview(collectionView)
collectionView.register(RecipeListViewCell.self, forCellWithReuseIdentifier: "RecipeCell")
collectionView.register(
RecipeListViewCell.self,
forCellWithReuseIdentifier: "RecipeCell"
)
configureCollectionView()
setupConstraints()
}

private func setupLayout() {
private func setupConstraints() {
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
Expand Down Expand Up @@ -75,7 +81,10 @@ extension RecipeListView: UICollectionViewDataSource {
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RecipeCell", for: indexPath) as! RecipeListViewCell
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: "RecipeCell",
for: indexPath
) as! RecipeListViewCell
let recipeViewModel = recipes[indexPath.item]
cell.configure(with: recipeViewModel)
return cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class RecipeListViewController: UIViewController {
private let recipeListMapper = RecipeListMapper()
private let router: RecipeListRouter

init(interactor: RecipeListInteractor, router: RecipeListRouter) {
init(
interactor: RecipeListInteractor,
router: RecipeListRouter
) {
self.interactor = interactor
self.router = router
super.init(nibName: nil, bundle: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ final class SearchBar: UIView {
}

private func setupUI() {
addsubviews()
setupConstraints()
}

private func addsubviews() {
addSubview(searchBar)
}

private func setupConstraints() {
searchBar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
searchBar.topAnchor.constraint(equalTo: self.topAnchor),
Expand All @@ -34,7 +42,7 @@ final class SearchBar: UIView {
searchBar.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}

func setDelegate(_ delegate: UISearchBarDelegate) {
searchBar.delegate = delegate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ final class AddRecipeView: UIView {
private func setupCollectionView() {
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(RecipeUploadImgaeCell.self, forCellWithReuseIdentifier: "ImageCell")
collectionView.register(SelectImageCell.self, forCellWithReuseIdentifier: "SelectImageCell")
collectionView.register(
RecipeUploadImgaeCell.self,
forCellWithReuseIdentifier: "ImageCell"
)
collectionView.register(
SelectImageCell.self,
forCellWithReuseIdentifier: "SelectImageCell"
)
}

private func setupCustomNavigationBar() {
Expand Down Expand Up @@ -196,9 +202,11 @@ extension AddRecipeView: UICollectionViewDataSource {
return (delegate?.numberOfImages() ?? 0) + 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelectImageCell", for: indexPath) as! SelectImageCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelectImageCell",
for: indexPath) as! SelectImageCell
cell.selectImageButton.addAction(
UIAction(
handler: { [weak self] _ in
Expand All @@ -209,7 +217,8 @@ extension AddRecipeView: UICollectionViewDataSource {
)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! RecipeUploadImgaeCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell",
for: indexPath) as! RecipeUploadImgaeCell
if let image = delegate?.recipeImage(at: indexPath.item - 1) {
cell.configure(with: image, isRepresentative: indexPath.item == 1)
}
Expand Down
Loading
Loading