Skip to content

Commit

Permalink
Merge pull request #53 from mash-up-kr/feature/#52-아이콘화면
Browse files Browse the repository at this point in the history
feat: 밈 저장 취소 및 아이콘 변경 기능 추가
  • Loading branch information
jongnan authored Jul 27, 2024
2 parents 841bd77 + 4186a1f commit 338c53d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 40 deletions.
7 changes: 7 additions & 0 deletions Projects/Core/PPACData/Sources/Endpoint/MemeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum MemeEndpoint: Requestable {
case getSearchKeywordMemeList(keyword: String)
case meme(memeId: String)
case bookmark(memeId: String)
case deleteBookmark(memeId: String)
case share(memeId: String)
case watch(memeId: String, type: String)
case reaction(memeId: String)
Expand All @@ -33,6 +34,8 @@ public enum MemeEndpoint: Requestable {
return .get
case .bookmark:
return .post
case .deleteBookmark:
return .delete
case .share:
return .post
case .watch:
Expand All @@ -56,6 +59,8 @@ public enum MemeEndpoint: Requestable {
return "/meme/\(memeId)"
case .bookmark(let memeId):
return "/meme/\(memeId)/save"
case .deleteBookmark(let memeId):
return "/meme/\(memeId)/save"
case .share(let memeId):
return "/meme/\(memeId)/share"
case .watch(let memeId, let type):
Expand All @@ -73,6 +78,8 @@ public enum MemeEndpoint: Requestable {
return nil
case .bookmark:
return nil
case .deleteBookmark:
return nil
case .share:
return nil
case .watch:
Expand Down
43 changes: 27 additions & 16 deletions Projects/Core/PPACData/Sources/Repository/MemeRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PPACDomain
import PPACNetwork
import PPACModels

public class MemeRepositoryImpl: MemeRepository {
public class MemeRepositoryImpl: MemeRepository {

// MARK: - Properties

Expand Down Expand Up @@ -65,25 +65,36 @@ public class MemeRepositoryImpl: MemeRepository {
}

public func bookmarkMeme(memeId: String) async throws {
let endpoint = MemeEndpoint.bookmark(memeId: memeId)
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)
switch result {
case .success:
return
case .failure(let failure):
throw failure
}
let endpoint = MemeEndpoint.bookmark(memeId: memeId)
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)
switch result {
case .success:
return
case .failure(let failure):
throw failure
}
}

public func deleteBookmarkMeme(memeId: String) async throws {
let endpoint = MemeEndpoint.deleteBookmark(memeId: memeId)
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)

switch result {
case .success:
return
case .failure(let failure):
throw failure
}
}


public func shareMeme(memeId: String) async throws {
let endpoint = MemeEndpoint.share(memeId: memeId)
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)
switch result {
case .success:
return
return
case .failure(let failure):
throw failure
throw failure
}
}

Expand All @@ -92,9 +103,9 @@ public class MemeRepositoryImpl: MemeRepository {
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)
switch result {
case .success:
return
return
case .failure(let failure):
throw failure
throw failure
}
}

Expand All @@ -103,9 +114,9 @@ public class MemeRepositoryImpl: MemeRepository {
let result = await networkservice.request(endpoint, dataType: BaseDTO<VoidResponse>.self)
switch result {
case .success:
return
return
case .failure(let failure):
throw failure
throw failure
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public protocol MemeRepository {
func getSearchKeywordMemeList(keyword: String) async throws -> [MemeDetail]
func getMemeDetail(memeId: String) async throws -> MemeDetail
func bookmarkMeme(memeId: String) async throws
func deleteBookmarkMeme(memeId: String) async throws
func shareMeme(memeId: String) async throws
func watchMeme(memeId: String, type: String) async throws
func reactToMeme(memeId: String) async throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ import Foundation
import PPACModels

public protocol BookmarkMemeUseCase {
func execute(memeId: String) async throws
func execute(memeId: String) async throws
func delete(memeId: String) async throws
}

public class BookmarkMemeUseCaseImpl: BookmarkMemeUseCase {
private let repository: MemeRepository

public init(repository: MemeRepository) {
self.repository = repository
}

public func execute(memeId: String) async throws {
try await repository.bookmarkMeme(memeId: memeId)
}
private let repository: MemeRepository

public init(repository: MemeRepository) {
self.repository = repository
}

public func execute(memeId: String) async throws {
try await repository.bookmarkMeme(memeId: memeId)
}

public func delete(memeId: String) async throws {
try await repository.deleteBookmarkMeme(memeId: memeId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ struct RecommendMemeButtonView : View {

copyButton(copyButtonTapped)
shareButton(shareButtonTapped)
saveButton(saveButtonTapped)
saveButton(isFarmemed: meme?.isFarmemed ?? false) {
meme?.isFarmemed.toggle()
saveButtonTapped()
}
}
.padding(.vertical, 30)
.padding(.horizontal, 32)
Expand Down Expand Up @@ -81,23 +84,37 @@ func shareButton(_ shareAction: @escaping () -> Void) -> some View {
)
}

func saveButton(_ saveAction: @escaping () -> Void) -> some View {
func saveButton(
isFarmemed: Bool,
_ saveAction: @escaping () -> Void
) -> some View {
CircleButton(
width: 50,
height: 50,
image: ResourceKitAsset.Icon.stroke.swiftUIImage,
image: isFarmemed ? ResourceKitAsset.Icon.filled.swiftUIImage : ResourceKitAsset.Icon.stroke.swiftUIImage,
action: saveAction
)
}

#Preview {
@State var meme: MemeDetail? = .mock
@State var meme: MemeDetail? = MemeDetail(
id: "1234",
title: "안녕하세요!",
keywords: ["웃김", "재미", "신나"],
imageUrlString: "https://host.com/asdf",
source: "종난",
isTodayMeme: true,
reaction: 130,
isFarmemed: true
)

return RecommendMemeButtonView(
meme: $meme,
reactionButtonTapped: { meme?.reaction += 1 },
copyButtonTapped: { print("copy~~") },
shareButtonTapped: { print("share~~") },
saveButtonTapped: { print("save!!") }
saveButtonTapped: {
print("isFarmemed: \(meme?.isFarmemed)")
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,19 @@ private extension RecommendViewModel {
}

if meme.isFarmemed {
debugPrint("already farmeme.")
return
}

do {
try await bookmarkMemeUseCase.execute(memeId: meme.id)
meme.isFarmemed = true
} catch {
debugPrint("Failed save meme : \(error)")
do {
try await bookmarkMemeUseCase.delete(memeId: meme.id)
meme.isFarmemed = false
} catch {
debugPrint("Faild delete meme : \(error)")
}
} else {
do {
try await bookmarkMemeUseCase.execute(memeId: meme.id)
meme.isFarmemed = true
} catch {
debugPrint("Failed save meme : \(error)")
}
}
}
}

0 comments on commit 338c53d

Please sign in to comment.