Skip to content

Commit

Permalink
Feat: MyPage 비즈니스 로직 연결 (#44)
Browse files Browse the repository at this point in the history
* feat: useCase 추가 및 userEndpoint 수정

* feat: router 추가 및 view에 viewModel 데이터 연결 (#36)

* feat: mainTabRouter 수정중(#36)

* feat: user api 디코딩 에러 수정 (#36)

* feat: memeList 아이템 클릭 후 memeDetail로 넘어가기와 copy button hander 추가 (#36)

* feat: tabRouter에 mypage 연결 (#36)

* feat: 레벨 달성 조건 이미지 수정 (#36)

* etc: 파일 위치 변경 (#36)

* feat: HorizontalMimScrollView 클릭액션 추가 (#36)

* etc: test device id 추가 (#36)

* etc: 사용하지 않는 mainTabViewModel 삭제 (#36)
  • Loading branch information
hryeong66 authored Jul 17, 2024
1 parent bd69c19 commit 7206bd3
Show file tree
Hide file tree
Showing 32 changed files with 690 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ public protocol HorizontalMimItemViewProtocol: View {

public struct HorizontalMimScrollView<Item: HorizontalMimItemProtocol, ItemView: HorizontalMimItemViewProtocol>: View where ItemView.Item == Item {
@Binding public var items: [Item]

public init(items: Binding<[Item]>) {
private var itemClickHandler: ((Item) -> ())?
public init(items: Binding<[Item]>, itemClickHandler: ((Item) -> ())? = nil) {
self._items = items
self.itemClickHandler = itemClickHandler
}

public var body: some View {
ScrollView(.horizontal) {
LazyHStack(spacing: 10) {
ForEach(items, id: \.self) { item in
ItemView(item: item)
.onTapGesture {
itemClickHandler?(item)
}
}
.listStyle(.plain)
}
Expand Down
31 changes: 27 additions & 4 deletions Projects/Core/DesignSystem/Sources/View/Meme/MemeItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,53 @@ import Kingfisher

public struct MemeItemView: View {
private let memeDetail: MemeDetail
private let memeClickHandler: ((MemeDetail) -> ())?
private let memeCopyHandler: ((MemeDetail) -> ())?

public init(memeDetail: MemeDetail) {
public init(
memeDetail: MemeDetail,
memeClickHandler: ((MemeDetail) -> ())? = nil,
memeCopyHandler: ((MemeDetail) -> ())? = nil
) {
self.memeDetail = memeDetail
self.memeClickHandler = memeClickHandler
self.memeCopyHandler = memeCopyHandler
}

public var body: some View {
VStack {
MemeItemViewWithButton(imageUrlString: memeDetail.imageUrlString)
MemeItemViewWithButton(memeDetail: memeDetail, memeCopyHandler: memeCopyHandler)
.onTapGesture {
memeClickHandler?(memeDetail)
}
MemeItemInfoView(memeName: memeDetail.title, reaction: memeDetail.reaction)
}
.padding(.bottom, 20)
}
}

struct MemeItemViewWithButton: View {
let imageUrlString: String
@State private var imageHeight: CGFloat = .zero
private let memeCopyHandler: ((MemeDetail) -> ())?
private let memeDetail: MemeDetail

init(memeDetail: MemeDetail, memeCopyHandler: ((MemeDetail) -> ())?) {
self.memeDetail = memeDetail
self.memeCopyHandler = memeCopyHandler
}

var body: some View {
ZStack(alignment: .bottomLeading) {
VStack {
ResizableMemeImageView(imageUrlString: imageUrlString, imageHeight: $imageHeight)
ResizableMemeImageView(imageUrlString: memeDetail.imageUrlString, imageHeight: $imageHeight)
}
.frame(height: imageHeight)
HStack {
Spacer()
CircleCopyButton()
.onTapGesture {
memeCopyHandler?(memeDetail)
}
.padding(20)
}
}
Expand Down Expand Up @@ -74,6 +96,7 @@ struct MemeItemInfoView: View {
HStack {
VStack(alignment: .leading, spacing: 6) {
Text(memeName)
.font(Font.Body.Medium.medium)
.lineLimit(2)
if reaction > 0 {
memeReactionView
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// MemeListEmptyView.swift
// DesignSystem
//
// Created by 장혜령 on 2024/07/15.
//

import SwiftUI
import ResourceKit

public struct MemeListEmptyView: View {
let description: String

public init(description: String) {
self.description = description
}

public var body: some View {
Text(description)
.font(Font.Body.Large.medium)
.foregroundStyle(Color.Text.assistive)
.padding(.top, 50)
.padding(.bottom, 102)
}
}

34 changes: 24 additions & 10 deletions Projects/Core/DesignSystem/Sources/View/Meme/MemeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import SwiftUI
import PPACModels

public struct MemeListView: View {

private let memeDetailList: [MemeDetail]
private let columns = Array(repeating: GridItem(.flexible(),
spacing: 12,
alignment: .center),count: 2)
spacing: 12,
alignment: .center),count: 2)
private let memeClickHandler: ((MemeDetail) -> ())?
private let memeCopyHandler: ((MemeDetail) -> ())?

public init(memeDetailList: [MemeDetail]) {
public init(
memeDetailList: [MemeDetail],
memeClickHandler: ((MemeDetail) -> ())? = nil,
memeCopyHandler: ((MemeDetail) -> ())? = nil
) {
self.memeDetailList = memeDetailList
self.memeClickHandler = memeClickHandler
self.memeCopyHandler = memeCopyHandler
}


var oddIndexedItems: [MemeDetail] {
memeDetailList.enumerated().compactMap { index, element in
return index % 2 == 0 ? element : nil
Expand All @@ -38,17 +44,25 @@ public struct MemeListView: View {
HStack {
LazyVStack {
ForEach(oddIndexedItems) { memeDetail in
MemeItemView(memeDetail: memeDetail)
MemeItemView(
memeDetail: memeDetail,
memeClickHandler: memeClickHandler,
memeCopyHandler: memeCopyHandler
)
}
}

LazyVStack {
ForEach(evenIndexedItems) { memeDetail in
MemeItemView(memeDetail: memeDetail)
MemeItemView(
memeDetail: memeDetail,
memeClickHandler: memeClickHandler,
memeCopyHandler: memeCopyHandler
)
}
}
}
.frame(maxWidth: .infinity)
.frame(maxWidth: .infinity)
}
.scrollTargetBehavior(.viewAligned)
}
Expand All @@ -57,8 +71,8 @@ public struct MemeListView: View {
#Preview {
let mockImageList = ["https://plus.unsplash.com/premium_photo-1661892088256-0a17130b3d0d?q=80&w=3560&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"https://plus.unsplash.com/premium_photo-1676955432796-226f504a560b?q=80&w=3333&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"https://images.unsplash.com/photo-1720247521923-f531207d23d8?q=80&w=2667&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",

"https://images.unsplash.com/photo-1720247521923-f531207d23d8?q=80&w=2667&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"https://images.unsplash.com/photo-1507146426996-ef05306b995a?q=80&w=3540&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" ]

let memeDetailList = (0..<20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ import Foundation

struct RecommendKeywordResponseDTO: Decodable {
let category: String
let keywords: [String]
let keywords: [KeywordResponseDTO]
}

struct KeywordResponseDTO: Decodable {
let _id: String
let name: String
}
26 changes: 15 additions & 11 deletions Projects/Core/PPACData/Sources/DTO/MemeResponseDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,44 @@ struct MemeWithPaginationResponseDTO: Decodable {
struct MemeResponseDTO: Decodable {
let _id: String
let title: String
let keywordIds: [String]
let keywords: [KeywordResponseDTO]
let image: String
let reaction: Int
let source: String
let isTodayMeme: Bool
let isDeleted: Bool?
let createdAt: String
let createdAt: String?
let updatedAt: String
let isFarmemed: Bool?
let isSaved: Bool
let watch: Int

public init(
_id: String,
title: String,
keywordIds: [String],
keywords: [KeywordResponseDTO],
image: String,
reaction: Int,
source: String,
isTodayMeme: Bool,
isDeleted: Bool?,
createdAt: String,
createdAt: String?,
updatedAt: String,
isFarmemed: Bool?
) {
isSaved: Bool,
watch: Int
)
{
self._id = _id
self.title = title
self.keywordIds = keywordIds
self.keywords = keywords
self.image = image
self.reaction = reaction
self.source = source
self.isTodayMeme = isTodayMeme
self.isDeleted = isDeleted
self.createdAt = createdAt
self.updatedAt = updatedAt
self.isFarmemed = isFarmemed
self.isSaved = isSaved
self.watch = watch
}
}

Expand All @@ -69,12 +73,12 @@ extension MemeResponseDTO {
return MemeDetail(
id: self._id,
title: self.title,
keywords: self.keywordIds,
keywords: self.keywords.map { $0.name },
imageUrlString: self.image,
source: self.source,
isTodayMeme: self.isTodayMeme,
reaction: self.reaction,
isFarmemed: self.isFarmemed ?? false
isFarmemed: self.isSaved
)
}
}
29 changes: 8 additions & 21 deletions Projects/Core/PPACData/Sources/Endpoint/UserEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import PPACModels
public enum UserEndpoint: Requestable {

case create(deviceId: String)
case userDetail(deviceId: String)
case savedMeme(deviceId: String)
case lastSeenMeme(deviceId: String)
case userDetail
case savedMeme
case lastSeenMeme

public var url: String {
return "https://ppac-server.run.goorm.io/api"
Expand All @@ -34,27 +34,18 @@ public enum UserEndpoint: Requestable {
}

public var headers: [String : String]? {
switch self {
case .create(let deviceId):
return ["deviceId": deviceId]
case .userDetail(let deviceId):
return ["deviceId": deviceId]
case .savedMeme(let deviceId):
return ["deviceId": deviceId]
case .lastSeenMeme(let deviceId):
return ["deviceId": deviceId]
}
return nil
}

public var path: String? {
switch self {
case .create(_):
return "/user"
case .userDetail(_):
case .userDetail:
return "/user"
case .savedMeme(_):
case .savedMeme:
return "/user/saved-memes"
case .lastSeenMeme(_):
case .lastSeenMeme:
return "/user/recent-memes"
}
}
Expand All @@ -64,11 +55,7 @@ public enum UserEndpoint: Requestable {
case .create(let deviceId):
let createDeviceRequest = CreateUserRequestDTO(deviceId: deviceId)
return .body(createDeviceRequest)
case .userDetail(_):
return nil
case .savedMeme(_):
return nil
case .lastSeenMeme(_):
default:
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class KeywordRepositoryImpl: KeywordRepository {
case .success(let data):
guard let mimCategoryData = data.data else { throw NetworkError.dataDecodingError }
let mimCategorys = mimCategoryData
.compactMap { MimCategory(title: $0.category, categories: $0.keywords) }
.compactMap { MimCategory(title: $0.category, categories: $0.keywords.map {$0.name }) }
return mimCategorys
case .failure(let error):
throw error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public final class UserRepositoryImpl: UserRepository {
}
}

public func getUserDetail(deviceId: String) async throws -> UserDetail {
public func getUserDetail() async throws -> UserDetail {
let result = await networkservice
.request(
UserEndpoint.userDetail(deviceId: deviceId),
UserEndpoint.userDetail,
dataType: BaseDTO<UserResponseDTO>.self
)
switch result {
Expand All @@ -54,10 +54,10 @@ public final class UserRepositoryImpl: UserRepository {
}
}

public func getSavedMeme(deviceId: String) async throws -> [MemeDetail] {
public func getSavedMeme() async throws -> [MemeDetail] {
let result = await networkservice
.request(
UserEndpoint.savedMeme(deviceId: deviceId),
UserEndpoint.savedMeme,
dataType: BaseDTO<MemeWithPaginationResponseDTO>.self
)

Expand All @@ -70,10 +70,10 @@ public final class UserRepositoryImpl: UserRepository {
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PPACModels

public protocol UserRepository {
func create(deviceId: String) async throws -> UserDetail
func getUserDetail(deviceId: String) async throws -> UserDetail
func getSavedMeme(deviceId: String) async throws -> [MemeDetail]
func getLastSeenMeme(deviceId: String) async throws -> [MemeDetail]
func getUserDetail() async throws -> UserDetail
func getSavedMeme() async throws -> [MemeDetail]
func getLastSeenMeme() async throws -> [MemeDetail]
}
Loading

0 comments on commit 7206bd3

Please sign in to comment.