Skip to content

Commit

Permalink
Merge pull request #108 from DeveloperAcademy-POSTECH/fix/106-page-al…
Browse files Browse the repository at this point in the history
…location-logic-issue

[#106] 페이지 계산 시 초기 페이지가 0으로 설정되는 이슈 해결
  • Loading branch information
zaehorang authored Nov 27, 2024
2 parents 99ee2d9 + cd4335f commit 59c1444
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ReadingScheduleCalculator {

var targetDate = settings.startDate
var remainderOffset = remainderPages
var cumulativePages = 0
var cumulativePages = settings.startPage

// 비독서일을 제외하고 읽어야 할 페이지를 초기 할당
while progress.getReadingRecordsKey(targetDate) <= progress.getReadingRecordsKey(settings.targetEndDate) {
Expand All @@ -37,15 +37,11 @@ struct ReadingScheduleCalculator {
while remainderOffset > 0 {
let dateKey = progress.getReadingRecordsKey(remainderTargetDate)
guard var record = progress.readingRecords[dateKey] else { return }
record.targetPages += 1
record.targetPages += remainderOffset
progress.readingRecords[dateKey] = record
remainderOffset -= 1
remainderTargetDate = Calendar.current.date(byAdding: .day, value: -1, to: remainderTargetDate)!
}

// 초기화 시 읽은 페이지 관련 데이터 초기 설정
progress.lastReadDate = nil
progress.lastPagesRead = 0
}

/// 읽은 페이지 입력 메서드 (오늘 날짜에만 값을 넣을 수 있음)
Expand Down Expand Up @@ -114,7 +110,7 @@ struct ReadingScheduleCalculator {
let dateKey = progress.getReadingRecordsKey(remainingTargetDate)

guard var record = progress.readingRecords[dateKey] else { return }
record.targetPages += 1
record.targetPages += remainderOffset
progress.readingRecords[dateKey] = record
remainderOffset -= 1

Expand Down Expand Up @@ -157,7 +153,7 @@ struct ReadingScheduleCalculator {
let dateKey = progress.getReadingRecordsKey(remainingTargetDate)
guard var record = progress.readingRecords[dateKey] else { return }

record.targetPages += 1
record.targetPages += remainderOffset
progress.readingRecords[dateKey] = record
remainderOffset -= 1
remainingTargetDate = Calendar.current.date(byAdding: .day, value: -1, to: remainingTargetDate)!
Expand Down Expand Up @@ -204,7 +200,7 @@ struct ReadingScheduleCalculator {
let totalReadingDays = firstCalculateTotalReadingDays(settings: settings, progress: progress)

// 총 페이지 수와 하루 할당량 계산
let totalPages = settings.targetEndPage - settings.startPage + 1
let totalPages = settings.targetEndPage - settings.startPage
let pagesPerDay = totalPages / totalReadingDays
let remainder = totalPages % totalReadingDays

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct FinishGoalView: View {
// TODO: 해당 모델 객체를 더 잘 만들 방식 고민하기
let bookMetaData = BookMetaData(title: book.title, author: book.author, coverURL: book.cover, totalPages: totalPages)
var userSettings = UserSettings(startPage: startPage, targetEndPage: totalPages, startDate: startDate, targetEndDate: endDate, nonReadingDays: bookSettingInputModel.nonReadingDays)
var readingProgress = ReadingProgress()
let readingProgress = ReadingProgress(lastPagesRead: startPage)
let completionStatus = CompletionStatus()

calculator.calculateInitialDailyTargets(for: userSettings, progress: readingProgress)
Expand Down

0 comments on commit 59c1444

Please sign in to comment.