-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Feat] #27 - 책리스트api연결 #28
base: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "feat/#27-\uCC45\uB9AC\uC2A4\uD2B8api\uC5F0\uACB0"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// File.swift | ||
// Aladin-iOS | ||
// | ||
// Created by JH on 2022/12/16. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Welcome | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도.. |
||
struct BookListResponseDTO: Codable { | ||
let status: Int | ||
let message: String | ||
let data: BookListData | ||
} | ||
|
||
// MARK: - DataClass | ||
struct BookListData: Codable { | ||
let topic, pick: [BookListDataArray] | ||
} | ||
|
||
// MARK: - Pick | ||
struct BookListDataArray: Codable { | ||
let id: Int | ||
let name, thumbnail: String | ||
let cover: String | ||
let pickDescription, summary, author, painter: String | ||
let intro, publisher: String | ||
let price, discountRate: Int | ||
let content: String | ||
let point: Int | ||
let topic, pick: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id, name, thumbnail, cover | ||
case pickDescription = "description" | ||
case summary, author, painter, intro, publisher, price | ||
case discountRate = "discount_rate" | ||
case content, point, topic, pick | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// BookListRouter.swift | ||
// Aladin-iOS | ||
// | ||
// Created by JH on 2022/12/16. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요건 필요 없지않아여? |
||
|
||
import Moya | ||
|
||
enum BookListRouter { | ||
case BookList | ||
} | ||
|
||
extension BookListRouter: TargetType { | ||
var baseURL: URL { | ||
return URL(string: APIConstants.baseURL)! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .BookList: | ||
return "/book" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .BookList: | ||
return .get | ||
} | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case .BookList: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
var headers: [String : String]? { | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import UIKit | ||
import SnapKit | ||
import Then | ||
import Moya | ||
|
||
|
||
final class HomeVC: UITabBarController { | ||
|
@@ -210,6 +211,43 @@ final class HomeVC: UITabBarController { | |
$0.image = ImageLiterals.Images.bottomBook | ||
} | ||
|
||
let bookListProvider = MoyaProvider<BookListRouter>( | ||
plugins: [NetworkLoggerPlugin(verbose: true)] | ||
) | ||
|
||
var pickArray: [BookListDataArray] = [] | ||
var topicArray: [BookListDataArray] = [] | ||
var bookListResponse: BookListResponseDTO? | ||
Comment on lines
+218
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맨 위에 선언해주면 더 잘보일거같아여~ |
||
|
||
|
||
func bookListAPI() { | ||
bookListProvider.request(.BookList) { response in | ||
switch response { | ||
case .success(let result): | ||
let status = result.statusCode | ||
if status >= 200 && status < 300 { | ||
do { | ||
self.bookListResponse = try result.map(BookListResponseDTO?.self)! | ||
guard let pickArray = self.bookListResponse?.data.pick else { return } | ||
guard let topicArray = self.bookListResponse?.data.topic else { return } | ||
self.hotBookContainerView.topicViewArray = topicArray | ||
Comment on lines
+226
to
+233
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 곤듀~ 잘했다 ~ 👍🏻 |
||
} catch(let err) { | ||
print(err.localizedDescription) | ||
} | ||
} else if status >= 400 { | ||
print("err") | ||
} | ||
case .failure(let err): | ||
print(err.localizedDescription) | ||
} | ||
} | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
bookListAPI() | ||
} | ||
Comment on lines
+246
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. life cycle 관련 코드는 위로 올려주세요..~ |
||
|
||
// MARK: - View Life Cycle | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import SnapKit | |
import Then | ||
|
||
class HotBookCVC: UICollectionViewCell { | ||
|
||
static let identifier = "HotBookCVC" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 이거 선언하지말구 제가 util에 만들어놓은 classname으루 쓰면 될 것 같아여 |
||
|
||
private let bookSampleImageView = UIImageView().then { | ||
$0.contentMode = .scaleAspectFit | ||
|
@@ -40,10 +42,27 @@ class HotBookCVC: UICollectionViewCell { | |
setLayout() | ||
} | ||
|
||
func dataBind(model : HotBookModel) { | ||
bookSampleImageView.image = UIImage(named: model.sampleImage) | ||
bookNameLabel.text = model.bookName | ||
bookIntroLabel.text = model.bookIntro | ||
func dataBind(model : BookListDataArray) { | ||
|
||
DispatchQueue.global().async { [weak self] in | ||
let url = URL(string: model.cover) | ||
if let data = try? Data(contentsOf: url!) { | ||
if let image = UIImage(data: data) { | ||
DispatchQueue.main.async { | ||
self?.bookSampleImageView.image = image | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+47
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 대박. 이 코드 설명좀 해주세여 ~ |
||
// let url = URL(string: model.cover) | ||
// do { | ||
// let data = try Data(contentsOf: url!) | ||
// bookSampleImageView.image = UIImage(data: data) | ||
// } catch (let error) { | ||
// print("err") | ||
// } | ||
Comment on lines
+57
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안쓰는 코드 지워주쎄용 |
||
bookNameLabel.text = model.name | ||
bookIntroLabel.text = model.pickDescription | ||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 야무지네요☃️ |
||
} | ||
|
||
required init?(coder: NSCoder) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주석 이름 체크해주세영~