Skip to content

Commit

Permalink
[#25] feat: api 모델 변경 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
whrlgus committed Nov 7, 2021
1 parent abe8f6e commit bc4497f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extension Date {
func toString() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy년 MM월 dd일"
formatter.timeZone = NSTimeZone.local
return formatter.string(from: self)
}
}
11 changes: 10 additions & 1 deletion depromeet-10-5/depromeet-10-5/Network/BodyMoodAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct BodyMoodAPIService {
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo3LCJpc3MiOiJkZ2RnIiwiZXhwIjoxNjM2MzAwNDk1LCJpYXQiOjE2MzYyMTQwOTV9.b4l3ALd5GcBWul1Dwns684ZX9XMLI_GvZuH-HqFMc5w"
}

func fetchPosterList(page: Int, size: Int) -> AnyPublisher<[PosterPhotoResponseModel], Error> {
func fetchPosterList(page: Int, size: Int) -> AnyPublisher<PosterPhotoListResponseModel, Error> {
let url = URL(string: "\(baseURL)/api/v1/posters?page=\(page)&size=\(size)")
return URLRequest(url: url!)
.setHttpMethod(.GET)
Expand Down Expand Up @@ -98,9 +98,18 @@ struct BodyMoodAPIResponse<Data: Decodable>: Decodable {
let data: Data
}

struct PosterPhotoListResponseModel: Decodable, Hashable {
let totalCount: Int
let pageTotalCount: Int
let pagePosition: Int
let posters: [PosterPhotoResponseModel]
}

struct PosterPhotoResponseModel: Decodable, Hashable {
let photoId: Int
let imageUrl: String
let createdAt: String
let updatedAt: String
}

struct PosterAddResponseModel: Decodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class PosterListViewModel: PosterListViewModelType {
@discardableResult
func loadImage() -> AnyPublisher<Bool, Never> {
let finished = CurrentValueSubject<Bool, Never>(false)
fetchSubscription = useCase.fetch(page: 0, size: 10)
fetchSubscription = useCase.fetch(page: 0, size: 100)
.sink(receiveCompletion: { _ in
}, receiveValue: { [weak self] list in
self?.postersSubject.send(list)
self?.postersSubject.send(list.posters)
finished.send(true)
})
return finished.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Photos
import Combine

protocol PosterUseCaseType {
func fetch(page: Int, size: Int) -> AnyPublisher<[PosterPhotoResponseModel], Error>
func fetch(page: Int, size: Int) -> AnyPublisher<PosterPhotoListResponseModel, Error>
}

class PosterUseCase: PosterUseCaseType {

func fetch(page: Int, size: Int) -> AnyPublisher<[PosterPhotoResponseModel], Error> {
func fetch(page: Int, size: Int) -> AnyPublisher<PosterPhotoListResponseModel, Error> {
BodyMoodAPIService.shared.fetchPosterList(page: page, size: size)
}
}

0 comments on commit bc4497f

Please sign in to comment.