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/166 home create schedule #181

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 11 additions & 7 deletions Projects/Domain/Source/Entity/Place.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
import Foundation

public enum Place: String, Codable, CaseIterable, Hashable {

case programming1 = "프로그래밍1실"
case programming2 = "프로그래밍2실"
case programming3 = "프로그래밍3실"
case korean = "국어실"
case math = "수학실"
case society = "사회실"

case programming1 = "PROGRAMMING_1"
case programming2 = "PROGRAMMING_2"
case programming3 = "PROGRAMMING_3"
case korean = "KOREAN"
case math = "MATH"
case society = "SOCIETY"
case hall = "HALL"
case audiovisual_room = "AUDIOVISUAL_ROOM"
case none = "NONE"
case etc = "ETC"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

public struct FetchScheduleBetweenRequest: RequestProtocol {

public let startDate: String
public let endDate: String
public let startAt: String
public let endAt: String

public init(startDate: String, endDate: String) {
self.startDate = startDate
self.endDate = endDate
public init(startAt: String, endAt: String) {
self.startAt = startAt
self.endAt = endAt
}
}
107 changes: 63 additions & 44 deletions Projects/Feature/Source/Home/Component/ScheduleContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,79 @@ struct ScheduleContainer: View {

private let scheduleData: [ScheduleResponse]?

func getSchedule(scheduleResponse: [ScheduleResponse]) -> [ScheduleResponse] {
var schedules: [ScheduleResponse] = []
var cnt: Int = 0

for data in scheduleResponse {
if schedules.count == 0 {
schedules.append(scheduleResponse[0])
} else if schedules[0].date == data.date || cnt <= 1 {
schedules.append(data)
if schedules[0].date != data.date {
cnt += 1
}
}
}


print("스케줄 \(schedules)")
return schedules
}

init(
data scheduleData: [ScheduleResponse]?
) {
self.scheduleData = scheduleData
}

var body: some View {
if let data = scheduleData {
HStack(alignment: .top, spacing: 12) {
ForEach(data, id: \.self) { data in
VStack(alignment: .leading, spacing: 0) {
Text("\(data.name)")
// Text("D - " + { () -> String in
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
// let currentDate = Date()
// guard let targetDate = dateFormatter.date(from: data.) else {
// return "오류"
// }
// let calendar = Calendar.current
// let dateComponents = calendar.dateComponents([.day], from: currentDate, to: targetDate)
//
// guard let daysDifference = dateComponents.day else {
// return "오류"
// }
// if daysDifference == 0 {
// return "day"
// } else {
// return "\(abs(daysDifference))"
// }
// }())
// .font(.title(.small))
// .dodamColor(.onSurfaceVariant)
//
// Text({ () -> String in
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd"
// dateFormatter.locale = Locale(identifier: "ko_KR")
// if let date = dateFormatter.date(from: data.startDate) {
// dateFormatter.dateFormat = "M월 d일 (E)"
// return dateFormatter.string(from: date)
// }
// return "오류"
// }())
// .font(.label(.medium))
// .dodamColor(.tertiary)
VStack(spacing: 10) {
if let data = scheduleData {
ForEach(0 ..< min(data.count, 2), id: \.self) { idx in
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .bottom, spacing: 4) {
Text("\(data[idx].date[0].suffix(2))일")
.heading2(.bold)
.foreground(DodamColor.Label.normal)

let weekdayName = { (dateString: String) -> String in
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

guard let date = dateFormatter.date(from: dateString) else {
return "알 수 없음"
}

let calendar = Calendar.current
let weekdayIndex = calendar.component(.weekday, from: date)
return calendar.weekdaySymbols[weekdayIndex - 1]
}

Text("\(weekdayName(data[idx].date[0]))")
.label(.medium)
.foreground(DodamColor.Label.alternative)

}

HStack {
Circle()
.frame(width: 6, height: 6)
.foregroundStyle(Color.init(0xffFFB5B5))
Text("\(data[idx].name)")
Spacer()
}
}
.padding(.bottom, 10)
.padding(.horizontal, 10)
}
} else {
SupportingContainer(
subTitle: "한달 간 일정이 없어요",
title: "다음 달 일정을 기다려주세요"
)
}
} else {
SupportingContainer(
subTitle: "한달 간 일정이 없어요",
title: "전체 일정 확인하기"
)
}
.padding(.top, 6)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct SupportingContainer: View {
.minimumScaleFactor(0.7)
.foreground(DodamColor.Primary.normal)
}
.padding(.top, 10)
.padding(.horizontal, 10)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
3 changes: 3 additions & 0 deletions Projects/Feature/Source/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ struct HomeView: View {
}
}
}
DodamContainer.default(title: "가까운 일정", icon: Dodam.icon(.calendar)) {
ScheduleContainer(data: viewModel.scheduleData)
}
}
.padding(.horizontal, 16)
}
Expand Down
22 changes: 20 additions & 2 deletions Projects/Feature/Source/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ class HomeViewModel: ObservableObject, OnAppearProtocol {
@Inject var outGoingRepository: any OutGoingRepository
@Inject var outSleepingRepository: any OutSleepingRepository
@Inject var nightStudyRepository: any NightStudyRepository
@Inject var scheduleRepository: any ScheduleRepository

// MARK: - Method
@MainActor
func fetchAllData() async {
async let fetchBannerData: () = await fetchBannerData()
async let fetchMealData: () = await fetchMealData()
async let fetchWakeupSongData: () = await fetchWakeupSongData()
async let fetchScheduleData: () = await fetchSchedule()

if Sign.isLoggedIn {
async let fetchOutData: () = await fetchOutData()
async let fetchNightStudy: () = await fetchNightStudy()
_ = await [fetchBannerData, fetchMealData, fetchWakeupSongData, fetchOutData, fetchNightStudy]
_ = await [fetchBannerData, fetchMealData, fetchWakeupSongData, fetchOutData, fetchNightStudy, fetchScheduleData]
} else {
_ = await [fetchBannerData, fetchMealData, fetchWakeupSongData]
_ = await [fetchBannerData, fetchMealData, fetchWakeupSongData, fetchScheduleData]
}
}

Expand All @@ -65,6 +67,7 @@ class HomeViewModel: ObservableObject, OnAppearProtocol {
outGoingData = nil
outSleepingData = nil
nightStudyData = nil
scheduleData = nil
}

@MainActor
Expand Down Expand Up @@ -162,4 +165,19 @@ class HomeViewModel: ObservableObject, OnAppearProtocol {
print(error)
}
}

@MainActor
func fetchSchedule() async {
let currentTime = Date.now
do {
scheduleData = try await scheduleRepository.fetchScheduleBetween(
.init(
startAt: "\(currentTime[.year])-\(String(format: "%.2d", currentTime[.month]))-\(String(format: "%.2d", currentTime[.day]))",
endAt: "\(currentTime[.year])-\(String(format: "%.2d", currentTime[.month]+1%12))-\(String(format: "%.2d", currentTime[.day]))"
)
)
} catch let error {
print(error)
}
}
}