-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] #271 - 서비스 레이어 추가했습니다. #272
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
Terning-iOS/Terning-iOS/Data/Network/Services/AnnouncementsService.swift
This file contains hidden or 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,31 @@ | ||
| // | ||
| // AnnouncementsService.swift | ||
| // Terning-iOS | ||
| // | ||
| // Created by 정민지 on 3/11/25. | ||
| // | ||
|
|
||
| import RxSwift | ||
| import Moya | ||
| import RxMoya | ||
|
|
||
| protocol AnnouncementsServiceProtocol { | ||
| func getDetailAnnouncements(internshipAnnouncementId: Int) -> Observable<JobDetailModel> | ||
| } | ||
|
|
||
| final class AnnouncementsService: AnnouncementsServiceProtocol { | ||
|
|
||
| private let provider: MoyaProvider<AnnouncementsTargetType> | ||
|
|
||
| init(provider: MoyaProvider<AnnouncementsTargetType>) { | ||
| self.provider = provider | ||
| } | ||
|
|
||
| func getDetailAnnouncements(internshipAnnouncementId: Int) -> Observable<JobDetailModel> { | ||
| return provider.rx.request(.getAnnouncements(internshipAnnouncementId: internshipAnnouncementId)) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<JobDetailModel>.self) | ||
| .compactMap { $0.result } | ||
| .asObservable() | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
Terning-iOS/Terning-iOS/Data/Network/Services/MypageService.swift
This file contains hidden or 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,39 @@ | ||
| // | ||
| // MypageService.swift | ||
| // Terning-iOS | ||
| // | ||
| // Created by 정민지 on 3/11/25. | ||
| // | ||
|
|
||
| import RxSwift | ||
| import Moya | ||
| import RxMoya | ||
|
|
||
| protocol MypageServiceProtocol { | ||
| func getProfileInfo() -> Observable<UserProfileInfoModel> | ||
| func patchProfileInfo(name: String, profileImage: String) -> Observable<Void> | ||
| } | ||
|
|
||
| final class MypageService: MypageServiceProtocol { | ||
|
|
||
| private let provider: MoyaProvider<MyPageTargetType> | ||
|
|
||
| init(provider: MoyaProvider<MyPageTargetType>) { | ||
| self.provider = provider | ||
| } | ||
|
|
||
| func getProfileInfo() -> Observable<UserProfileInfoModel> { | ||
| return provider.rx.request(.getProfileInfo) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<UserProfileInfoModel>.self) | ||
| .compactMap { $0.result } | ||
| .asObservable() | ||
| } | ||
|
|
||
| func patchProfileInfo(name: String, profileImage: String) -> Observable<Void> { | ||
| return provider.rx.request(.patchProfileInfo(name: name, profileImage: profileImage)) | ||
| .filterSuccessfulStatusCodes() | ||
| .map { _ in () } | ||
| .asObservable() | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
Terning-iOS/Terning-iOS/Data/Network/Services/SearchService.swift
This file contains hidden or 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,58 @@ | ||
| // | ||
| // SearchService.swift | ||
| // Terning-iOS | ||
| // | ||
| // Created by 정민지 on 3/10/25. | ||
| // | ||
|
|
||
| import RxSwift | ||
| import Moya | ||
| import RxMoya | ||
|
|
||
| protocol SearchServiceProtocol { | ||
| func getSearchResult(keyword: String, sortBy: String, page: Int, size: Int) -> Observable<SearchResultModel> | ||
| func getMostViewDatas() -> Observable<[RecommendAnnouncement]> | ||
| func getMostScrapDatas() -> Observable<[RecommendAnnouncement]> | ||
| func getAdvertiseDatas() -> Observable<[BannerModel]> | ||
| } | ||
|
|
||
| final class SearchService: SearchServiceProtocol { | ||
|
|
||
| private let provider: MoyaProvider<SearchTargetType> | ||
|
|
||
| init(provider: MoyaProvider<SearchTargetType>) { | ||
| self.provider = provider | ||
| } | ||
|
|
||
| func getSearchResult(keyword: String, sortBy: String, page: Int, size: Int) -> Observable<SearchResultModel> { | ||
| return provider.rx.request(.getSearchResult(keyword: keyword, sortBy: sortBy, page: page, size: size)) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<SearchResultModel>.self) | ||
| .compactMap { $0.result } | ||
| .asObservable() | ||
| } | ||
|
|
||
| func getMostViewDatas() -> Observable<[RecommendAnnouncement]> { | ||
| return provider.rx.request(.getMostViewDatas) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<RecommendAnnouncementModel>.self) | ||
| .compactMap { $0.result?.announcements } | ||
| .asObservable() | ||
| } | ||
|
|
||
| func getMostScrapDatas() -> Observable<[RecommendAnnouncement]> { | ||
| return provider.rx.request(.getMostScrapDatas) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<RecommendAnnouncementModel>.self) | ||
| .compactMap { $0.result?.announcements } | ||
| .asObservable() | ||
| } | ||
|
|
||
| func getAdvertiseDatas() -> Observable<[BannerModel]> { | ||
| return provider.rx.request(.getAdvertiseDatas) | ||
| .filterSuccessfulStatusCodes() | ||
| .map(BaseResponse<AdvertisementModel>.self) | ||
| .compactMap { $0.result?.banners } | ||
| .asObservable() | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service로 정리한 이 코드와, 변경하기 전(PR에 적은 긴 서버 통신 코드) 코드는 어떤 차이점이 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel에 존재하던 이전 서버 통신 코드에서 데이터 가공이나 UI 업데이트 코드 등을 제외하고 네트워크 호출 부분만 가져와서 Service에 넣었어요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 제가 말한 거는 예외 처리에서 차이가 있다!라는 것을 말씀드리려고 했습니다.
현재 코드는
filterSuccessfulStatusCodes200에서 299번까지 성공 코드일 때만 필터가 되기 때문에
mapper 문제인지, 서버 문제인지 어디서 문제가 발생하는지 구분하는 데에 어려울 수 있다는 점 말하려고 했어요!
저도 어떻게 해야 서버 통신을 좋게 할 수 있을지 고민하고 있기 때문에 회의 때 이 부분도 말하면 좋을 것 같습니다~