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

Feature/favorite/main #52

Merged
merged 7 commits into from
Jul 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ import Domain
final class GroupExercisesByPartUsecaseTest: XCTestCase {

func testImplement() throws {
// given
let onlyShowsFavorite: Bool = false
let usecase = Domain.GroupExercisesByPartUsecase()

// when
let result = usecase.implement(exercises: [
EXERCISE_SQUAT,
EXERCISE_BENCH,
EXERCISE_DEAD,
])
], onlyShowsFavorite: onlyShowsFavorite)

// then
XCTAssertEqual(2, result[.leg]?.count)
XCTAssertEqual(1, result[.back]?.count)
XCTAssertEqual(1, result[.chest]?.count)
Expand Down
10 changes: 10 additions & 0 deletions dg-muscle-ios/sources/App/DI/DependencyInjector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ public final class DependencyInjector: Injector {
public func resolve<T, Arg1, Arg2>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2) -> T {
container.resolve(serviceType, arguments: arg1, arg2)!
}

// 세 개의 인수를 처리하는 resolve 함수
public func resolve<T, Arg1, Arg2, Arg3>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> T {
container.resolve(serviceType, arguments: arg1, arg2, arg3)!
}

// 네 개의 인수를 처리하는 resolve 함수
public func resolve<T, Arg1, Arg2, Arg3, Arg4>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> T {
container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4)!
}
}
13 changes: 13 additions & 0 deletions dg-muscle-ios/sources/App/DI/HistoryAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftUI
import Presentation

public struct HistoryAssembly: Assembly {

public func assemble(container: Swinject.Container) {
container.register(HeatMapColorSelectView.self) { resolver in
let userRepository = resolver.resolve(UserRepository.self)!
Expand All @@ -34,6 +35,18 @@ public struct HistoryAssembly: Assembly {
coordinator?.history.manageRun(run: run)
} manageMemo: { memo in
coordinator?.history.manageMemo(memo: memo)
} selectExerciseViewFactory: { tapExercise, add, close, run in
let exerciseRepository = resolver.resolve(ExerciseRepository.self)!
let userRepository = resolver.resolve(UserRepository.self)!

return SelectExerciseView(
exerciseRepository: exerciseRepository,
userRepository: userRepository,
tapExercise: tapExercise,
add: add,
close: close,
run: run
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion dg-muscle-ios/sources/DataLayer/User/Model/UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct UserData: Codable {
var fcmToken: String?
var link: String?
var developer: Bool?
var onlyShowsFavoriteExercises: Bool?

init(domain: Domain.User) {
self.id = domain.uid
Expand All @@ -29,6 +30,7 @@ struct UserData: Codable {
self.link = domain.link?.absoluteString
self.deleted = false
self.developer = domain.developer
self.onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
}

var domain: Domain.User {
Expand All @@ -40,7 +42,8 @@ struct UserData: Codable {
heatMapColor: heatmapColor?.domain ?? .green,
fcmToken: fcmToken,
link: .init(string: link ?? ""),
developer: developer ?? false
developer: developer ?? false,
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises ?? false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public final class UserRepositoryImpl: UserRepository {
try await AuthManager().updateUser(photoURL: _user?.photoURL)
}

public func updateUser(onlyShowsFavoriteExercises: Bool) {
_user?.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
}

public func withDrawal() async -> (any Error)? {

if _user?.uid == "taEJh30OpGVsR3FEFN2s67A8FvF3" {
Expand Down Expand Up @@ -164,7 +168,8 @@ public final class UserRepositoryImpl: UserRepository {
heatMapColor: .green,
fcmToken: nil,
link: nil,
developer: false
developer: false,
onlyShowsFavoriteExercises: false
)
return user
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import Foundation

public final class GroupExercisesByPartUsecase {
public init() { }
public func implement(exercises: [Exercise]) -> [Exercise.Part: [Exercise]] {
public func implement(exercises: [Exercise], onlyShowsFavorite: Bool) -> [Exercise.Part: [Exercise]] {
var exercises = exercises

if onlyShowsFavorite {
exercises = exercises
.filter({ $0.favorite })
}

var hashMap: [Exercise.Part: Set<Exercise>] = [:]

for exercise in exercises {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class SubscribeExercisesGroupedByPartUsecase {
private func bind() {
exerciseRepository
.exercises
.map({ GroupExercisesByPartUsecase().implement(exercises: $0) })
.map({ GroupExercisesByPartUsecase().implement(exercises: $0, onlyShowsFavorite: false) })
.assign(to: &$data)
}
}
5 changes: 4 additions & 1 deletion dg-muscle-ios/sources/Domain/User/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct User {
public var fcmToken: String?
public var link: URL?
public var developer: Bool
public var onlyShowsFavoriteExercises: Bool

public init(
uid: String,
Expand All @@ -25,7 +26,8 @@ public struct User {
heatMapColor: HeatMapColor,
fcmToken: String?,
link: URL?,
developer: Bool
developer: Bool,
onlyShowsFavoriteExercises: Bool
) {
self.uid = uid
self.displayName = displayName
Expand All @@ -35,5 +37,6 @@ public struct User {
self.fcmToken = fcmToken
self.link = link
self.developer = developer
self.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public protocol UserRepository {
func updateUser(photo: UIImage?) async throws
func updateUser(backgroundImage: UIImage?) async throws
func updateUser(link: URL?)
func updateUser(onlyShowsFavoriteExercises: Bool)
func withDrawal() async -> Error?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// SubscribeOnlyShowsFavoriteExercisesUsecase.swift
// Domain
//
// Created by 신동규 on 7/13/24.
//

import Foundation
import Combine

public final class SubscribeOnlyShowsFavoriteExercisesUsecase {
@Published var onlyShowsFavoriteExercises: Bool

let userRepository: UserRepository

public init(userRepository: UserRepository) {
self.onlyShowsFavoriteExercises = userRepository.get()?.onlyShowsFavoriteExercises ?? false
self.userRepository = userRepository

bind()
}

public func implement() -> AnyPublisher<Bool, Never> {
$onlyShowsFavoriteExercises.eraseToAnyPublisher()
}

private func bind() {
userRepository
.user
.map({ $0?.onlyShowsFavoriteExercises ?? false })
.assign(to: &$onlyShowsFavoriteExercises)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// UpdateOnlyShowsFavoriteExercisesUsecase.swift
// Domain
//
// Created by 신동규 on 7/13/24.
//

import Foundation

public final class UpdateOnlyShowsFavoriteExercisesUsecase {
let userRepository: UserRepository

public init(userRepository: UserRepository) {
self.userRepository = userRepository
}

public func implement(value: Bool) {
userRepository.updateUser(onlyShowsFavoriteExercises: value)
}
}
15 changes: 10 additions & 5 deletions dg-muscle-ios/sources/MockData/Data/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public let USER_DG: User = .init(
heatMapColor: .purple,
fcmToken: nil,
link: .init(string: "https://github.com/donggyushin"),
developer: true
developer: true,
onlyShowsFavoriteExercises: true
)


Expand All @@ -30,7 +31,8 @@ public let USER_1: User = .init(
heatMapColor: .green,
fcmToken: nil,
link: nil,
developer: false
developer: false,
onlyShowsFavoriteExercises: false
)

public let USER_2: User = .init(
Expand All @@ -41,7 +43,8 @@ public let USER_2: User = .init(
heatMapColor: .green,
fcmToken: nil,
link: nil,
developer: false
developer: false,
onlyShowsFavoriteExercises: false
)

public let USER_3: User = .init(
Expand All @@ -52,7 +55,8 @@ public let USER_3: User = .init(
heatMapColor: .mint,
fcmToken: nil,
link: nil,
developer: false
developer: false,
onlyShowsFavoriteExercises: false
)

public let USER_4: User = .init(
Expand All @@ -63,5 +67,6 @@ public let USER_4: User = .init(
heatMapColor: .mint,
fcmToken: nil,
link: .init(string: "https://github.com/donggyushin"),
developer: false
developer: false,
onlyShowsFavoriteExercises: false
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public final class UserRepositoryMock: UserRepository {
_user?.link = link
}

public func updateUser(onlyShowsFavoriteExercises: Bool) {
_user?.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
}

public func withDrawal() async -> (any Error)? {
nil
}
Expand Down
6 changes: 5 additions & 1 deletion dg-muscle-ios/sources/Presentation/Common/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public struct User: Hashable, Identifiable {
public let fcmToken: String?
public let link: URL?
public let developer: Bool
public let onlyShowsFavoriteExercises: Bool

public init() {
uid = UUID().uuidString
Expand All @@ -29,6 +30,7 @@ public struct User: Hashable, Identifiable {
fcmToken = nil
link = nil
developer = false
onlyShowsFavoriteExercises = false
}

public init(domain: Domain.User) {
Expand All @@ -40,6 +42,7 @@ public struct User: Hashable, Identifiable {
self.fcmToken = domain.fcmToken
self.link = domain.link
self.developer = domain.developer
self.onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
}

public var domain: Domain.User {
Expand All @@ -51,7 +54,8 @@ public struct User: Hashable, Identifiable {
heatMapColor: heatMapColor.domain,
fcmToken: fcmToken,
link: link,
developer: developer
developer: developer,
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Friend: Hashable, Identifiable {
var heatMapColor: Common.HeatMapColor
var link: URL?
var developer: Bool
var onlyShowsFavoriteExercises: Bool

init(domain: Domain.User) {
uid = domain.uid
Expand All @@ -27,6 +28,7 @@ struct Friend: Hashable, Identifiable {
heatMapColor = .init(domain: domain.heatMapColor)
link = domain.link
developer = domain.developer
onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
}

var domain: Domain.User {
Expand All @@ -38,7 +40,8 @@ struct Friend: Hashable, Identifiable {
heatMapColor: heatMapColor.domain,
fcmToken: nil,
link: link,
developer: developer
developer: developer,
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
import Foundation
import Domain

struct Exercise: Hashable {
let id: String
let name: String
let favorite: Bool
let parts: [ExercisePart]
public struct HistoryExercise: Hashable {
public let id: String
public let name: String
public let favorite: Bool
public let parts: [ExercisePart]

init(domain: Domain.Exercise) {
public init(domain: Domain.Exercise) {
self.id = domain.id
self.name = domain.name
self.favorite = domain.favorite
self.parts = domain.parts.map({ .init(domain: $0) })
}

var domain: Domain.Exercise {
public var domain: Domain.Exercise {
.init(
id: id,
name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import Foundation
import Domain

enum ExercisePart: String, CaseIterable {
public enum ExercisePart: String, CaseIterable {
case arm
case back
case chest
case core
case leg
case shoulder

init(domain: Domain.Exercise.Part) {
public init(domain: Domain.Exercise.Part) {
switch domain {
case .arm:
self = .arm
Expand All @@ -33,7 +33,7 @@ enum ExercisePart: String, CaseIterable {
}
}

var domain: Domain.Exercise.Part {
public var domain: Domain.Exercise.Part {
switch self {
case .arm:
return .arm
Expand Down
Loading
Loading