Skip to content

Commit 3c41830

Browse files
authored
[Merge] #207 - 홈 캘린더 네트워크 연결
2 parents 02a184d + 151ae21 commit 3c41830

20 files changed

Lines changed: 521 additions & 74 deletions

File tree

CERTI-iOS/Application/DIContainer/AppDIContainer.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ extension AppDIContainer {
6666
func makeGetFavoritePreCertificationUseCase() -> GetFavoriteCertificationUseCase {
6767
return DefaultGetFavoriteCertificationUseCase(repository: homeRepository)
6868
}
69+
70+
func makeGetMonthlyPreCertificationUseCase() -> GetMonthlyPreCertificationUseCase {
71+
return DefaultGetMonthlyPreCertificationUseCase(repository: homeRepository)
72+
}
73+
74+
func makeGetDailyPreCertificationUseCase() -> GetDailyPreCertificationUseCase {
75+
return DefaultGetDailyPreCertificationUseCase(repository: homeRepository)
76+
}
6977

7078
func makeFetchUserInfoUseCase() -> FetchUserInfoUseCase {
7179
return DefaultFetchUserInfoUseCase(repository: userRepository)
@@ -276,7 +284,9 @@ extension AppDIContainer {
276284
fetchUserInfoUseCase: makeFetchUserInfoUseCase(),
277285
withDrawUseCase: makeWithDrawUseCase(),
278286
switchFavoriteUseCase: makeSwitchFavoriteUseCase(),
279-
fetchRecommendUseCase: makeFetchRecommendUseCase()
287+
fetchRecommendUseCase: makeFetchRecommendUseCase(),
288+
getMonthlyPreCertificationUseCase: makeGetMonthlyPreCertificationUseCase(),
289+
getDailyPreCertificationUseCase: makeGetDailyPreCertificationUseCase()
280290
)
281291
}
282292

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// DailyPreCertificationResponseDTO.swift
3+
// CERTI-iOS
4+
//
5+
// Created by nayeon on 1/30/26.
6+
//
7+
8+
typealias DailyPreCertificationResponseDTO = BaseResponseDTO<DailyPreCertificationData>
9+
10+
struct DailyPreCertificationData: Decodable {
11+
let date: String
12+
let certifications: [DailyPreCertificationInfoData]
13+
}
14+
15+
extension DailyPreCertificationData {
16+
func toDailyPreCertificationEntity() -> DailyPreCertificationEntity {
17+
return DailyPreCertificationEntity(
18+
date: date,
19+
certifications: certifications.map {
20+
$0.toDailyPreCertificationEntityData()
21+
}
22+
)
23+
}
24+
}
25+
26+
struct DailyPreCertificationInfoData: Decodable {
27+
let certificationId: Int
28+
let certificationName: String
29+
let tags: [String]
30+
let averagePeriod: String
31+
let charge: String
32+
let agencyName: String
33+
let testType: String
34+
let description: String
35+
let applicationMethod: String
36+
let applicationUrl: String
37+
let expirationPeriod: String
38+
let city: String
39+
let state: String
40+
let testDate: String
41+
let isAcquired: Bool
42+
let certificationType: String
43+
}
44+
45+
extension DailyPreCertificationInfoData {
46+
func toDailyPreCertificationEntityData() -> DailyPreCertificationEntityData {
47+
return DailyPreCertificationEntityData(
48+
certificationId: certificationId,
49+
certificationName: certificationName,
50+
tags: tags,
51+
averagePeriod: averagePeriod,
52+
charge: charge,
53+
agencyName: agencyName,
54+
testType: testType,
55+
description: description,
56+
applicationMethod: applicationMethod,
57+
applicationUrl: applicationUrl,
58+
expirationPeriod: expirationPeriod,
59+
city: city,
60+
state: state,
61+
testDate: testDate,
62+
isAcquired: isAcquired,
63+
certificationType: certificationType
64+
)
65+
}
66+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// MonthlyPreCertificationResponseDTO.swift
3+
// CERTI-iOS
4+
//
5+
// Created by nayeon on 1/30/26.
6+
//
7+
8+
typealias MonthlyPreCertificationResponseDTO = BaseResponseDTO<MonthlyPreCertificationData>
9+
10+
struct MonthlyPreCertificationData: Decodable {
11+
let year: Int
12+
let month: Int
13+
let days: [HasCertificationDaysData]
14+
}
15+
16+
extension MonthlyPreCertificationData {
17+
func toMonthlyPreCertificationEntity() -> MonthlyPreCertificationEntity {
18+
return MonthlyPreCertificationEntity(
19+
year: year,
20+
month: month,
21+
days: days.map {
22+
$0.toHasCertificationDaysEntityData()
23+
}
24+
)
25+
}
26+
}
27+
28+
struct HasCertificationDaysData: Decodable {
29+
let day: Int
30+
let count: Int
31+
}
32+
33+
extension HasCertificationDaysData {
34+
func toHasCertificationDaysEntityData() -> HasCertificationDaysEntityData {
35+
return HasCertificationDaysEntityData(
36+
day: day,
37+
count: count
38+
)
39+
}
40+
}

CERTI-iOS/Data/Network/Home/HomeAPI.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ enum HomeAPI {
1313
case getPreCertification
1414
case deletePreCertification(id: Int)
1515
case getFavoriteCertification
16+
case getMonthlyPreCertification(year: Int, month: Int)
17+
case getDailyPreCertification(date: String)
1618
case addPreCertification(request: AddPreCertificationRequestDTO)
1719
case editPreCertification(request: EditPreCertificationRequestDTO, id: Int)
1820
}
@@ -33,6 +35,10 @@ extension HomeAPI: BaseTargetType {
3335
return "home/pre-certification/\(id)"
3436
case .getFavoriteCertification:
3537
return "home/favorite"
38+
case .getMonthlyPreCertification:
39+
return "home/pre-certification/month"
40+
case .getDailyPreCertification:
41+
return "home/pre-certification/day"
3642
case .addPreCertification:
3743
return "home/pre-certification"
3844
case .editPreCertification(_, id: let id):
@@ -50,6 +56,10 @@ extension HomeAPI: BaseTargetType {
5056
return .get
5157
case .addPreCertification:
5258
return .post
59+
case .getMonthlyPreCertification:
60+
return .get
61+
case .getDailyPreCertification:
62+
return .get
5363
case .editPreCertification:
5464
return .patch
5565
}
@@ -63,6 +73,18 @@ extension HomeAPI: BaseTargetType {
6373
return .requestPlain
6474
case .getFavoriteCertification:
6575
return .requestPlain
76+
case .getMonthlyPreCertification(let year, let month):
77+
return .requestParameters(
78+
parameters: [
79+
"year": "\(year)",
80+
"month": "\(month)"],
81+
encoding: URLEncoding.queryString
82+
)
83+
case .getDailyPreCertification(let date):
84+
return .requestParameters(
85+
parameters: ["date": "\(date)"],
86+
encoding: URLEncoding.queryString
87+
)
6688
case .addPreCertification(let request):
6789
return .requestJSONEncodable(request)
6890
case .editPreCertification(let request, _):

CERTI-iOS/Data/Network/Home/HomeService.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ protocol HomeServiceProtocol {
1313
func getPreCertification() async -> Result<PreCertificationInfoResponseDTO, NetworkError>
1414
func deletePreCertification(id: Int) async -> Result<Void, NetworkError>
1515
func getFavoriteCertification() async -> Result<FavoriteCertificationResponseDTO, NetworkError>
16+
func getMonthlyPreCertification(year: Int, month: Int) async -> Result<MonthlyPreCertificationResponseDTO, NetworkError>
17+
func getDailyPreCertification(date: String) async -> Result<DailyPreCertificationResponseDTO, NetworkError>
1618
func addPreCertification(request: AddPreCertificationRequestDTO) async -> Result<BaseResponseDTO<Bool>, NetworkError>
1719
func editPreCertification(request: EditPreCertificationRequestDTO, id: Int) async -> Result<Void, NetworkError>
1820
}
@@ -37,6 +39,14 @@ final class HomeService: BaseService, HomeServiceProtocol {
3739
return await requestDecodable(provider, .addPreCertification(request: request))
3840
}
3941

42+
func getMonthlyPreCertification(year: Int, month: Int) async -> Result<MonthlyPreCertificationResponseDTO, NetworkError> {
43+
return await requestDecodable(provider, .getMonthlyPreCertification(year: year, month: month))
44+
}
45+
46+
func getDailyPreCertification(date: String) async -> Result<DailyPreCertificationResponseDTO, NetworkError> {
47+
return await requestDecodable(provider, .getDailyPreCertification(date: date))
48+
}
49+
4050
func editPreCertification(request: EditPreCertificationRequestDTO, id: Int) async -> Result<Void, NetworkError> {
4151
return await requestVoid(provider, .editPreCertification(request: request, id: id))
4252
}

CERTI-iOS/Data/Repositories/DefaultHomeRepository.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ final class DefaultHomeRepository: HomeRepository {
7373
}
7474
}
7575

76+
func getMonthlyPreCertification(year: Int, month: Int) async -> Result<MonthlyPreCertificationEntity, NetworkError> {
77+
let result = await service.getMonthlyPreCertification(year: year, month: month)
78+
switch result {
79+
case .success(let dto):
80+
guard let entity = dto.data?.toMonthlyPreCertificationEntity() else {
81+
return .failure(.decodingError)
82+
}
83+
return .success(entity)
84+
case .failure(let error):
85+
return .failure(error)
86+
}
87+
}
88+
89+
func getDailyPreCertification(date: String) async -> Result<DailyPreCertificationEntity, NetworkError> {
90+
let result = await service.getDailyPreCertification(date: date)
91+
switch result {
92+
case .success(let dto):
93+
guard let entity = dto.data?.toDailyPreCertificationEntity() else {
94+
return .failure(.decodingError)
95+
}
96+
return .success(entity)
97+
case .failure(let error):
98+
return .failure(error)
99+
}
100+
}
101+
76102
func editPreCertification(request: EditPreCertificationEntity, id: Int) async -> Result<Void, NetworkError> {
77103
let dto = EditPreCertificationRequestDTO(testDate: request.testDate, city: request.city, state: request.state)
78104
return await service.editPreCertification(request: dto, id: id)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// DailyPreCertificationEntity.swift
3+
// CERTI-iOS
4+
//
5+
// Created by nayeon on 1/30/26.
6+
//
7+
8+
struct DailyPreCertificationEntity {
9+
let date: String
10+
let certifications: [DailyPreCertificationEntityData]
11+
}
12+
13+
struct DailyPreCertificationEntityData {
14+
let certificationId: Int
15+
let certificationName: String
16+
let tags: [String]
17+
let averagePeriod: String
18+
let charge: String
19+
let agencyName: String
20+
let testType: String
21+
let description: String
22+
let applicationMethod: String
23+
let applicationUrl: String
24+
let expirationPeriod: String
25+
let city: String
26+
let state: String
27+
let testDate: String
28+
let isAcquired: Bool
29+
let certificationType: String
30+
}
31+
32+
extension DailyPreCertificationEntityData {
33+
func toCalendarPreLicenseCardModel() -> CalendarPreLicenseCardModel {
34+
return CalendarPreLicenseCardModel(
35+
certificationId: certificationId,
36+
location: city,
37+
time: testDate,
38+
title: certificationName,
39+
category: certificationType,
40+
description: description
41+
)
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MonthlyPreCertificationEntity.swift
3+
// CERTI-iOS
4+
//
5+
// Created by nayeon on 1/30/26.
6+
//
7+
8+
struct MonthlyPreCertificationEntity {
9+
let year: Int
10+
let month: Int
11+
let days: [HasCertificationDaysEntityData]
12+
}
13+
14+
struct HasCertificationDaysEntityData: Decodable {
15+
let day: Int
16+
let count: Int
17+
}

CERTI-iOS/Domain/Interfaces/Repositories/HomeRepository.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ protocol HomeRepository {
1111
func getPreCertification() async -> Result<PreCertificationEntity, NetworkError>
1212
func deletePreCertification(id: Int) async -> Result<Void, NetworkError>
1313
func getFavoriteCertification() async -> Result<FavoriteCertificationEntity, NetworkError>
14+
func getMonthlyPreCertification(year: Int, month: Int) async -> Result<MonthlyPreCertificationEntity, NetworkError>
15+
func getDailyPreCertification(date: String) async -> Result<DailyPreCertificationEntity, NetworkError>
1416
func addPreCertification(request: AddPreCertificationEntity) async -> Result<AppendPreCertificationStatus, NetworkError>
1517
func editPreCertification(request: EditPreCertificationEntity, id: Int) async -> Result<Void, NetworkError>
1618
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// GetDailyPreCertificationUseCase.swift
3+
// CERTI-iOS
4+
//
5+
// Created by nayeon on 1/30/26.
6+
//
7+
8+
protocol GetDailyPreCertificationUseCase {
9+
func execute(date: String) async -> Result<DailyPreCertificationEntity, NetworkError>
10+
}
11+
12+
final class DefaultGetDailyPreCertificationUseCase: GetDailyPreCertificationUseCase {
13+
14+
private let repository: HomeRepository
15+
16+
init(repository: HomeRepository) {
17+
self.repository = repository
18+
}
19+
20+
func execute(date: String) async -> Result<DailyPreCertificationEntity, NetworkError> {
21+
await repository.getDailyPreCertification(date: date)
22+
}
23+
24+
}

0 commit comments

Comments
 (0)