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

[Feat] #27 - 책리스트api연결 #28

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Aladin-iOS/Aladin-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
A305F36D292DF31D00FDF5DD /* HotBookModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A305F36C292DF31D00FDF5DD /* HotBookModel.swift */; };
A305F36F2930889D00FDF5DD /* ListTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A305F36E2930889D00FDF5DD /* ListTVC.swift */; };
A305F37129308C3300FDF5DD /* ListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A305F37029308C3300FDF5DD /* ListModel.swift */; };
A33402FF294C524500514DEE /* BookListResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33402FE294C524500514DEE /* BookListResponseDTO.swift */; };
A3340301294C541E00514DEE /* BookListRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3340300294C541E00514DEE /* BookListRouter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -97,6 +99,8 @@
A305F36C292DF31D00FDF5DD /* HotBookModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HotBookModel.swift; sourceTree = "<group>"; };
A305F36E2930889D00FDF5DD /* ListTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTVC.swift; sourceTree = "<group>"; };
A305F37029308C3300FDF5DD /* ListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModel.swift; sourceTree = "<group>"; };
A33402FE294C524500514DEE /* BookListResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookListResponseDTO.swift; sourceTree = "<group>"; };
A3340300294C541E00514DEE /* BookListRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookListRouter.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -232,6 +236,7 @@
isa = PBXGroup;
children = (
8EE879BB2931FD8A005F7AEC /* BookLikeResponseDTO.swift */,
A33402FE294C524500514DEE /* BookListResponseDTO.swift */,
14A7C1402933C8F90001AEB4 /* BookDetailResponseDTO.swift */,
);
path = DTO;
Expand All @@ -252,6 +257,7 @@
children = (
8EE879B32931F0D0005F7AEC /* BookRouter.swift */,
8EE879B52931F0DE005F7AEC /* BasketRouter.swift */,
A3340300294C541E00514DEE /* BookListRouter.swift */,
);
path = Router;
sourceTree = "<group>";
Expand Down Expand Up @@ -436,10 +442,12 @@
8EE879B22931F065005F7AEC /* APIConstants.swift in Sources */,
140A38852930A04C00208C8D /* BasketFooterView.swift in Sources */,
8EE879BC2931FD8A005F7AEC /* BookLikeResponseDTO.swift in Sources */,
A3340301294C541E00514DEE /* BookListRouter.swift in Sources */,
8E4FE7AD292381F600E9F36A /* Adjusted+.swift in Sources */,
8EE879BA2931F0EC005F7AEC /* NetworkLoggerPlugin.swift in Sources */,
8EE879B82931F0E6005F7AEC /* Encodable+.swift in Sources */,
8E4FE7B12923823400E9F36A /* getClassName.swift in Sources */,
A33402FF294C524500514DEE /* BookListResponseDTO.swift in Sources */,
8EE879B42931F0D0005F7AEC /* BookRouter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
41 changes: 41 additions & 0 deletions Aladin-iOS/Aladin-iOS/Network/DTO/BookListResponseDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// File.swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석 이름 체크해주세영~

// Aladin-iOS
//
// Created by JH on 2022/12/16.
//

import Foundation

// MARK: - Welcome
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
}
48 changes: 48 additions & 0 deletions Aladin-iOS/Aladin-iOS/Network/Router/BookListRouter.swift
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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"]
}
}


38 changes: 38 additions & 0 deletions Aladin-iOS/Aladin-iOS/Screens/Home/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit
import SnapKit
import Then
import Moya


final class HomeVC: UITabBarController {
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

life cycle 관련 코드는 위로 올려주세요..~


// MARK: - View Life Cycle

Expand Down
27 changes: 23 additions & 4 deletions Aladin-iOS/Aladin-iOS/Screens/Home/HotBookCVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SnapKit
import Then

class HotBookCVC: UICollectionViewCell {

static let identifier = "HotBookCVC"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 이거 선언하지말구 제가 util에 만들어놓은 classname으루 쓰면 될 것 같아여


private let bookSampleImageView = UIImageView().then {
$0.contentMode = .scaleAspectFit
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

야무지네요☃️

}

required init?(coder: NSCoder) {
Expand Down
28 changes: 16 additions & 12 deletions Aladin-iOS/Aladin-iOS/Screens/Home/HotBookContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class HotBookContainerView: UIView {

return cv
}()

var topicViewArray: [BookListDataArray] = []

// private var sampleImage = [
// UIImage(named: "bookSample1"),
Expand All @@ -29,12 +31,12 @@ class HotBookContainerView: UIView {

// MARK: - Variables

var hotBookModel : [HotBookModel] = [
HotBookModel(sampleImage: "bookSample1", bookName: "브랜드로 남는다는 것", bookIntro: "끝까지 살아남는 브랜드는 무엇이 다른가"),
HotBookModel(sampleImage: "bookSample2", bookName: "피아노 치는 할머니가 될래", bookIntro: "인생 후반전에 만난 피아노를 향한 세레나데"),
HotBookModel(sampleImage: "bookSample3", bookName: "익스텐드 마인드", bookIntro: "창조성은 어떻게 뇌 바깥에서 탄생하는가"),
HotBookModel(sampleImage: "bookSample1", bookName: "스크롤테스트용", bookIntro: "스크롤 테스트용 어쩌고~ 브랜드는 무엇이 다른가")
]
// var hotBookModel : [HotBookModel] = [
// HotBookModel(sampleImage: "bookSample1", bookName: "브랜드로 남는다는 것", bookIntro: "끝까지 살아남는 브랜드는 무엇이 다른가"),
// HotBookModel(sampleImage: "bookSample2", bookName: "피아노 치는 할머니가 될래", bookIntro: "인생 후반전에 만난 피아노를 향한 세레나데"),
// HotBookModel(sampleImage: "bookSample3", bookName: "익스텐드 마인드", bookIntro: "창조성은 어떻게 뇌 바깥에서 탄생하는가"),
// HotBookModel(sampleImage: "bookSample1", bookName: "스크롤테스트용", bookIntro: "스크롤 테스트용 어쩌고~ 브랜드는 무엇이 다른가")
// ]

// MARK: - View Life Cycle

Expand All @@ -43,10 +45,14 @@ class HotBookContainerView: UIView {

hotBookCV.backgroundColor = .clear
setLayout()
hotBookCV.register(HotBookCVC.self, forCellWithReuseIdentifier: "2")
hotBookCV.register(HotBookCVC.self, forCellWithReuseIdentifier: HotBookCVC.identifier)
hotBookCV.delegate = self
hotBookCV.dataSource = self
hotBookCV.showsHorizontalScrollIndicator = false

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.hotBookCV.reloadData()
}
}

private func setLayout(){
Expand All @@ -69,14 +75,12 @@ class HotBookContainerView: UIView {

extension HotBookContainerView: UICollectionViewDelegate, UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return hotBookModel.count
return topicViewArray.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = hotBookCV.dequeueReusableCell(withReuseIdentifier: "2", for: indexPath) as! HotBookCVC
cell.dataBind(model: hotBookModel[indexPath.item])

let cell = hotBookCV.dequeueReusableCell(withReuseIdentifier: HotBookCVC.identifier, for: indexPath) as! HotBookCVC
cell.dataBind(model: self.topicViewArray[indexPath.item])
return cell
}

}