-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feature] 랭킹 API 구현 및 연동
- Loading branch information
Showing
37 changed files
with
404 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
HongikYeolgong2/Data/DTO/Ranking/WeeklyRankingResponseDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// WeeklyRankingResponseDTO.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// 전체 랭킹데이터 응답 DTO | ||
struct WeeklyRankingResponseDTO: Decodable { | ||
let weekName: String | ||
let departmentRankings: [StudyRankingResponseDTO] | ||
} | ||
|
||
/// 개별학과 응답 DTO | ||
struct StudyRankingResponseDTO: Decodable { | ||
let department: String | ||
let studyDurationOfWeek: Int | ||
let currentRank: Int | ||
let rankChange: Int | ||
} |
16 changes: 16 additions & 0 deletions
16
HongikYeolgong2/Data/DTO/Weekly/WeekFieldResponseDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// WeekFieldResponseDTO.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// 날짜기준 주차 정보를 받아옵니다 | ||
/// weekNumber를 제외한 필드는 삭제예정 | ||
struct WeekFieldResponseDTO: Decodable { | ||
let year: Int | ||
let weekName: String | ||
let weekNumber: Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
HongikYeolgong2/Data/Repositories/Weekly/WeeklyRepositoryImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// WeeklyRepositoryImpl.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import Combine | ||
|
||
final class WeeklyRepositoryImpl: WeeklyRepository { | ||
func getWeekField(date: String) -> AnyPublisher<Int, NetworkError> { | ||
return Future<Int, NetworkError> { promise in | ||
Task { | ||
do { | ||
let response: BaseResponse<WeekFieldResponseDTO> = try await NetworkService.shared.request(endpoint: WeeklyEndpoint.getWeekField(date: date)) | ||
promise(.success(response.data.weekNumber)) | ||
} catch let error as NetworkError { | ||
print(error.message) | ||
promise(.failure(error)) | ||
} | ||
} | ||
}.eraseToAnyPublisher() | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
HongikYeolgong2/Domain/Entities/Ranking/WeeklyRanking.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// WeeklyRanking.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// 랭킹뷰에서 사용하는 랭킹리스트 | ||
struct WeeklyRanking { | ||
let weekName: String | ||
let departmentRankings: [RankingDepartment] | ||
|
||
init(weekName: String, departmentRankings: [RankingDepartment]) { | ||
self.weekName = weekName | ||
self.departmentRankings = departmentRankings | ||
} | ||
|
||
init() { | ||
self.weekName = "" | ||
self.departmentRankings = [] | ||
} | ||
} | ||
|
||
/// 개별학과 랭킹정보 | ||
struct RankingDepartment: Hashable { | ||
let department: String | ||
let studyDurationOfWeek: Int | ||
let currentRank: Int | ||
let rankChange: Int | ||
} |
51 changes: 51 additions & 0 deletions
51
HongikYeolgong2/Domain/Interactors/RankingDataInteractor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// RankingDataInteractor.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
protocol RankingDataInteractor { | ||
func getCurrentWeekField(yearWeek: Binding<Int>) | ||
func getWeeklyRanking(yearWeek: Int, weeklyRanking: Binding<WeeklyRanking>) | ||
} | ||
|
||
final class RankingDataInteractorImpl: RankingDataInteractor { | ||
let studySessionRepository: StudySessionRepository | ||
let weeklyRepository: WeeklyRepository | ||
let cancleBag = CancelBag() | ||
|
||
init(studySessionRepository: StudySessionRepository, weeklyRepository: WeeklyRepository) { | ||
self.studySessionRepository = studySessionRepository | ||
self.weeklyRepository = weeklyRepository | ||
} | ||
|
||
|
||
/// 현재 날짜기준 주차정보를 받아옵니다 -> 202443(2024년 43주차 정보) | ||
/// - Parameter weekNumber: 주차정보 | ||
func getCurrentWeekField(yearWeek: Binding<Int>) { | ||
weeklyRepository | ||
.getWeekField(date: Date().toDateString()) | ||
.sink(receiveCompletion: {_ in}, receiveValue: { | ||
yearWeek.wrappedValue = $0 | ||
}) | ||
.store(in: cancleBag) | ||
} | ||
|
||
/// 주차정보에 해당하는 랭킹데이터를 받아옵니다. | ||
/// - Parameters: | ||
/// - yearWeek: 주차정보 | ||
/// - weeklyRanking: 랭킹데이터 | ||
func getWeeklyRanking(yearWeek: Int, weeklyRanking: Binding<WeeklyRanking>) { | ||
studySessionRepository | ||
.getWeeklyRanking(yearWeek: yearWeek) | ||
.sink { _ in | ||
|
||
} receiveValue: { | ||
weeklyRanking.wrappedValue = $0 | ||
} | ||
.store(in: cancleBag) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// WeeklyRepository.swift | ||
// HongikYeolgong2 | ||
// | ||
// Created by 권석기 on 10/31/24. | ||
// | ||
|
||
import Combine | ||
|
||
protocol WeeklyRepository { | ||
func getWeekField(date: String) -> AnyPublisher<Int, NetworkError> | ||
} |
Oops, something went wrong.