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

Feature/#90 search api #94

Merged
merged 12 commits into from
Aug 15, 2024
Merged
6 changes: 4 additions & 2 deletions Projects/App/Sources/MainTab/MainTabPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public extension MainTabFeature {
case let .path(.element(_, action: .카테고리상세(.delegate(.contentItemTapped(content))))),
let .pokit(.delegate(.contentDetailTapped(content))),
let .remind(.delegate(.링크상세(content))),
let .path(.element(_, action: .링크목록(.delegate(.링크상세(content: content))))):
let .path(.element(_, action: .링크목록(.delegate(.링크상세(content: content))))),
let .path(.element(_, action: .검색(.delegate(.linkCardTapped(content: content))))):
// TODO: 링크상세 모델과 링크수정 모델 일치시키기
state.contentDetail = ContentDetailFeature.State(contentId: content.id)
return .none
Expand All @@ -116,7 +117,8 @@ public extension MainTabFeature {
let .pokit(.delegate(.링크수정하기(id))),
let .remind(.delegate(.링크수정(id))),
let .path(.element(_, action: .카테고리상세(.delegate(.링크수정(id))))),
let .path(.element(_, action: .링크목록(.delegate(.링크수정(id))))):
let .path(.element(_, action: .링크목록(.delegate(.링크수정(id))))),
let .path(.element(_, action: .검색(.delegate(.링크수정(id))))):
return .run { send in await send(.inner(.링크추가및수정이동(contentId: id))) }

case let .contentDetail(.presented(.delegate(.컨텐츠_삭제_완료(contentId: id)))):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ extension DependencyValues {
public struct UserDefaultsClient {
public var boolKey: @Sendable (UserDefaultsKey.BoolKey) -> Bool = { _ in false }
public var stringKey: @Sendable (UserDefaultsKey.StringKey) -> String? = { _ in "" }
public var stringArrayKey: @Sendable (UserDefaultsKey.ArrayKey) -> [String]? = { _ in [] }
public var removeBool: @Sendable (UserDefaultsKey.BoolKey) async -> Void
public var removeString: @Sendable (UserDefaultsKey.StringKey) async -> Void
public var removeStringArray: @Sendable (UserDefaultsKey.ArrayKey) async -> Void
public var setBool: @Sendable (Bool, UserDefaultsKey.BoolKey) async -> Void
public var setString: @Sendable (String, UserDefaultsKey.StringKey) async -> Void
public var setStringArray: @Sendable ([String], UserDefaultsKey.ArrayKey) async -> Void
}

extension UserDefaultsClient: DependencyKey {
Expand All @@ -32,21 +35,26 @@ extension UserDefaultsClient: DependencyKey {
return Self(
boolKey: { defaults().bool(forKey: $0.rawValue) },
stringKey: { defaults().string(forKey: $0.rawValue) },
stringArrayKey: { defaults().stringArray(forKey: $0.rawValue) },

removeBool: { defaults().removeObject(forKey: $0.rawValue) },
removeString: { defaults().removeObject(forKey: $0.rawValue) },
removeStringArray: { defaults().removeObject(forKey: $0.rawValue) },

setBool: { defaults().set($0, forKey: $1.rawValue) },
setString: { defaults().set($0, forKey: $1.rawValue) }
setString: { defaults().set($0, forKey: $1.rawValue) },
setStringArray: { defaults().set($0, forKey: $1.rawValue) }
)
}()

public static let testValue: Self = {
Self(
removeBool: { _ in },
removeString: { _ in },
removeStringArray: { _ in },
setBool: { _, _ in },
setString: { _, _ in }
setString: { _, _ in },
setStringArray: {_, _ in }
)
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import Foundation

public enum UserDefaultsKey {
public enum BoolKey: String {
case doNothing
case autoSaveSearch
}
public enum StringKey: String {
/// `구글` or `애플`
case authPlatform
case authCode
case jwt
}
public enum ArrayKey: String {
case searchWords
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
import Foundation

public struct BaseConditionRequest: Decodable {
public var searchWord: String
public var categoryIds: [Int]
public var isUnreadFiltered: Bool
public var isFavoriteFlitered: Bool
public var startDate: Date?
public var endDate: Date?
public var startDate: String?
public var endDate: String?

public init(
searchWord: String = "",
categoryIds: [Int],
isRead: Bool,
favorites: Bool,
startDate: Date? = nil,
endDate: Date? = nil
startDate: String? = nil,
endDate: String? = nil
) {
self.searchWord = searchWord
self.categoryIds = categoryIds
self.isUnreadFiltered = isRead
self.isFavoriteFlitered = favorites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension CategoryEndpoint: TargetType {
parameters: [
"page": model.page,
"size": model.size,
"sort": model.sort,
"sort": model.sort.map { String($0) }.joined(separator: ","),
"filterUncategorized": categorized
],
encoding: URLEncoding.default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public struct ContentClient {
public var 미분류_카테고리_컨텐츠_조회: @Sendable (
_ model: BasePageableRequest
) async throws -> ContentListInquiryResponse
public var 컨텐츠_검색: @Sendable (
_ pageable: BasePageableRequest,
_ condition: BaseConditionRequest
) async throws -> ContentListInquiryResponse
}

extension ContentClient: DependencyKey {
Expand Down Expand Up @@ -81,6 +85,14 @@ extension ContentClient: DependencyKey {
},
미분류_카테고리_컨텐츠_조회: { model in
try await provider.request(.미분류_카테고리_컨텐츠_조회(model: model))
},
컨텐츠_검색: { pageable, condition in
try await provider.request(
.컨텐츠_검색(
pageable: pageable,
condition: condition
)
)
}
)
}()
Expand All @@ -94,7 +106,8 @@ extension ContentClient: DependencyKey {
즐겨찾기: { _ in .mock },
즐겨찾기_취소: { _ in .init() },
카테고리_내_컨텐츠_목록_조회: { _, _, _ in .mock },
미분류_카테고리_컨텐츠_조회: { _ in .mock }
미분류_카테고리_컨텐츠_조회: { _ in .mock },
컨텐츠_검색: { _, _ in .mock }
)
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum ContentEndpoint {
condition: BaseConditionRequest
)
case 미분류_카테고리_컨텐츠_조회(model: BasePageableRequest)
case 컨텐츠_검색(
pageable: BasePageableRequest,
condition: BaseConditionRequest
)
}

extension ContentEndpoint: TargetType {
Expand All @@ -48,6 +52,8 @@ extension ContentEndpoint: TargetType {
return "/\(contentId)"
case .미분류_카테고리_컨텐츠_조회:
return "/uncategorized"
case .컨텐츠_검색(model: let model):
return ""
}
}

Expand All @@ -66,7 +72,8 @@ extension ContentEndpoint: TargetType {
return .patch

case .카태고리_내_컨텐츠_목록_조회,
.미분류_카테고리_컨텐츠_조회:
.미분류_카테고리_컨텐츠_조회,
.컨텐츠_검색:
return .get
}
}
Expand All @@ -90,12 +97,11 @@ extension ContentEndpoint: TargetType {
parameters: [
"page": pageable.page,
"size": pageable.size,
"sort": pageable.sort,
"sort": pageable.sort.map { String($0) }.joined(separator: ","),
"isRead": condition.isUnreadFiltered ? condition.isUnreadFiltered : "",
"favorites": condition.isFavoriteFlitered ? condition.isFavoriteFlitered : "",
"startDate": condition.startDate ?? "",
"endDate": condition.endDate ?? "",
"categoryIds": condition.categoryIds
"endDate": condition.endDate ?? ""
],
encoding: URLEncoding.default
)
Expand All @@ -104,7 +110,22 @@ extension ContentEndpoint: TargetType {
parameters: [
"page": model.page,
"size": model.size,
"sort": model.sort
"sort": model.sort.map { String($0) }.joined(separator: ",")
],
encoding: URLEncoding.default
)
case let .컨텐츠_검색(pageable, condition):
return .requestParameters(
parameters: [
"page": pageable.page,
"size": pageable.size,
"sort": pageable.sort.map { String($0) }.joined(separator: ","),
"isRead": condition.isUnreadFiltered ? condition.isUnreadFiltered : "",
"favorites": condition.isFavoriteFlitered ? condition.isFavoriteFlitered : "",
"startDate": condition.startDate ?? "",
"endDate": condition.endDate ?? "",
"categoryIds": condition.categoryIds.map { String($0) }.joined(separator: ","),
"searchWord": condition.searchWord
],
encoding: URLEncoding.default
)
Expand Down
12 changes: 11 additions & 1 deletion Projects/Domain/Sources/FilterBottom/FilterBottom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@
import Foundation

public struct FilterBottom: Equatable {
// - MARK: Response
/// 카테고리(포킷) 리스트
public var categoryList: BaseCategoryListInquiry

// - MARK: Request
/// 조회할 페이징 정보
public var pageable: BasePageable

public init() {
self.categoryList = .init(
data: [],
page: 0,
size: 10,
sort: [],
hasNext: false
)
self.pageable = .init(
page: 0,
size: 10,
sort: ["desc"]
)
}
}
9 changes: 8 additions & 1 deletion Projects/Domain/Sources/Search/Search.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct Search: Equatable {
// - MARK: Request
/// 검색 조건
public var condition: Condition
/// 조회할 페이징 정보
public var pageable: BasePageable

public init() {
self.contentList = .init(
Expand All @@ -26,9 +28,14 @@ public struct Search: Equatable {
self.condition = .init(
searchWord: "",
categoryIds: [],
isRead: true,
isRead: false,
favorites: false
)
self.pageable = .init(
page: 0,
size: 10,
sort: ["desc"]
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private extension CategoryDetailFeature {

case .onAppear:
return .run { send in
let request = BasePageableRequest(page: 0, size: 100, sort: ["desc"])
let request = BasePageableRequest(page: 0, size: 100, sort: ["createdAt", "desc"])
let response = try await categoryClient.카테고리_목록_조회(request, true).toDomain()
await send(.async(.카테고리_내_컨텐츠_목록_조회))
await send(.inner(.카테고리_목록_조회_결과(response)))
Expand Down
24 changes: 16 additions & 8 deletions Projects/Feature/FeaturePokit/Sources/PokitRootFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ private extension PokitRootFeature {
if state.domain.categoryList.hasNext {
return .run { [domain = state.domain.categoryList,
sortType = state.sortType] send in
let sort = sortType == .sort(.최신순) ? "desc" : "asc"
let request = BasePageableRequest(page: domain.page + 1, size: 10, sort: [sort])
let sort: [String] = sortType == .sort(.최신순)
? ["createdAt", "desc"]
: ["name", "asc"]
let request = BasePageableRequest(page: domain.page + 1, size: 10, sort: sort)
let classified = try await categoryClient.카테고리_목록_조회(request, true).toDomain()
await send(.inner(.분류_페이지네이션_결과(contentList: classified)))
}
Expand All @@ -229,8 +231,10 @@ private extension PokitRootFeature {
if state.domain.unclassifiedContentList.hasNext {
return .run { [domain = state.domain.unclassifiedContentList,
sortType = state.sortType] send in
let sort = sortType == .sort(.최신순) ? "desc" : "asc"
let request = BasePageableRequest(page: domain.page + 1, size: 10, sort: [sort])
let sort: [String] = sortType == .sort(.최신순)
? ["createdAt", "desc"]
: ["name", "asc"]
let request = BasePageableRequest(page: domain.page + 1, size: 10, sort: sort)
let unclassified = try await contentClient.미분류_카테고리_컨텐츠_조회(request).toDomain()
await send(.inner(.미분류_페이지네이션_결과(contentList: unclassified)))
}
Expand Down Expand Up @@ -316,8 +320,10 @@ private extension PokitRootFeature {
contentList = state.domain.unclassifiedContentList,
sortType = state.sortType
] send in
let sort = sortType == .sort(.최신순) ? "desc" : "asc"
let request = BasePageableRequest(page: 0, size: contentList.size, sort: [sort])
let sort: [String] = sortType == .sort(.최신순)
? ["createdAt", "desc"]
: ["name", "asc"]
let request = BasePageableRequest(page: 0, size: contentList.size, sort: sort)
let contentList = try await contentClient.미분류_카테고리_컨텐츠_조회(
request
).toDomain()
Expand All @@ -326,8 +332,10 @@ private extension PokitRootFeature {
case .목록조회_갱신용:
return .run { [domain = state.domain.categoryList,
sortType = state.sortType] send in
let sort = sortType == .sort(.최신순) ? "desc" : "asc"
let request = BasePageableRequest(page: 0, size: domain.size, sort: [sort])
let sort: [String] = sortType == .sort(.최신순)
? ["createdAt", "desc"]
: ["name", "asc"]
let request = BasePageableRequest(page: 0, size: domain.size, sort: sort)
let classified = try await categoryClient.카테고리_목록_조회(request, true).toDomain()
await send(.inner(.onAppearResult(classified: classified)))
await send(.inner(.sort))
Expand Down
Loading