Skip to content
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

feat: 커서 페이징 적용 #364

Merged
merged 11 commits into from
Feb 22, 2024
22 changes: 16 additions & 6 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
839F1DF82B62AEDA0071C622 /* LOTextLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839F1DF72B62AEDA0071C622 /* LOTextLabel.swift */; };
83C35E1B2B108C3500D8DD5C /* PlaybackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */; };
83C35E1E2B10923C00D8DD5C /* PlaybackCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */; };
FC06392E2B83D3F00019E4FB /* PostsPage.json in Resources */ = {isa = PBXBuildFile; fileRef = FC06392D2B83D3F00019E4FB /* PostsPage.json */; };
FC0E80242B1A0BBB00EF56D6 /* UploadPostPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */; };
FC0E80252B1A0BBB00EF56D6 /* UploadPostWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E801F2B1A0BBB00EF56D6 /* UploadPostWorker.swift */; };
FC0E80262B1A0BBB00EF56D6 /* UploadPostRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E80202B1A0BBB00EF56D6 /* UploadPostRouter.swift */; };
Expand Down Expand Up @@ -199,6 +200,8 @@
FC4084CA2B1F291200CE4727 /* UploadVideoDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4084C92B1F291200CE4727 /* UploadVideoDTO.swift */; };
FC4084CC2B1F2F5D00CE4727 /* UploadPost.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4084CB2B1F2F5D00CE4727 /* UploadPost.swift */; };
FC42E4142B17AB69005D4956 /* VideoFileWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC42E4132B17AB69005D4956 /* VideoFileWorker.swift */; };
FC43D9DA2B6F773C00FD9BCB /* PostsPageDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC43D9D92B6F773C00FD9BCB /* PostsPageDTO.swift */; };
FC43D9DC2B73935B00FD9BCB /* PostsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC43D9DB2B73935B00FD9BCB /* PostsPage.swift */; };
FC49758F2B03432800D8627F /* Pretendard-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FC4975862B03432700D8627F /* Pretendard-SemiBold.ttf */; };
FC4975932B03432800D8627F /* Pretendard-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FC49758A2B03432800D8627F /* Pretendard-Bold.ttf */; };
FC4975942B03432800D8627F /* Pretendard-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FC49758B2B03432800D8627F /* Pretendard-Regular.ttf */; };
Expand Down Expand Up @@ -245,7 +248,6 @@
FC7E45462AFEB62B004F155A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC7E45442AFEB62B004F155A /* LaunchScreen.storyboard */; };
FC7E456A2AFEC06E004F155A /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = FC7E45692AFEC06E004F155A /* .swiftlint.yml */; };
FC8696D32B26008B00F9A7B9 /* SettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33972B1843BE00ECAFB0 /* SettingViewController.swift */; };
FC8DC42A2B5A5B7600FC772A /* LOImageCacher in Frameworks */ = {isa = PBXBuildFile; productRef = FC8DC4292B5A5B7600FC772A /* LOImageCacher */; };
FC8DC42F2B5A5C4600FC772A /* LOImageCacher in Frameworks */ = {isa = PBXBuildFile; productRef = FC8DC42E2B5A5C4600FC772A /* LOImageCacher */; };
FC930E752B0CD75C00AA48E3 /* ProfilePresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC930E6F2B0CD75C00AA48E3 /* ProfilePresenter.swift */; };
FC930E772B0CD75C00AA48E3 /* ProfileRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC930E712B0CD75C00AA48E3 /* ProfileRouter.swift */; };
Expand Down Expand Up @@ -430,6 +432,7 @@
839F1DF72B62AEDA0071C622 /* LOTextLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOTextLabel.swift; sourceTree = "<group>"; };
83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackView.swift; sourceTree = "<group>"; };
83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackCell.swift; sourceTree = "<group>"; };
FC06392D2B83D3F00019E4FB /* PostsPage.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = PostsPage.json; sourceTree = "<group>"; };
FC0E801E2B1A0BBB00EF56D6 /* UploadPostPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostPresenter.swift; sourceTree = "<group>"; };
FC0E801F2B1A0BBB00EF56D6 /* UploadPostWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostWorker.swift; sourceTree = "<group>"; };
FC0E80202B1A0BBB00EF56D6 /* UploadPostRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPostRouter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -468,6 +471,8 @@
FC4084C92B1F291200CE4727 /* UploadVideoDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadVideoDTO.swift; sourceTree = "<group>"; };
FC4084CB2B1F2F5D00CE4727 /* UploadPost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadPost.swift; sourceTree = "<group>"; };
FC42E4132B17AB69005D4956 /* VideoFileWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoFileWorker.swift; sourceTree = "<group>"; };
FC43D9D92B6F773C00FD9BCB /* PostsPageDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsPageDTO.swift; sourceTree = "<group>"; };
FC43D9DB2B73935B00FD9BCB /* PostsPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsPage.swift; sourceTree = "<group>"; };
FC4975862B03432700D8627F /* Pretendard-SemiBold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-SemiBold.ttf"; sourceTree = "<group>"; };
FC49758A2B03432800D8627F /* Pretendard-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Bold.ttf"; sourceTree = "<group>"; };
FC49758B2B03432800D8627F /* Pretendard-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Regular.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -681,6 +686,7 @@
194C21CE2B1DF63D00C62645 /* MockDatas */ = {
isa = PBXGroup;
children = (
FC06392D2B83D3F00019E4FB /* PostsPage.json */,
FC4E0C122B28609C00152596 /* PostBoard.json */,
192513972B278645001533FA /* CheckSignUp.json */,
1925138D2B278645001533FA /* CheckUserName.json */,
Expand Down Expand Up @@ -740,6 +746,7 @@
isa = PBXGroup;
children = (
19A1692C2B17750B00DB34C0 /* Post.swift */,
FC43D9DB2B73935B00FD9BCB /* PostsPage.swift */,
19A169412B17C70C00DB34C0 /* Member.swift */,
19A169432B17C71C00DB34C0 /* Board.swift */,
FC4084CB2B1F2F5D00CE4727 /* UploadPost.swift */,
Expand Down Expand Up @@ -781,6 +788,7 @@
FC767F942B1222350088CF9B /* ProfileImageDTO.swift */,
FC767F962B1224B80088CF9B /* IntroduceDTO.swift */,
19A169372B17BCA800DB34C0 /* PostDTO.swift */,
FC43D9D92B6F773C00FD9BCB /* PostsPageDTO.swift */,
19A169392B17BCC400DB34C0 /* MemberDTO.swift */,
19A1693B2B17BD1C00DB34C0 /* BoardDTO.swift */,
8321A2FE2B1E428C000A12AF /* ReportDTO.swift */,
Expand Down Expand Up @@ -1305,7 +1313,6 @@
name = Layover;
packageProductDependencies = (
194551FC2B0386D100299768 /* KakaoSDK */,
FC8DC4292B5A5B7600FC772A /* LOImageCacher */,
19AF2A052B5D06B9008C3620 /* HLSCachingServer */,
);
productName = Layover;
Expand Down Expand Up @@ -1419,6 +1426,7 @@
1925139C2B278645001533FA /* DeleteVideo.json in Resources */,
1925139F2B278646001533FA /* PostListMore.json in Resources */,
1925139A2B278645001533FA /* PostList.json in Resources */,
FC06392E2B83D3F00019E4FB /* PostsPage.json in Resources */,
192513992B278645001533FA /* PostListEnd.json in Resources */,
192513A12B278646001533FA /* DeleteUser.json in Resources */,
192513A22B278646001533FA /* ReportPlaybackVideo.json in Resources */,
Expand Down Expand Up @@ -1492,6 +1500,7 @@
194552282B0479B600299768 /* BaseViewController.swift in Sources */,
194552212B0478B400299768 /* HomePresenter.swift in Sources */,
1972CCDA2B13A4BA00C3C762 /* SignUpWorker.swift in Sources */,
FC43D9DA2B6F773C00FD9BCB /* PostsPageDTO.swift in Sources */,
1945520D2B0399E500299768 /* MainTabBarViewController.swift in Sources */,
FC2511AB2B04EA6B004717BC /* MapConfigurator.swift in Sources */,
1945523B2B05258200299768 /* HomeConfigurator.swift in Sources */,
Expand All @@ -1516,6 +1525,7 @@
194552242B0478B400299768 /* HomeModels.swift in Sources */,
8321A3012B1F1EC5000A12AF /* MockReportWorker.swift in Sources */,
19A1692D2B17750B00DB34C0 /* Post.swift in Sources */,
FC43D9DC2B73935B00FD9BCB /* PostsPage.swift in Sources */,
194552022B038B8300299768 /* OSLog+.swift in Sources */,
8321A2F92B1E15F3000A12AF /* LOReportStackView.swift in Sources */,
FC0E80272B1A0BBB00EF56D6 /* UploadPostModels.swift in Sources */,
Expand Down Expand Up @@ -1991,15 +2001,15 @@
package = 194551FB2B03863B00299768 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */;
productName = KakaoSDK;
};
FC8DC42E2B5A5C4600FC772A /* LOImageCacher */ = {
isa = XCSwiftPackageProductDependency;
productName = LOImageCacher;
};
19AF2A052B5D06B9008C3620 /* HLSCachingServer */ = {
isa = XCSwiftPackageProductDependency;
package = 19AF2A042B5D06B9008C3620 /* XCRemoteSwiftPackageReference "HLSCachingServer" */;
productName = HLSCachingServer;
};
FC8DC42E2B5A5C4600FC772A /* LOImageCacher */ = {
isa = XCSwiftPackageProductDependency;
productName = LOImageCacher;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = FC7E452E2AFEB623004F155A /* Project object */;
Expand Down
14 changes: 14 additions & 0 deletions iOS/Layover/Layover/Models/PostsPage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// PostsPage.swift
// Layover
//
// Created by kong on 2024/02/07.
// Copyright © 2024 CodeBomber. All rights reserved.
//

import Foundation

struct PostsPage {
let cursor: Int
let posts: [Post]
}
33 changes: 33 additions & 0 deletions iOS/Layover/Layover/Network/DTOs/PostsPageDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// PostsPageDTO.swift
// Layover
//
// Created by kong on 2024/02/04.
// Copyright © 2024 CodeBomber. All rights reserved.
//

import Foundation

struct PostsPageDTO: Decodable {
let lastID: Int
let posts: [PostDTO]

enum CodingKeys: String, CodingKey {
case lastID = "lastId"
case posts = "boardsResDto"
}
}

struct PostRequestDTO: Encodable {
let cursor: Int?
let memberId: String?
}

extension PostsPageDTO {
func toDomain() -> PostsPage {
return PostsPage(
cursor: lastID,
posts: posts.map { $0.toDomain() }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
import Foundation

protocol PostEndPointFactory {
func makeHomePostListEndPoint() -> EndPoint<Response<[PostDTO]>>
func makeHomePostListEndPoint(at cursor: Int?) -> EndPoint<Response<PostsPageDTO>>
func makeMapPostListEndPoint(latitude: Double, longitude: Double) -> EndPoint<Response<[PostDTO]>>
func makeTagSearchPostListEndPoint(of tag: String, at page: Int) -> EndPoint<Response<[PostDTO]>>
}

final class DefaultPostEndPointFactory: PostEndPointFactory {
func makeHomePostListEndPoint() -> EndPoint<Response<[PostDTO]>> {
return EndPoint(
path: "/board/home",
method: .GET
)
func makeHomePostListEndPoint(at cursor: Int?) -> EndPoint<Response<PostsPageDTO>> {
var queryParameters: [String: Int]?
if let cursor {
queryParameters?.updateValue(cursor, forKey: "cursor")
}
return EndPoint(path: "/board/home",
method: .GET,
queryParameters: queryParameters)
}

func makeMapPostListEndPoint(latitude: Double, longitude: Double) -> EndPoint<Response<[PostDTO]>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol UserEndPointFactory {
func makeIntroduceModifyEndPoint(introduce: String) -> EndPoint<Response<IntroduceDTO>>
func makeUserWithDrawEndPoint() -> EndPoint<Response<NicknameDTO>>
func makeUserInformationEndPoint(with id: Int?) -> EndPoint<Response<MemberDTO>>
func makeUserPostsEndPoint(at page: Int, of id: Int?) -> EndPoint<Response<[PostDTO]>>
func makeUserPostsEndPoint(at cursor: Int?, of id: Int?) -> EndPoint<Response<PostsPageDTO>>
func makeUserProfileImageDefaultEndPoint() -> EndPoint<Response<Data>>
func makeFetchUserProfilePresignedURL(of fileType: String) -> EndPoint<Response<PresignedURLDTO>>
}
Expand Down Expand Up @@ -76,12 +76,14 @@ final class DefaultUserEndPointFactory: UserEndPointFactory {
)
}

func makeUserPostsEndPoint(at page: Int, of id: Int? = nil) -> EndPoint<Response<[PostDTO]>> {
var queryParameters = [String: String]()
queryParameters.updateValue(String(page), forKey: "page")

func makeUserPostsEndPoint(at cursor: Int?, of id: Int? = nil) -> EndPoint<Response<PostsPageDTO>> {
var queryParameters: PostRequestDTO?
if let id {
queryParameters.updateValue(String(id), forKey: "memberId")
queryParameters = PostRequestDTO(cursor: cursor,
memberId: String(id))
} else {
queryParameters = PostRequestDTO(cursor: cursor,
memberId: nil)
}

return EndPoint(
Expand Down
4 changes: 0 additions & 4 deletions iOS/Layover/Layover/Network/Provider/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ extension ProviderType {
method: method)
}

func upload(from fileURL: URL, to url: String, method: HTTPMethod = .PUT) async throws -> Data {
return try await upload(from: fileURL, to: url, method: method)
}

func upload(fromFile: URL,
to url: String,
method: HTTPMethod = .PUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ extension EditProfileViewController: PHPickerViewControllerDelegate {
}
}
}.resume()
picker.deselectAssets(withIdentifiers: results.compactMap(\.assetIdentifier))
}
picker.deselectAssets(withIdentifiers: results.compactMap(\.assetIdentifier))
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions iOS/Layover/Layover/Scenes/Home/HomeInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import UIKit
protocol HomeBusinessLogic {
@discardableResult
func fetchPosts(with request: HomeModels.FetchPosts.Request) async -> Bool
@discardableResult
func fetchMorePosts() async -> Bool
func playPosts(with request: HomeModels.PlayPosts.Request)
func fetchLocationAuthorizationStatus()
func selectVideo(with request: HomeModels.SelectVideo.Request)
Expand All @@ -36,6 +38,8 @@ final class HomeInteractor: HomeDataStore {
var homeWorker: HomeWorkerProtocol?
var presenter: HomePresentationLogic?
var locationManager: CurrentLocationManager?
var postPageLastID: Int?
var canFetchMorePosts = true

// MARK: - DataStore

Expand All @@ -51,14 +55,31 @@ extension HomeInteractor: HomeBusinessLogic {

@discardableResult
func fetchPosts(with request: Models.FetchPosts.Request) async -> Bool {
guard let posts = await homeWorker?.fetchPosts() else { return false }
let response = Models.FetchPosts.Response(posts: posts)

guard let postsPage = await homeWorker?.fetchPosts() else { return false }
let response = Models.FetchPosts.Response(cursor: postsPage.cursor,
posts: postsPage.posts)
self.postPageLastID = response.cursor
await MainActor.run {
self.posts = posts
self.posts = response.posts
presenter?.presentPosts(with: response)
}
return true
}

@discardableResult
func fetchMorePosts() async -> Bool {
if canFetchMorePosts {
canFetchMorePosts = false
guard let postsPage = await homeWorker?.fetchMorePosts(at: postPageLastID) else { return false }
let response = Models.FetchPosts.Response(cursor: postsPage.cursor,
posts: postsPage.posts)
self.postPageLastID = response.cursor
await MainActor.run {
self.posts = response.posts
presenter?.presentMorePosts(with: response)
}
canFetchMorePosts = true
}
return true
}

Expand Down
1 change: 1 addition & 0 deletions iOS/Layover/Layover/Scenes/Home/HomeModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum HomeModels {
}

struct Response {
let cursor: Int
let posts: [Post]
}

Expand Down
18 changes: 18 additions & 0 deletions iOS/Layover/Layover/Scenes/Home/HomePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit

protocol HomePresentationLogic {
func presentPosts(with response: HomeModels.FetchPosts.Response)
func presentMorePosts(with response: HomeModels.FetchPosts.Response)
func presentPlaybackScene(with response: HomeModels.PlayPosts.Response)
func presentTagPlayList(with response: HomeModels.ShowTagPlayList.Response)
func presentUploadScene()
Expand Down Expand Up @@ -43,6 +44,23 @@ final class HomePresenter: HomePresentationLogic {
viewController?.displayPosts(with: viewModel)
}

func presentMorePosts(with response: Models.FetchPosts.Response) {
var displayedPosts = [Models.DisplayedPost]()

for post in response.posts {
guard let thumbnailURL = post.board.thumbnailImageURL,
let videoURL = post.board.videoURL else { continue }
let displayedPost = Models.DisplayedPost(thumbnailImageURL: thumbnailURL,
videoURL: videoURL,
title: post.board.title,
tags: post.tag)
displayedPosts.append(displayedPost)
}

let viewModel = Models.FetchPosts.ViewModel(displayedPosts: displayedPosts)
viewController?.displayMorePosts(with: viewModel)
}

// MARK: - UseCase Present PlaybackScene

func presentPlaybackScene(with response: HomeModels.PlayPosts.Response) {
Expand Down
Loading
Loading