Skip to content
Merged
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
12 changes: 12 additions & 0 deletions Terning-iOS/Terning-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
2D3F7D9E2D7F345C0052B35F /* SearchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D3F7D9D2D7F344F0052B35F /* SearchService.swift */; };
2D3F7DA02D807B9F0052B35F /* MypageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D3F7D9F2D807B9D0052B35F /* MypageService.swift */; };
2D3F7DA42D807F520052B35F /* AnnouncementsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D3F7DA32D807F510052B35F /* AnnouncementsService.swift */; };
2D4EE3852C3D6E6B00E3E95B /* CustomProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EE3842C3D6E6B00E3E95B /* CustomProgressView.swift */; };
2D4EE3872C3D7CB200E3E95B /* CustomOnboardingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EE3862C3D7CB200E3E95B /* CustomOnboardingButton.swift */; };
2D4EE3892C3D9EA400E3E95B /* Date+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EE3882C3D9EA400E3E95B /* Date+.swift */; };
Expand Down Expand Up @@ -200,6 +203,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
2D3F7D9D2D7F344F0052B35F /* SearchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchService.swift; sourceTree = "<group>"; };
2D3F7D9F2D807B9D0052B35F /* MypageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MypageService.swift; sourceTree = "<group>"; };
2D3F7DA32D807F510052B35F /* AnnouncementsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementsService.swift; sourceTree = "<group>"; };
2D4EE3842C3D6E6B00E3E95B /* CustomProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProgressView.swift; sourceTree = "<group>"; };
2D4EE3862C3D7CB200E3E95B /* CustomOnboardingButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomOnboardingButton.swift; sourceTree = "<group>"; };
2D4EE3882C3D9EA400E3E95B /* Date+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1080,6 +1086,9 @@
71780C332C4572300073B731 /* Services */ = {
isa = PBXGroup;
children = (
2D3F7DA32D807F510052B35F /* AnnouncementsService.swift */,
2D3F7D9D2D7F344F0052B35F /* SearchService.swift */,
2D3F7D9F2D807B9D0052B35F /* MypageService.swift */,
71F8F8722D278C4700B822F3 /* HomeService.swift */,
2DD4DC922D1F80D10036D08D /* FiltersService.swift */,
71DE23772C7C67690024ACED /* TNCalendarService.swift */,
Expand Down Expand Up @@ -1649,6 +1658,7 @@
2DC61EFF2C40824A009F991F /* SummaryInfoTableViewCell.swift in Sources */,
71B5092D2C4326F8006D8E56 /* adjusted+.swift in Sources */,
B871D7352C3ECF37008D78C2 /* UpcomingCard.swift in Sources */,
2D3F7DA42D807F520052B35F /* AnnouncementsService.swift in Sources */,
2D4EE3A22C3E788200E3E95B /* ProfileViewModel.swift in Sources */,
2DC985F92C456F9300D46729 /* RecommendCollectionViewCell.swift in Sources */,
2D89C75F2C486E05002B035F /* GraphicCollectionViewCell.swift in Sources */,
Expand Down Expand Up @@ -1686,8 +1696,10 @@
2DC61EF32C4075E3009F991F /* JobDetailViewController.swift in Sources */,
715028692C84AA1600F67472 /* LoginRepository.swift in Sources */,
2D4EE3852C3D6E6B00E3E95B /* CustomProgressView.swift in Sources */,
2D3F7D9E2D7F345C0052B35F /* SearchService.swift in Sources */,
2DC61EF92C407E65009F991F /* JobDetailTableViewHeaderCell.swift in Sources */,
71780C352C45725E0073B731 /* Providers.swift in Sources */,
2D3F7DA02D807B9F0052B35F /* MypageService.swift in Sources */,
2DF2571A2C8DEF4E00B85843 /* LogoutViewModel.swift in Sources */,
71780C522C45A4950073B731 /* SearchTargetType.swift in Sources */,
71DE237A2C7C67890024ACED /* ScrapsService.swift in Sources */,
Expand Down
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 Terning-iOS/Terning-iOS/Data/Network/Services/MypageService.swift
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 Terning-iOS/Terning-iOS/Data/Network/Services/SearchService.swift
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()
}
}
Comment on lines +12 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service로 정리한 이 코드와, 변경하기 전(PR에 적은 긴 서버 통신 코드) 코드는 어떤 차이점이 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewModel에 존재하던 이전 서버 통신 코드에서 데이터 가공이나 UI 업데이트 코드 등을 제외하고 네트워크 호출 부분만 가져와서 Service에 넣었어요..!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 제가 말한 거는 예외 처리에서 차이가 있다!라는 것을 말씀드리려고 했습니다.

현재 코드는 filterSuccessfulStatusCodes
200에서 299번까지 성공 코드일 때만 필터가 되기 때문에
mapper 문제인지, 서버 문제인지 어디서 문제가 발생하는지 구분하는 데에 어려울 수 있다는 점 말하려고 했어요!

저도 어떻게 해야 서버 통신을 좋게 할 수 있을지 고민하고 있기 때문에 회의 때 이 부분도 말하면 좋을 것 같습니다~