-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from leeari95/step1
오픈 마켓 [STEP 1] 아리,제리
- Loading branch information
Showing
39 changed files
with
1,828 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
included: | ||
- OpenMarket # 프로젝트 이름 | ||
excluded: # 린트 과정에서 무시할 파일 경로. `included`보다 우선순위 높음 | ||
- OpenMarket/AppDelegate.swift | ||
- OpenMarket/SceneDelegate.swift | ||
identifier_name: | ||
min_length: | ||
- 2 # only min_length | ||
error: 4 # only error | ||
excluded: # 제외할 문자열 목록 사용 | ||
- id | ||
- URL | ||
- url | ||
- GlobalAPIKey | ||
disabled_rules: # 실행에서 제외할 룰 식별자들 | ||
- colon | ||
- control_statement | ||
- trailing_whitespace | ||
- vertical_parameter_alignment | ||
opt_in_rules: # 일부 룰은 옵트 인 형태로 제공 | ||
- empty_count |
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
OpenMarket/OpenMarket/Assets.xcassets/product.dataset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"data" : [ | ||
{ | ||
"filename" : "product.json", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
OpenMarket/OpenMarket/Assets.xcassets/product.dataset/product.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"id": 16, | ||
"vendor_id": 2, | ||
"name": "팥빙수", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/2/thumb/8279f1c16c6111ecbf33d51698ab7ead.png", | ||
"currency": "KRW", | ||
"price": 2000.0, | ||
"bargain_price": 2000.0, | ||
"discounted_price": 0.0, | ||
"stock": 0, | ||
"created_at": "2022-01-03 00:00:00.000", | ||
"issued_at": "2022-01-03 00:00:00.000", | ||
"images": [ | ||
{ | ||
"id": 7, | ||
"url": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/2/origin/8279f1c16c6111ecbf33d51698ab7ead.png", | ||
"thumbnail_url": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/2/thumb/8279f1c16c6111ecbf33d51698ab7ead.png", | ||
"succeed": true, | ||
"issued_at": "2022-01-03 00:00:00.000" | ||
} | ||
], | ||
"vendors": { | ||
"name": "dacodaco", | ||
"id": 2, | ||
"created_at": "2021-12-26 00:00:00.000", | ||
"issued_at": "2021-12-26 00:00:00.000" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
OpenMarket/OpenMarket/Assets.xcassets/products.dataset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"data" : [ | ||
{ | ||
"filename" : "products.json", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
OpenMarket/OpenMarket/Assets.xcassets/products.dataset/products.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"page_no": 1, | ||
"items_per_page": 20, | ||
"total_count": 5, | ||
"offset": 0, | ||
"limit": 20, | ||
"pages": [ | ||
{ | ||
"id": 15, | ||
"vendor_id": 3, | ||
"name": "pizza", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/3/thumb/f510cb6e689f11ecbf33d124b2c61dc4.jpg", | ||
"currency": "KRW", | ||
"price": 25000, | ||
"bargain_price": 25000, | ||
"discounted_price": 0, | ||
"stock": 0, | ||
"created_at": "2021-12-29 00:00:00.000", | ||
"issued_at": "2021-12-29 00:00:00.000" | ||
}, | ||
{ | ||
"id": 13, | ||
"vendor_id": 2, | ||
"name": "팥빙수", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/2/thumb/f70ad56a689911ecbf33f11af721febf.png", | ||
"currency": "KRW", | ||
"price": 2000, | ||
"bargain_price": 2000, | ||
"discounted_price": 0, | ||
"stock": 0, | ||
"created_at": "2021-12-29 00:00:00.000", | ||
"issued_at": "2021-12-29 00:00:00.000" | ||
}, | ||
{ | ||
"id": 4, | ||
"vendor_id": 3, | ||
"name": "Test Product", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/3/thumb/87aa7c8966df11ecad1df993f20d4a2a.jpg", | ||
"currency": "KRW", | ||
"price": 1000, | ||
"bargain_price": 900, | ||
"discounted_price": 100, | ||
"stock": 0, | ||
"created_at": "2021-12-27 00:00:00.000", | ||
"issued_at": "2021-12-27 00:00:00.000" | ||
}, | ||
{ | ||
"id": 3, | ||
"vendor_id": 3, | ||
"name": "Test Product", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/3/thumb/2f6021a066dc11ec9626955448777bf5.jpg", | ||
"currency": "KRW", | ||
"price": 1000, | ||
"bargain_price": 1000, | ||
"discounted_price": 0, | ||
"stock": 0, | ||
"created_at": "2021-12-27 00:00:00.000", | ||
"issued_at": "2021-12-27 00:00:00.000" | ||
}, | ||
{ | ||
"id": 2, | ||
"vendor_id": 2, | ||
"name": "팥빙수", | ||
"thumbnail": "https://s3.ap-northeast-2.amazonaws.com/media.yagom-academy.kr/training-resources/2/thumb/a3257844661911ec8eff5b6e36134cb4.png", | ||
"currency": "KRW", | ||
"price": 2000, | ||
"bargain_price": 2000, | ||
"discounted_price": 0, | ||
"stock": 0, | ||
"created_at": "2021-12-26 00:00:00.000", | ||
"issued_at": "2021-12-26 00:00:00.000" | ||
} | ||
], | ||
"last_page": 1, | ||
"has_next": false, | ||
"has_prev": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// NetworkError.swift | ||
// OpenMarket | ||
// | ||
// Created by 이호영 on 2022/01/04. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NetworkError: LocalizedError { | ||
case responseCasting | ||
case statusCode(Int) | ||
case notFoundURL | ||
|
||
var errorDescription: String { | ||
switch self { | ||
case .responseCasting: | ||
return "캐스팅에 실패하였습니다." | ||
case .statusCode(let code): | ||
return "상태 코드 에러 : \(code)" | ||
case .notFoundURL: | ||
return "URL을 찾을 수 없습니다." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ParserError.swift | ||
// OpenMarket | ||
// | ||
// Created by Ari on 2022/01/03. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ParserError: LocalizedError { | ||
case assetNotfound | ||
case decodingFail | ||
case encodingFail | ||
|
||
var errorDescription: String { | ||
switch self { | ||
case .assetNotfound: | ||
return "에셋 데이터를 찾을 수 없습니다." | ||
case .decodingFail: | ||
return "디코딩을 하는 도중 에러가 발생했습니다." | ||
case .encodingFail: | ||
return "인코딩을 하는 도중 에러가 발생했습니다." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Data+extension.swift | ||
// OpenMarket | ||
// | ||
// Created by 이호영 on 2022/01/04. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Data { | ||
mutating func append(_ string: String) { | ||
guard let data = string.data(using: .utf8) else { | ||
return | ||
} | ||
self.append(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Parser.swift | ||
// OpenMarket | ||
// | ||
// Created by Ari on 2022/01/03. | ||
// | ||
|
||
import UIKit | ||
|
||
struct JSONParser: JSONParserable { | ||
private let jsonDecoder = JSONDecoder() | ||
private let jsonEncoder = JSONEncoder() | ||
|
||
func decode<T: Decodable>(fileName: String, decodingType: T.Type) -> Result<T, ParserError> { | ||
guard let asset = NSDataAsset(name: fileName) else { | ||
return .failure(.assetNotfound) | ||
} | ||
guard let decodeData = try? jsonDecoder.decode(decodingType, from: asset.data) else { | ||
return .failure(.decodingFail) | ||
} | ||
return .success(decodeData) | ||
} | ||
|
||
func decode<T: Decodable>(source: Data, decodingType: T.Type) -> Result<T, ParserError> { | ||
guard let data = try? jsonDecoder.decode(decodingType, from: source) else { | ||
return .failure(.decodingFail) | ||
} | ||
return .success(data) | ||
} | ||
|
||
func encode<T: Encodable>(object: T) -> Result<Data, ParserError> { | ||
guard let data = try? jsonEncoder.encode(object) else { | ||
return .failure(.encodingFail) | ||
} | ||
return .success(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// NetworkConstant.swift | ||
// OpenMarket | ||
// | ||
// Created by Ari on 2022/01/04. | ||
// | ||
|
||
import Foundation | ||
|
||
enum APIAddress { | ||
static let baseURL = "https://market-training.yagom-academy.kr/api/products" | ||
case products(page: UInt, itemsPerPage: UInt) | ||
case product(id: UInt) | ||
case register | ||
case secret(id: UInt, secret: String) | ||
case delete(id: UInt, secret: String) | ||
|
||
var url: URL? { | ||
switch self { | ||
case .products(let page, let itemsPerPage): | ||
return URL(string: APIAddress.baseURL + "?page-no=\(page)" + "&items-per-page=\(itemsPerPage)") | ||
case .product(let id): | ||
return URL(string: APIAddress.baseURL + "/\(id)") | ||
case .register: | ||
return URL(string: APIAddress.baseURL) | ||
case .secret(let id, let secret): | ||
return URL(string: APIAddress.baseURL + "/\(id)" + "/\(secret)") | ||
case .delete(let id, let secret): | ||
return URL(string: APIAddress.baseURL + "/\(id)" + "/\(secret)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ContentType.swift | ||
// OpenMarket | ||
// | ||
// Created by 이호영 on 2022/01/06. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ContentType { | ||
case contentType | ||
case json | ||
case formData(boundary: String) | ||
|
||
var string: String { | ||
switch self { | ||
case .contentType: | ||
return "Content-Type" | ||
case .json: | ||
return "application/json" | ||
case .formData(let boundary): | ||
return "multipart/form-data; boundary=\"\(boundary)\"" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// HTTPMethod.swift | ||
// OpenMarket | ||
// | ||
// Created by Ari on 2022/01/06. | ||
// | ||
|
||
import Foundation | ||
|
||
enum HTTPMethod: String { | ||
case get = "GET" | ||
case post = "POST" | ||
case patch = "PATCH" | ||
case delete = "DELETE" | ||
} |
Oops, something went wrong.