Skip to content

Commit 1e73f83

Browse files
authored
Feature/favorite/main (#52)
* feat: add onlyShowsFavoriteExercises * feat: UpdateOnlyShowsFavoriteExercisesUsecase * feat: SubscribeOnlyShowsFavoriteExercisesUsecase * feat: update viewmodel * refactor: DI refactoring * feat: add feature that can shows only favorites * fix test case
1 parent e519903 commit 1e73f83

22 files changed

+217
-62
lines changed

dg-muscle-ios/Tests/Exercise/GroupExercisesByPartUsecaseTest.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import Domain
1212
final class GroupExercisesByPartUsecaseTest: XCTestCase {
1313

1414
func testImplement() throws {
15+
// given
16+
let onlyShowsFavorite: Bool = false
1517
let usecase = Domain.GroupExercisesByPartUsecase()
1618

19+
// when
1720
let result = usecase.implement(exercises: [
1821
EXERCISE_SQUAT,
1922
EXERCISE_BENCH,
2023
EXERCISE_DEAD,
21-
])
24+
], onlyShowsFavorite: onlyShowsFavorite)
2225

26+
// then
2327
XCTAssertEqual(2, result[.leg]?.count)
2428
XCTAssertEqual(1, result[.back]?.count)
2529
XCTAssertEqual(1, result[.chest]?.count)

dg-muscle-ios/sources/App/DI/DependencyInjector.swift

+10
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ public final class DependencyInjector: Injector {
4747
public func resolve<T, Arg1, Arg2>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2) -> T {
4848
container.resolve(serviceType, arguments: arg1, arg2)!
4949
}
50+
51+
// 세 개의 인수를 처리하는 resolve 함수
52+
public func resolve<T, Arg1, Arg2, Arg3>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3) -> T {
53+
container.resolve(serviceType, arguments: arg1, arg2, arg3)!
54+
}
55+
56+
// 네 개의 인수를 처리하는 resolve 함수
57+
public func resolve<T, Arg1, Arg2, Arg3, Arg4>(_ serviceType: T.Type, arguments arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3, _ arg4: Arg4) -> T {
58+
container.resolve(serviceType, arguments: arg1, arg2, arg3, arg4)!
59+
}
5060
}

dg-muscle-ios/sources/App/DI/HistoryAssembly.swift

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SwiftUI
1212
import Presentation
1313

1414
public struct HistoryAssembly: Assembly {
15+
1516
public func assemble(container: Swinject.Container) {
1617
container.register(HeatMapColorSelectView.self) { resolver in
1718
let userRepository = resolver.resolve(UserRepository.self)!
@@ -34,6 +35,18 @@ public struct HistoryAssembly: Assembly {
3435
coordinator?.history.manageRun(run: run)
3536
} manageMemo: { memo in
3637
coordinator?.history.manageMemo(memo: memo)
38+
} selectExerciseViewFactory: { tapExercise, add, close, run in
39+
let exerciseRepository = resolver.resolve(ExerciseRepository.self)!
40+
let userRepository = resolver.resolve(UserRepository.self)!
41+
42+
return SelectExerciseView(
43+
exerciseRepository: exerciseRepository,
44+
userRepository: userRepository,
45+
tapExercise: tapExercise,
46+
add: add,
47+
close: close,
48+
run: run
49+
)
3750
}
3851
}
3952

dg-muscle-ios/sources/DataLayer/User/Model/UserData.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct UserData: Codable {
1818
var fcmToken: String?
1919
var link: String?
2020
var developer: Bool?
21+
var onlyShowsFavoriteExercises: Bool?
2122

2223
init(domain: Domain.User) {
2324
self.id = domain.uid
@@ -29,6 +30,7 @@ struct UserData: Codable {
2930
self.link = domain.link?.absoluteString
3031
self.deleted = false
3132
self.developer = domain.developer
33+
self.onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
3234
}
3335

3436
var domain: Domain.User {
@@ -40,7 +42,8 @@ struct UserData: Codable {
4042
heatMapColor: heatmapColor?.domain ?? .green,
4143
fcmToken: fcmToken,
4244
link: .init(string: link ?? ""),
43-
developer: developer ?? false
45+
developer: developer ?? false,
46+
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises ?? false
4447
)
4548
}
4649
}

dg-muscle-ios/sources/DataLayer/User/Repository/UserRepositoryImpl.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public final class UserRepositoryImpl: UserRepository {
8888
try await AuthManager().updateUser(photoURL: _user?.photoURL)
8989
}
9090

91+
public func updateUser(onlyShowsFavoriteExercises: Bool) {
92+
_user?.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
93+
}
94+
9195
public func withDrawal() async -> (any Error)? {
9296

9397
if _user?.uid == "taEJh30OpGVsR3FEFN2s67A8FvF3" {
@@ -164,7 +168,8 @@ public final class UserRepositoryImpl: UserRepository {
164168
heatMapColor: .green,
165169
fcmToken: nil,
166170
link: nil,
167-
developer: false
171+
developer: false,
172+
onlyShowsFavoriteExercises: false
168173
)
169174
return user
170175
}

dg-muscle-ios/sources/Domain/Exercise/Usecase/GroupExercisesByPartUsecase.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import Foundation
99

1010
public final class GroupExercisesByPartUsecase {
1111
public init() { }
12-
public func implement(exercises: [Exercise]) -> [Exercise.Part: [Exercise]] {
12+
public func implement(exercises: [Exercise], onlyShowsFavorite: Bool) -> [Exercise.Part: [Exercise]] {
13+
var exercises = exercises
14+
15+
if onlyShowsFavorite {
16+
exercises = exercises
17+
.filter({ $0.favorite })
18+
}
19+
1320
var hashMap: [Exercise.Part: Set<Exercise>] = [:]
1421

1522
for exercise in exercises {

dg-muscle-ios/sources/Domain/Exercise/Usecase/SubscribeExercisesGroupedByPartUsecase.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class SubscribeExercisesGroupedByPartUsecase {
2424
private func bind() {
2525
exerciseRepository
2626
.exercises
27-
.map({ GroupExercisesByPartUsecase().implement(exercises: $0) })
27+
.map({ GroupExercisesByPartUsecase().implement(exercises: $0, onlyShowsFavorite: false) })
2828
.assign(to: &$data)
2929
}
3030
}

dg-muscle-ios/sources/Domain/User/Model/User.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct User {
1616
public var fcmToken: String?
1717
public var link: URL?
1818
public var developer: Bool
19+
public var onlyShowsFavoriteExercises: Bool
1920

2021
public init(
2122
uid: String,
@@ -25,7 +26,8 @@ public struct User {
2526
heatMapColor: HeatMapColor,
2627
fcmToken: String?,
2728
link: URL?,
28-
developer: Bool
29+
developer: Bool,
30+
onlyShowsFavoriteExercises: Bool
2931
) {
3032
self.uid = uid
3133
self.displayName = displayName
@@ -35,5 +37,6 @@ public struct User {
3537
self.fcmToken = fcmToken
3638
self.link = link
3739
self.developer = developer
40+
self.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
3841
}
3942
}

dg-muscle-ios/sources/Domain/User/Repository/UserRepository.swift

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public protocol UserRepository {
2525
func updateUser(photo: UIImage?) async throws
2626
func updateUser(backgroundImage: UIImage?) async throws
2727
func updateUser(link: URL?)
28+
func updateUser(onlyShowsFavoriteExercises: Bool)
2829
func withDrawal() async -> Error?
2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// SubscribeOnlyShowsFavoriteExercisesUsecase.swift
3+
// Domain
4+
//
5+
// Created by 신동규 on 7/13/24.
6+
//
7+
8+
import Foundation
9+
import Combine
10+
11+
public final class SubscribeOnlyShowsFavoriteExercisesUsecase {
12+
@Published var onlyShowsFavoriteExercises: Bool
13+
14+
let userRepository: UserRepository
15+
16+
public init(userRepository: UserRepository) {
17+
self.onlyShowsFavoriteExercises = userRepository.get()?.onlyShowsFavoriteExercises ?? false
18+
self.userRepository = userRepository
19+
20+
bind()
21+
}
22+
23+
public func implement() -> AnyPublisher<Bool, Never> {
24+
$onlyShowsFavoriteExercises.eraseToAnyPublisher()
25+
}
26+
27+
private func bind() {
28+
userRepository
29+
.user
30+
.map({ $0?.onlyShowsFavoriteExercises ?? false })
31+
.assign(to: &$onlyShowsFavoriteExercises)
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// UpdateOnlyShowsFavoriteExercisesUsecase.swift
3+
// Domain
4+
//
5+
// Created by 신동규 on 7/13/24.
6+
//
7+
8+
import Foundation
9+
10+
public final class UpdateOnlyShowsFavoriteExercisesUsecase {
11+
let userRepository: UserRepository
12+
13+
public init(userRepository: UserRepository) {
14+
self.userRepository = userRepository
15+
}
16+
17+
public func implement(value: Bool) {
18+
userRepository.updateUser(onlyShowsFavoriteExercises: value)
19+
}
20+
}

dg-muscle-ios/sources/MockData/Data/User.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public let USER_DG: User = .init(
1818
heatMapColor: .purple,
1919
fcmToken: nil,
2020
link: .init(string: "https://github.com/donggyushin"),
21-
developer: true
21+
developer: true,
22+
onlyShowsFavoriteExercises: true
2223
)
2324

2425

@@ -30,7 +31,8 @@ public let USER_1: User = .init(
3031
heatMapColor: .green,
3132
fcmToken: nil,
3233
link: nil,
33-
developer: false
34+
developer: false,
35+
onlyShowsFavoriteExercises: false
3436
)
3537

3638
public let USER_2: User = .init(
@@ -41,7 +43,8 @@ public let USER_2: User = .init(
4143
heatMapColor: .green,
4244
fcmToken: nil,
4345
link: nil,
44-
developer: false
46+
developer: false,
47+
onlyShowsFavoriteExercises: false
4548
)
4649

4750
public let USER_3: User = .init(
@@ -52,7 +55,8 @@ public let USER_3: User = .init(
5255
heatMapColor: .mint,
5356
fcmToken: nil,
5457
link: nil,
55-
developer: false
58+
developer: false,
59+
onlyShowsFavoriteExercises: false
5660
)
5761

5862
public let USER_4: User = .init(
@@ -63,5 +67,6 @@ public let USER_4: User = .init(
6367
heatMapColor: .mint,
6468
fcmToken: nil,
6569
link: .init(string: "https://github.com/donggyushin"),
66-
developer: false
70+
developer: false,
71+
onlyShowsFavoriteExercises: false
6772
)

dg-muscle-ios/sources/MockData/Repository/UserRepositoryMock.swift

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public final class UserRepositoryMock: UserRepository {
4848
_user?.link = link
4949
}
5050

51+
public func updateUser(onlyShowsFavoriteExercises: Bool) {
52+
_user?.onlyShowsFavoriteExercises = onlyShowsFavoriteExercises
53+
}
54+
5155
public func withDrawal() async -> (any Error)? {
5256
nil
5357
}

dg-muscle-ios/sources/Presentation/Common/Model/User.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public struct User: Hashable, Identifiable {
1919
public let fcmToken: String?
2020
public let link: URL?
2121
public let developer: Bool
22+
public let onlyShowsFavoriteExercises: Bool
2223

2324
public init() {
2425
uid = UUID().uuidString
@@ -29,6 +30,7 @@ public struct User: Hashable, Identifiable {
2930
fcmToken = nil
3031
link = nil
3132
developer = false
33+
onlyShowsFavoriteExercises = false
3234
}
3335

3436
public init(domain: Domain.User) {
@@ -40,6 +42,7 @@ public struct User: Hashable, Identifiable {
4042
self.fcmToken = domain.fcmToken
4143
self.link = domain.link
4244
self.developer = domain.developer
45+
self.onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
4346
}
4447

4548
public var domain: Domain.User {
@@ -51,7 +54,8 @@ public struct User: Hashable, Identifiable {
5154
heatMapColor: heatMapColor.domain,
5255
fcmToken: fcmToken,
5356
link: link,
54-
developer: developer
57+
developer: developer,
58+
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises
5559
)
5660
}
5761
}

dg-muscle-ios/sources/Presentation/Friend/List/Model/Friend.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct Friend: Hashable, Identifiable {
1818
var heatMapColor: Common.HeatMapColor
1919
var link: URL?
2020
var developer: Bool
21+
var onlyShowsFavoriteExercises: Bool
2122

2223
init(domain: Domain.User) {
2324
uid = domain.uid
@@ -27,6 +28,7 @@ struct Friend: Hashable, Identifiable {
2728
heatMapColor = .init(domain: domain.heatMapColor)
2829
link = domain.link
2930
developer = domain.developer
31+
onlyShowsFavoriteExercises = domain.onlyShowsFavoriteExercises
3032
}
3133

3234
var domain: Domain.User {
@@ -38,7 +40,8 @@ struct Friend: Hashable, Identifiable {
3840
heatMapColor: heatMapColor.domain,
3941
fcmToken: nil,
4042
link: link,
41-
developer: developer
43+
developer: developer,
44+
onlyShowsFavoriteExercises: onlyShowsFavoriteExercises
4245
)
4346
}
4447
}

dg-muscle-ios/sources/Presentation/History/Model/Form/Exercise.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
import Foundation
99
import Domain
1010

11-
struct Exercise: Hashable {
12-
let id: String
13-
let name: String
14-
let favorite: Bool
15-
let parts: [ExercisePart]
11+
public struct HistoryExercise: Hashable {
12+
public let id: String
13+
public let name: String
14+
public let favorite: Bool
15+
public let parts: [ExercisePart]
1616

17-
init(domain: Domain.Exercise) {
17+
public init(domain: Domain.Exercise) {
1818
self.id = domain.id
1919
self.name = domain.name
2020
self.favorite = domain.favorite
2121
self.parts = domain.parts.map({ .init(domain: $0) })
2222
}
2323

24-
var domain: Domain.Exercise {
24+
public var domain: Domain.Exercise {
2525
.init(
2626
id: id,
2727
name: name,

dg-muscle-ios/sources/Presentation/History/Model/Form/ExercisePart.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import Foundation
99
import Domain
1010

11-
enum ExercisePart: String, CaseIterable {
11+
public enum ExercisePart: String, CaseIterable {
1212
case arm
1313
case back
1414
case chest
1515
case core
1616
case leg
1717
case shoulder
1818

19-
init(domain: Domain.Exercise.Part) {
19+
public init(domain: Domain.Exercise.Part) {
2020
switch domain {
2121
case .arm:
2222
self = .arm
@@ -33,7 +33,7 @@ enum ExercisePart: String, CaseIterable {
3333
}
3434
}
3535

36-
var domain: Domain.Exercise.Part {
36+
public var domain: Domain.Exercise.Part {
3737
switch self {
3838
case .arm:
3939
return .arm

0 commit comments

Comments
 (0)