Skip to content

Commit

Permalink
🔀 서버 명세서에 맞게 EndPoint, DTO, Entity 재수정 (#146)
Browse files Browse the repository at this point in the history
* 🎨 Refactor Entity and DTO to align with server credits API specification

* 🎨 Refactor Entity and DTO to align with server notices API specification

* 🎨 Refactor Entity and DTO to align with server products list API specification

* 🎨 Refactor Entity and DTO to align with server products price history API specification

* 🎨 Refactor Entity and DTO to align with server products search API specification

* ✅ Update code to pass the unit test
  • Loading branch information
WhiteHyun authored May 7, 2024
1 parent 7403f2f commit 425b4cf
Show file tree
Hide file tree
Showing 44 changed files with 100 additions and 278 deletions.
4 changes: 2 additions & 2 deletions APIService/Sources/CreditsAPI/CreditsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private extension Credits {
init(dto: CreditsResponse) {
self.init(
title: dto.title,
body: dto.body,
date: dto.date
content: dto.content,
date: dto.createdAt
)
}
}
5 changes: 3 additions & 2 deletions APIService/Sources/CreditsAPI/Responses/CreditsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Foundation
// MARK: - ProductResponse

struct CreditsResponse: Decodable {
let id: Int
let title: String
let body: String
let date: Date
let content: String
let createdAt: Date
}
5 changes: 0 additions & 5 deletions APIService/Sources/HomeAPI/HomeEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import NetworkAPIKit

public enum HomeEndPoint {
case fetchProducts(ProductRequest)
case fetchCount(ProductCountRequest)
}

// MARK: EndPoint
Expand All @@ -26,17 +25,13 @@ extension HomeEndPoint: EndPoint {
switch self {
case .fetchProducts:
"/v2/products"
case .fetchCount:
"/v2/products/count"
}
}

public var parameters: HTTPParameter {
switch self {
case let .fetchProducts(requestModel):
.query(requestModel)
case let .fetchCount(requestModel):
.query(requestModel)
}
}

Expand Down
6 changes: 0 additions & 6 deletions APIService/Sources/HomeAPI/HomeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import NetworkAPIKit

public protocol HomeServiceRepresentable {
func fetchProductList(request: ProductRequest) async throws -> Paginated<Product>
func fetchProductCount(request: ProductCountRequest) async throws -> Int
}

// MARK: - HomeService
Expand All @@ -33,11 +32,6 @@ extension HomeService: HomeServiceRepresentable {
let response: ProductResponse = try await network.request(with: HomeEndPoint.fetchProducts(request))
return Paginated<Product>(dto: response)
}

public func fetchProductCount(request: ProductCountRequest) async throws -> Int {
let countResponse: ProductCountResponse = try await network.request(with: HomeEndPoint.fetchCount(request))
return countResponse.count
}
}

private extension Paginated where Model == Product {
Expand Down
30 changes: 0 additions & 30 deletions APIService/Sources/HomeAPI/Requests/ProductCountRequest.swift

This file was deleted.

16 changes: 5 additions & 11 deletions APIService/Sources/HomeAPI/Requests/ProductRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ public struct ProductRequest: Encodable {
public let store: ConvenienceStore
public let promotion: Promotion
public let order: Order
public let pageSize: Int
public let limit: Int
public let offset: Int
public let date: Date

enum CodingKeys: String, CodingKey {
case store
case promotion
case order
case pageSize = "page_size"
case offset
}

public init(store: ConvenienceStore, promotion: Promotion, order: Order, pageSize: Int, offset: Int) {
public init(store: ConvenienceStore, promotion: Promotion, order: Order, limit: Int, offset: Int, date: Date = .now) {
self.store = store
self.promotion = promotion
self.order = order
self.pageSize = pageSize
self.limit = limit
self.offset = offset
self.date = date
}
}
12 changes: 0 additions & 12 deletions APIService/Sources/HomeAPI/Responses/ProductCountResponse.swift

This file was deleted.

12 changes: 3 additions & 9 deletions APIService/Sources/HomeAPI/Responses/ProductResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ struct ProductResponse: Decodable, Paginatable {
let hasMore: Bool

let results: [ProductItemResponse]

enum CodingKeys: String, CodingKey {
case count
case hasMore = "has_more"
case results
}
}

// MARK: - ProductItemResponse
Expand All @@ -36,11 +30,11 @@ struct ProductItemResponse: Decodable {

enum CodingKeys: String, CodingKey {
case id
case imageURL = "img"
case imageURL = "imageUrl"
case price
case date
case date = "eventDate"
case name
case promotion = "tag"
case promotion
case convenienceStore = "store"
}
}
5 changes: 1 addition & 4 deletions APIService/Sources/HomeAPISupport/HomeURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import NetworkAPIKit
public final class HomeURLProtocol: URLProtocol {
private lazy var mockData: [String: Data?] = [
HomeEndPoint.fetchProducts(
.init(store: .gs25, promotion: .allItems, order: .normal, pageSize: 0, offset: 0)
.init(store: .gs25, promotion: .allItems, order: .normal, limit: 0, offset: 0)
).path: loadMockData(fileName: "HomeProductResponse"),
HomeEndPoint.fetchCount(
.init(convenienceStore: .gs25, promotion: .allItems)
).path: loadMockData(fileName: "HomeProductCountResponse"),
]

override public class func canInit(with _: URLRequest) -> Bool {
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion APIService/Sources/NoticeAPI/NoticeDetailService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private extension NoticeDetail {
init(dto: NoticeItemResponse) {
self.init(
title: dto.title,
context: dto.body
context: dto.content
)
}
}
4 changes: 2 additions & 2 deletions APIService/Sources/NoticeAPI/NoticeEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ extension NoticeEndPoint: EndPoint {
public var path: String {
switch self {
case .fetchList:
"/v2/notice"
"/v2/notices"
case let .fetchDetail(id):
"/v2/notice/\(id)"
"/v2/notices/\(id)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions APIService/Sources/NoticeAPI/NoticeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private extension Notice {
init(dto: NoticeItemResponse) {
self.init(
id: dto.id,
date: dto.date,
date: dto.createdAt,
title: dto.title
)
}
Expand All @@ -64,7 +64,7 @@ private extension NoticeDetail {
init(dto: NoticeItemResponse) {
self.init(
title: dto.title,
context: dto.body
context: dto.content
)
}
}
11 changes: 3 additions & 8 deletions APIService/Sources/NoticeAPI/Requests/NoticeListRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
import Foundation

public struct NoticeListRequest: Encodable {
let pageSize: Int
let limit: Int
let offset: Int

public init(pageSize: Int, offset: Int) {
self.pageSize = pageSize
public init(limit: Int, offset: Int) {
self.limit = limit
self.offset = offset
}

enum CodingKeys: String, CodingKey {
case pageSize = "page_size"
case offset
}
}
10 changes: 2 additions & 8 deletions APIService/Sources/NoticeAPI/Responses/NoticeResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ struct NoticeResponse: Decodable, Paginatable {
let hasMore: Bool

let results: [NoticeItemResponse]

enum CodingKeys: String, CodingKey {
case count
case hasMore = "has_more"
case results
}
}

// MARK: - NoticeItemResponse

struct NoticeItemResponse: Decodable {
let id: Int
let title: String
let body: String?
let date: Date
let content: String
let createdAt: Date
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NoticeAPI

public final class NoticeURLProtocol: URLProtocol {
private lazy var mockData: [String: Data?] = [
NoticeEndPoint.fetchList(.init(pageSize: 0, offset: 0)).path: loadMockData(fileName: "NoticeListResponse"),
NoticeEndPoint.fetchList(.init(limit: 0, offset: 0)).path: loadMockData(fileName: "NoticeListResponse"),
NoticeEndPoint.fetchDetail(2).path: loadMockData(fileName: "NoticeDetailResponse"),
]

Expand Down
16 changes: 6 additions & 10 deletions APIService/Sources/ProductInfoAPI/ProductInfoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,25 @@ extension ProductInfoService: ProductInfoServiceRepresentable {
let response: ProductDetailResponse = try await network.request(
with: ProductInfoEndPoint.fetchProduct(productID)
)
if let item = response.results.first {
return DetailProduct(dto: item)
} else {
return DetailProduct(id: 0, imageURL: nil, price: 0, name: "", promotion: .allItems, convenienceStore: ._7Eleven, date: .distantPast)
}
return DetailProduct(dto: response)
}

public func fetchProductPrice(productID: Int) async throws -> [DetailProduct] {
let response: ProductDetailPricesResponse = try await network.request(
let response: [ProductDetailResponse] = try await network.request(
with: ProductInfoEndPoint.fetchPrices(productID)
)
return response.results.map(DetailProduct.init(dto:))
return response.map(DetailProduct.init(dto:))
}
}

private extension DetailProduct {
init(dto: ProductDetailItemResponse) {
init(dto: ProductDetailResponse) {
self.init(
id: dto.id,
imageURL: dto.img,
imageURL: dto.imageURL,
price: dto.price,
name: dto.name,
promotion: dto.tag,
promotion: dto.promotion,
convenienceStore: dto.store,
date: dto.date
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
import Entity
import Foundation

// MARK: - ProductDetailResponse

struct ProductDetailResponse: Decodable {
let count: Int
let results: [ProductDetailItemResponse]
}

// MARK: - ProductDetailItemResponse

struct ProductDetailItemResponse: Decodable {
let id: Int
let name: String
let img: URL?
let price: Int
let promotion: Promotion
let store: ConvenienceStore
let tag: Promotion
let proinfo: Int
let date: Date
let id: Int
let imageURL: URL?

enum CodingKeys: String, CodingKey {
case id
case name
case price
case promotion
case store
case date = "eventDate"
case imageURL = "imageUrl"
}
}
16 changes: 8 additions & 8 deletions APIService/Sources/SearchAPI/Requests/SearchProductRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import Foundation

public struct SearchProductRequest: Encodable {
public let name: String
public let order: Order
public let pageSize: Int
public let limit: Int
public let offset: Int
public let date: Date

enum CodingKeys: String, CodingKey {
case name = "product_name"
case order
case pageSize = "page_size"
case limit
case offset
case date
}

public init(name: String) {
public init(name: String, limit: Int = 5000, offset: Int = 1, date: Date = .now) {
self.name = name
order = .normal
pageSize = 5000
offset = 0
self.limit = limit
self.offset = offset
self.date = date
}
}
Loading

0 comments on commit 425b4cf

Please sign in to comment.