Skip to content

Commit

Permalink
Merge pull request #84 from mash-up-kr/feature/#82-my-registered-meme…
Browse files Browse the repository at this point in the history
…-hyerjang

feat: 내가 올린 밈 api 연결
  • Loading branch information
hryeong66 authored Oct 3, 2024
2 parents 26670fc + 84a4c4b commit c136550
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Projects/Core/PPACData/Sources/DTO/MemeResponseDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct MemeResponseDTO: Decodable {
updatedAt: String,
isSaved: Bool,
isReaction: Bool,
watch: Int
watch: Int?
)
{
self._id = _id
Expand Down
25 changes: 17 additions & 8 deletions Projects/Core/PPACData/Sources/Endpoint/UserEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ public enum UserEndpoint: Requestable {

case create(deviceId: String)
case userDetail
case savedMeme(page: Int, size: Int)
case lastSeenMeme
case savedMeme(page: Int, size: Int)
case registeredMemes(page: Int, size: Int)


public var httpMethod: PPACNetwork.HTTPMethod {
switch self {
case .create:
return .post
case .userDetail:
return .get
case .savedMeme:
return .get
case .lastSeenMeme:
case .userDetail,
.lastSeenMeme,
.savedMeme,
.registeredMemes:
return .get
}
}
Expand All @@ -39,10 +40,12 @@ public enum UserEndpoint: Requestable {
return "/user"
case .userDetail:
return "/user"
case .savedMeme:
return "/user/saved-memes"
case .lastSeenMeme:
return "/user/recent-memes"
case .savedMeme:
return "/user/saved-memes"
case .registeredMemes:
return "/user/registered-memes"
}
}

Expand All @@ -57,6 +60,12 @@ public enum UserEndpoint: Requestable {
"size" : "\(size)"
]
return .query(parameters)
case .registeredMemes(let page, let size):
let parameters: [String: String] = [
"page" : "\(page)",
"size" : "\(size)"
]
return .query(parameters)
default:
return nil
}
Expand Down
38 changes: 32 additions & 6 deletions Projects/Core/PPACData/Sources/Repository/UserRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public final class UserRepositoryImpl: UserRepository {
}
}

public func getLastSeenMeme() async throws -> [MemeDetail] {
let result = await networkservice
.request(
UserEndpoint.lastSeenMeme,
dataType: BaseDTO<[MemeResponseDTO]>.self
)

switch result {
case .success(let data):
guard let memeResponseDTOList = data.data else { throw NetworkError.dataDecodingError }
return memeResponseDTOList.map { $0.toModel() }
case .failure(let error):
throw error
}
}

public func getSavedMeme(page: Int, size: Int) async throws -> MemeListWithPagination {
let result = await networkservice
.request(
Expand All @@ -64,7 +80,7 @@ public final class UserRepositoryImpl: UserRepository {
switch result {
case .success(let data):
guard let memeWithPaginationResponseDTO = data.data else { throw NetworkError.dataDecodingError }
var result = memeWithPaginationResponseDTO.toModel()
let result = memeWithPaginationResponseDTO.toModel()
let memeList = result.memeList
.map {
var meme = $0
Expand All @@ -80,17 +96,27 @@ public final class UserRepositoryImpl: UserRepository {
}
}

public func getLastSeenMeme() async throws -> [MemeDetail] {
public func getRegisteredMeme(page: Int, size: Int) async throws -> MemeListWithPagination {
let result = await networkservice
.request(
UserEndpoint.lastSeenMeme,
dataType: BaseDTO<[MemeResponseDTO]>.self
UserEndpoint.registeredMemes(page: page, size: size),
dataType: BaseDTO<MemeWithPaginationResponseDTO>.self
)

switch result {
case .success(let data):
guard let memeResponseDTOList = data.data else { throw NetworkError.dataDecodingError }
return memeResponseDTOList.map { $0.toModel() }
guard let memeWithPaginationResponseDTO = data.data else { throw NetworkError.dataDecodingError }
let result = memeWithPaginationResponseDTO.toModel()
let memeList = result.memeList
.map {
var meme = $0
meme.reaction = 0
return meme
}
return MemeListWithPagination(
pagination: result.pagination,
memeList: memeList
)
case .failure(let error):
throw error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PPACModels
public protocol UserRepository {
func create(deviceId: String) async throws -> UserDetail
func getUserDetail() async throws -> UserDetail
func getSavedMeme(page: Int, size: Int) async throws -> MemeListWithPagination
func getLastSeenMeme() async throws -> [MemeDetail]
func getSavedMeme(page: Int, size: Int) async throws -> MemeListWithPagination
func getRegisteredMeme(page: Int, size: Int) async throws -> MemeListWithPagination
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class MockCheckUserInfoUseCase: CheckUserInfoUseCase {
func create(deviceId: String) async throws -> UserDetail { return UserDetail.mock }
func getUserDetail() async throws -> UserDetail { return UserDetail.mock }
func getSavedMeme(page: Int, size: Int) async throws -> MemeListWithPagination { return MemeListWithPagination.mock }
func getRegisteredMeme(page: Int, size: Int) async throws -> MemeListWithPagination { return MemeListWithPagination.mock }
func getLastSeenMeme() async throws -> [MemeDetail] { return [] }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// GetRegisteredMemeUseCase.swift
// PPACDomain
//
// Created by 장혜령 on 10/2/24.
//

import Foundation
import PPACModels

public protocol GetRegisteredMemeUseCase {
func execute(page: Int, size: Int) async throws -> MemeListWithPagination
}

public class GetRegisteredMemeUseCaseImpl: GetRegisteredMemeUseCase {
public let userRepository: UserRepository

public init(userRepository: UserRepository) {
self.userRepository = userRepository
}

public func execute(page: Int, size: Int) async throws -> MemeListWithPagination {
return try await self.userRepository.getRegisteredMeme(page: page, size: size)
}
}

1 change: 1 addition & 0 deletions Projects/Features/MyPage/Sources/MyPageRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class MyPageRouter: Router, MyPageRouting {
getUserDetailUseCase: GetUserDetailUseCaseImpl(userRepository: repository),
getLastSeenMemeUseCase: GetLastSeenMemeUseCaseImpl(userRepository: repository),
getSavedMemeUseCase: GetSavedMemeUseCaseImpl(userRepository: repository),
getRegisteredMemeUseCase: GetRegisteredMemeUseCaseImpl(userRepository: repository),
copyImageUseCase: CopyImageUseCaseImpl()
)
).tabBar(selectedTab: selectedTab)
Expand Down
16 changes: 15 additions & 1 deletion Projects/Features/MyPage/Sources/MyPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct MyPageView: View {
viewModel.dispatch(type: .onTappedSegmentedTitleItem(title: title))
}
)
SavedMemeListView(
MemeListView(
memeDetailList: $viewModel.state.currentMyMemeList,
memeClickHandler: { meme in
viewModel.dispatch(type: .onTappedSavedMeme(meme: meme))
Expand All @@ -49,7 +49,21 @@ public struct MyPageView: View {
viewModel.dispatch(type: .onAppearLastMeme)
}
)
.padding(.horizontal, 20)
.padding(.bottom, 138)
// SavedMemeListView(
// memeDetailList: $viewModel.state.currentMyMemeList,
// memeClickHandler: { meme in
// viewModel.dispatch(type: .onTappedSavedMeme(meme: meme))
// },
// memeCopyHandler: { meme in
// viewModel.dispatch(type: .onTappedCopyButton(meme: meme))
// },
// onAppearLastMemeHandler: {
// viewModel.dispatch(type: .onAppearLastMeme)
// }
// )
// .padding(.bottom, 138)
}
.onAppear {
viewModel.dispatch(type: .onAppearMyPageView)
Expand Down
Loading

0 comments on commit c136550

Please sign in to comment.