Skip to content

Commit b07e0f2

Browse files
committed
Feat: 루틴 완료 api v2 연동 (#T3-178)
1 parent ebabfe5 commit b07e0f2

15 files changed

Lines changed: 251 additions & 178 deletions

File tree

Projects/DataSource/Sources/DTO/RoutineCompletionDTO.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
//
77

88
struct RoutineCompletionListDTO: Encodable {
9-
let performedDate: String
109
let routineCompletionInfos: [RoutineCompletionDTO]
1110
}
1211

1312
struct RoutineCompletionDTO: Encodable {
1413
let routineId: String
15-
let completeYn: Bool
16-
let historySeq: Int
17-
let routineType: String
14+
let routineCompleteYn: Bool
15+
let subRoutineCompleteYn: [Bool]
1816
}

Projects/DataSource/Sources/Endpoint/RoutineEndpoint.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ extension RoutineEndpoint: Endpoint {
4242

4343
var method: HTTPMethod {
4444
switch self {
45-
case .createRoutine, .updateRoutineCompletion:
45+
case .createRoutine:
4646
.post
47+
case .updateRoutineCompletion:
48+
.put
4749
case .fetchRoutine, .fetchRoutines:
4850
.get
4951
case .updateRoutine:

Projects/DataSource/Sources/Repository/RoutineRepository.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,12 @@ final class RoutineRepository: RoutineRepositoryProtocol {
7474
_ = try await networkService.request(endpoint: endpoint, type: EmptyResponseDTO.self)
7575
}
7676

77-
func updateRoutineCompletions(routines: [RoutineCompletionEntity]) async throws {
78-
guard let routine = routines.first else { return }
79-
let performedDate = routine.performedDate
77+
func updateRoutineCompletions(routines: [RoutineEntity]) async throws {
8078
let completionDTO = routines.map({ RoutineCompletionDTO(
8179
routineId: $0.routineId,
82-
completeYn: $0.completeYn,
83-
historySeq: $0.historySeq,
84-
routineType: $0.routineType) })
85-
86-
let completionListDTO = RoutineCompletionListDTO(
87-
performedDate: performedDate,
88-
routineCompletionInfos: completionDTO)
80+
routineCompleteYn: $0.routineCompleteYn,
81+
subRoutineCompleteYn: $0.subRoutineCompleteYn) })
82+
let completionListDTO = RoutineCompletionListDTO(routineCompletionInfos: completionDTO)
8983

9084
let endpoint = RoutineEndpoint.updateRoutineCompletion(routines: completionListDTO)
9185
_ = try await networkService.request(endpoint: endpoint, type: EmptyResponseDTO.self)

Projects/Domain/Sources/Entity/RoutineCompletionEntity.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

Projects/Domain/Sources/Protocol/Repository/RoutineRepositoryProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ public protocol RoutineRepositoryProtocol {
3838

3939
/// 루틴 완료 여부를 업데이트 합니다.
4040
/// - Parameter routines: 완료 여부를 업데이트할 루틴 배열
41-
func updateRoutineCompletions(routines: [RoutineCompletionEntity]) async throws
41+
func updateRoutineCompletions(routines: [RoutineEntity]) async throws
4242
}

Projects/Domain/Sources/Protocol/UseCase/RoutineUseCaseProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ public protocol RoutineUseCaseProtocol {
1818

1919
func deleteDailyRoutine(routineId: String) async throws
2020

21-
func updateRoutineCompletions(routines: [RoutineCompletionEntity]) async throws
21+
func updateRoutineCompletions(routines: [RoutineEntity]) async throws
2222
}

Projects/Domain/Sources/UseCase/Routine/RoutineUseCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public final class RoutineUseCase: RoutineUseCaseProtocol {
6363
try await routineRepository.deleteDailyRoutine(routineId: routineId)
6464
}
6565

66-
public func updateRoutineCompletions(routines: [RoutineCompletionEntity]) async throws {
66+
public func updateRoutineCompletions(routines: [RoutineEntity]) async throws {
6767
try await routineRepository.updateRoutineCompletions(routines: routines)
6868
}
6969
}

Projects/Presentation/Sources/Common/View/TabBarView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final public class TabBarView: UITabBarController {
4848
guard let mypageViewModel = DIContainer.shared.resolve(type: MypageViewModel.self)
4949
else { fatalError("mypageViewModel 의존성이 등록되지 않았습니다.") }
5050

51-
let homeView = HomeView(viewModel: homeViewModel)
51+
let homeView = HomeViewController(viewModel: homeViewModel)
5252
let recommendView = RecommendedRoutineViewController(viewModel: recommendedRoutineViewModel)
5353
let mypageView = MypageView(viewModel: mypageViewModel)
5454

Projects/Presentation/Sources/Home/Model/Routine.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ struct Routine: RoutineProtocol {
2020
let isDeleted: Bool
2121
let startDate: Date
2222
let endDate: Date
23+
24+
func toRoutineEntity() -> RoutineEntity {
25+
return RoutineEntity(
26+
routineId: id,
27+
routineName: title,
28+
repeatDay: repeatDay.map({ $0.rawValue }),
29+
executionTime: startTime.convertToString(dateType: .time),
30+
routineCompleteYn: isDone,
31+
subRoutineNames: subRoutines,
32+
subRoutineCompleteYn: subRoutineCompleted,
33+
recommendedRoutineType: routineType?.rawValue,
34+
routineDeletedYn: isDeleted,
35+
routineStartDate: startDate.convertToString(dateType: .yearMonthDate),
36+
routineEndDate: endDate.convertToString(dateType: .yearMonthDate))
37+
}
2338
}
2439

2540
extension RoutineEntity {

Projects/Presentation/Sources/Home/View/Component/DateView.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ final class DateView: UIView {
1616
static let dateButtonTopSpacing: CGFloat = 7
1717
static let dateButtonSize: CGFloat = 30
1818
static let dateLabelHeight: CGFloat = 17
19+
static let allCompletedIconTopSpacing: CGFloat = 5
1920
}
2021

2122
private let dayLabel = UILabel()
2223
private let dateButton = UIButton()
2324
private let dateLabel = UILabel()
25+
private let allCompletedIcon = UIImageView()
2426
private let date: Date
2527
private let isToday: Bool
2628
private var isSelected: Bool {
2729
didSet {
2830
updateAttribute()
2931
}
3032
}
31-
var didTappedDateButton: ((Date) -> Void)?
33+
var didTapDateButton: ((Date) -> Void)?
3234

3335
init(
3436
date: Date,
@@ -66,12 +68,16 @@ final class DateView: UIView {
6668
dateLabel.text = "\(date.convertToString(dateType: .date))"
6769
dateLabel.font = BitnagilFont(style: .body2, weight: .medium).font
6870
dateLabel.textColor = BitnagilColor.gray70
71+
72+
allCompletedIcon.image = BitnagilIcon.asteriskIcon
73+
allCompletedIcon.isHidden = true
6974
}
7075

7176
private func configureLayout() {
7277
addSubview(dayLabel)
7378
addSubview(dateButton)
7479
dateButton.addSubview(dateLabel)
80+
addSubview(allCompletedIcon)
7581

7682
dayLabel.snp.makeConstraints { make in
7783
make.top.leading.trailing.equalToSuperview()
@@ -89,6 +95,11 @@ final class DateView: UIView {
8995
make.center.equalToSuperview()
9096
make.height.equalTo(Layout.dateLabelHeight)
9197
}
98+
99+
allCompletedIcon.snp.makeConstraints { make in
100+
make.top.equalTo(dateButton.snp.bottom).offset(Layout.allCompletedIconTopSpacing)
101+
make.centerX.equalToSuperview()
102+
}
92103
}
93104

94105
private func updateAttribute() {
@@ -106,10 +117,14 @@ final class DateView: UIView {
106117
}
107118

108119
private func selectDate() {
109-
didTappedDateButton?(date)
120+
didTapDateButton?(date)
110121
}
111122

112123
func updateSelectState(isSelected: Bool) {
113124
self.isSelected = isSelected
114125
}
126+
127+
func updateAllCompleted() {
128+
allCompletedIcon.isHidden.toggle()
129+
}
115130
}

0 commit comments

Comments
 (0)