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

[TNT-210] 트레이너 캘린더 api 연결 #83

Merged
merged 2 commits into from
Feb 13, 2025
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 @@ -64,9 +64,10 @@ public struct TCalendarRepresentable: UIViewRepresentable {
calendar.appearance.titleDefaultColor = .clear
calendar.calendarWeekdayView.weekdayLabels[0].textColor = UIColor(.red500)


return calendar
}

public func updateUIView(_ uiView: FSCalendar, context: Context) {
// `selectedDate` 반영
uiView.select(selectedDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,79 @@ public struct SessonEntity: Equatable, Encodable {
self.isCompleted = isCompleted
}
}

// mapper
// MARK: - GetDateSessionListDTO -> GetDateSessionListEntity
public extension GetDateSessionListDTO {
func toEntity() -> GetDateSessionListEntity {
return GetDateSessionListEntity(
count: self.count,
date: self.date,
lessons: self.lessons.map { $0.toEntity() }
)
}

// GetDateSessionListEntity -> GetDateSessionListDTO
func toDTO() -> GetDateSessionListDTO {
return GetDateSessionListDTO(
count: self.count,
date: self.date,
lessons: self.lessons.map { $0.toDTO() }
)
}
}

// MARK: - SessonDTO -> SessonEntity
public extension SessonDTO {
public func toEntity() -> SessonEntity {
return SessonEntity(
ptLessonId: self.ptLessonId,
traineeId: self.traineeId,
traineeName: self.traineeName,
session: self.session,
startTime: self.startTime,
endTime: self.endTime,
isCompleted: self.isCompleted
)
}

// SessonEntity -> SessonDTO
public func toDTO() -> SessonDTO {
return SessonDTO(
ptLessonId: self.ptLessonId,
traineeId: self.traineeId,
traineeName: self.traineeName,
session: self.session,
startTime: self.startTime,
endTime: self.endTime,
isCompleted: self.isCompleted
)
}
}

// MARK: - GetDateSessionListEntity -> GetDateSessionListDTO
public extension GetDateSessionListEntity {
public func toDTO() -> GetDateSessionListDTO {
return GetDateSessionListDTO(
count: self.count,
date: self.date,
lessons: self.lessons.map { $0.toDTO() }
)
}
}

// MARK: - SessonEntity -> SessonDTO
public extension SessonEntity {
public func toDTO() -> SessonDTO {
return SessonDTO(
ptLessonId: self.ptLessonId,
traineeId: self.traineeId,
traineeName: self.traineeName,
session: self.session,
startTime: self.startTime,
endTime: self.endTime,
isCompleted: self.isCompleted
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public struct TrainerHomeFeature {
}

@Dependency(\.traineeUseCase) private var traineeUseCase: TraineeUseCase
@Dependency(\.trainerRepoUseCase) private var trainerRepoUseCase: TrainerRepository

public enum Action: Sendable, ViewAction {
/// 뷰에서 발생한 액션을 처리합니다.
Expand All @@ -103,6 +104,14 @@ public struct TrainerHomeFeature {
case tapPopUpConnectButton
/// 화면이 표시될 때
case onAppear
/// events 타입에 맞춰서 달력 스케줄 캐수 표시 데이터 계산
case fetchMonthlyLessons(year: Int, month: Int)
/// 달력 스케줄 캐수 표시 데이터 업데이트
case updateEvents([Date: Int])
/// 특정 날짜 탭
case calendarDateTap
/// 탭한 일자 api 형태에 맞춰 변환하기(yyyy-mm-dd)
case settingSessionList(sessions: GetDateSessionListEntity)
}
}

Expand All @@ -117,7 +126,7 @@ public struct TrainerHomeFeature {
case .view(let action):
switch action {
case .binding(\.selectedDate):
print(state.events[state.selectedDate])
print("state.events[state.selectedDate] \(state.events[state.selectedDate])")
return .none

case .binding:
Expand Down Expand Up @@ -157,11 +166,59 @@ public struct TrainerHomeFeature {
return .send(.setNavigating(.trainerMakeInvitationCodePage))

case .onAppear:
let year: Int = Calendar.current.component(.year, from: state.selectedDate)
let month: Int = Calendar.current.component(.month, from: state.selectedDate)

if let hideUntil = state.hidePopupUntil, hideUntil > Date() {
state.view_isPopUpPresented = false
} else {
state.view_isPopUpPresented = true
}

return .send(.view(.fetchMonthlyLessons(year: year, month: month)))

case .fetchMonthlyLessons(year: let year, month: let month):
return .run { send in
do {
let temp: GetMonthlyLessonListResDTO = try await trainerRepoUseCase.getMonthlyLessonList(
year: year,
month: month
)

let dateFormatter: DateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
Comment on lines +188 to +189
Copy link
Contributor

Choose a reason for hiding this comment

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

홈 관련 나머지 작업하실 때 저희 사용하고 있는 TDateFormatUtility로 바꿔주시면 좋을 것 같아요! DateFormatter 하나씩 만드는게 초기화 비용이 크더라구요

Copy link
Member Author

Choose a reason for hiding this comment

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

네~


var events: [Date: Int] = [:]
for lesson in temp.calendarPtLessonCounts {
if let date = dateFormatter.date(from: lesson.date) {
events[date] = lesson.count
} else {
print("Invalid date format: \(lesson.date)")
}
}
await send(.view(.updateEvents(events)))
} catch {
print("리스트 Fetching Error: \(error)")
}
}
case .updateEvents(let events):
state.events = events
return .none

case .calendarDateTap:
let formattedDate = TDateFormatUtility.formatter(for: .yyyyMMdd).string(from: state.selectedDate)

return .run { send in
do {
let sessionList: GetDateSessionListEntity = try await trainerRepoUseCase.getDateSessionList(date: formattedDate).toEntity()
await send(.view(.settingSessionList(sessions: sessionList)))
} catch {
print("error \(error.localizedDescription)")
}
}

case .settingSessionList(let list):
state.tappedsessionInfo = list
return .none
}
case .setNavigating:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ public struct TrainerHomeView: View {
currentPage: $store.view_currentPage,
events: store.events
)
.onChange(of: store.state.selectedDate, { oldValue, newValue in
let startOfDay = Calendar.current.startOfDay(for: newValue)
store.selectedDate = startOfDay
store.send(.view(.calendarDateTap))
})
.padding(.horizontal, 20)
}
}
.padding(.vertical, 12)

}

/// 수업 리스트 상단 타이틀
Expand Down Expand Up @@ -110,10 +114,12 @@ public struct TrainerHomeView: View {
@ViewBuilder
private func RecordList() -> some View {
VStack {
if let record = store.tappedsessionInfo {
if let record = store.tappedsessionInfo, !record.lessons.isEmpty {
ForEach(record.lessons, id: \.id) { record in
SessionCellView(session: record) {
send(.tapSessionCompleted(id: record.ptLessonId))
} onTap: {
// TODO: - 트레이너 기록 추가
}
}
} else {
Expand All @@ -131,9 +137,10 @@ public struct TrainerHomeView: View {
.frame(width: 126, height: 58)
.overlay {
HStack(spacing: 4) {
Image(.icnPlusEmpty)
Image(.icnPlus)
.resizable()
.frame(width: 24, height: 24)
.tint(Color.common0)
Text("수업추가")
.typographyStyle(.body1Medium, with: .neutral50)
}
Expand Down Expand Up @@ -215,6 +222,7 @@ extension TrainerHomeView {
struct SessionCellView: View {
var session: SessonEntity
var onTapComplete: () -> Void
var onTap: (() -> Void)?

var body: some View {
HStack(spacing: 20) {
Expand All @@ -237,7 +245,7 @@ extension TrainerHomeView {

if session.isCompleted {
Button {
//
onTap?()
} label: {
HStack(spacing: 4) {
Image(.icnWriteWhite)
Expand Down
14 changes: 13 additions & 1 deletion TnT/Projects/TnTApp/Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ import ComposableArchitecture

struct ContentView: View {
var body: some View {
Text("")
TrainerHomeView(store: Store(initialState: TrainerHomeFeature.State(), reducer: {
TrainerHomeFeature()
}))
// TrainerMypageView(store: Store(initialState: TrainerMypageFeature.State(
// userName: "홍길동",
// userImageUrl: nil,
// studentCount: 10,
// oldStudentCount: 5,
// appPushNotificationAllowed: true,
// versionInfo: "1.0.0"
// ), reducer: {
// TrainerMypageFeature()
// }))
}
}

Expand Down
Binary file modified TnT/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.