Skip to content

Commit

Permalink
Merge pull request #82 from leeari95/step1
Browse files Browse the repository at this point in the history
오픈 마켓 [STEP 1] 아리,제리
  • Loading branch information
GREENOVER authored Jan 7, 2022
2 parents 788afdc + d553f99 commit 0c2d12a
Show file tree
Hide file tree
Showing 39 changed files with 1,828 additions and 19 deletions.
21 changes: 21 additions & 0 deletions OpenMarket/.swiftlint.yml
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
353 changes: 350 additions & 3 deletions OpenMarket/OpenMarket.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 OpenMarket/OpenMarket/Assets.xcassets/product.dataset/product.json
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"
}
}
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
}
}
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
}
18 changes: 13 additions & 5 deletions OpenMarket/OpenMarket/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -11,15 +14,20 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Do any additional setup after loading the view.
}


}

25 changes: 25 additions & 0 deletions OpenMarket/OpenMarket/Error/NetworkError.swift
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을 찾을 수 없습니다."
}
}
}
25 changes: 25 additions & 0 deletions OpenMarket/OpenMarket/Error/ParserError.swift
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 "인코딩을 하는 도중 에러가 발생했습니다."
}
}
}
17 changes: 17 additions & 0 deletions OpenMarket/OpenMarket/Extension/Data+extension.swift
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)
}
}
37 changes: 37 additions & 0 deletions OpenMarket/OpenMarket/Model/JSONParser.swift
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)
}
}
32 changes: 32 additions & 0 deletions OpenMarket/OpenMarket/Model/Network/APIAddress.swift
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)")
}
}
}
25 changes: 25 additions & 0 deletions OpenMarket/OpenMarket/Model/Network/ContentType.swift
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)\""
}
}
}
15 changes: 15 additions & 0 deletions OpenMarket/OpenMarket/Model/Network/HTTPMethod.swift
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"
}
Loading

0 comments on commit 0c2d12a

Please sign in to comment.