Skip to content

Commit

Permalink
Merge pull request #233 from OMZigak/feat/#227-serviceAPI
Browse files Browse the repository at this point in the history
[feat] 홈 화면 및 내 모임 리스트 화면 API 연결
  • Loading branch information
mmaybei authored Jul 18, 2024
2 parents d8218ee + d7f4906 commit c01882e
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "empty.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions KkuMulKum/Source/Core/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ final class MainTabBarController: UITabBarController {
private func setTabBar() {
let homeViewController: HomeViewController = HomeViewController(
viewModel: HomeViewModel(
service: MockHomeService()
service: HomeService()
)).then {
$0.tabBarItem.title = ""
$0.tabBarItem.image = .iconHome
}

let meetingListViewController = MeetingListViewController(
viewModel: MeetingListViewModel(
service: MockMeetingListService()
service: MeetingService()
)).then {
$0.tabBarItem.title = "내 모임"
$0.tabBarItem.image = .iconGroup
Expand Down
26 changes: 20 additions & 6 deletions KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ import Foundation
import Moya

protocol HomeServiceType {
func fetchLoginUser() -> ResponseBodyDTO<LoginUserModel>
func fetchNearestPromise() -> ResponseBodyDTO<NearestPromiseModel>
func fetchUpcomingPromise() -> ResponseBodyDTO<UpcomingPromiseListModel>
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>?
func fetchNearestPromise() async throws -> ResponseBodyDTO<NearestPromiseModel>?
func fetchUpcomingPromise() async throws -> ResponseBodyDTO<UpcomingPromiseListModel>?
}

extension HomeService: HomeServiceType {
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? {
return try await request(with: .fetchLoginUser)
}

func fetchNearestPromise() async throws -> ResponseBodyDTO<NearestPromiseModel>? {
return try await request(with: .fetchNearestPromise)
}

func fetchUpcomingPromise() async throws -> ResponseBodyDTO<UpcomingPromiseListModel>? {
return try await request(with: .fetchUpcomingPromise)
}
}

final class MockHomeService: HomeServiceType {
func fetchLoginUser() -> ResponseBodyDTO<LoginUserModel> {
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? {
let mockData = ResponseBodyDTO<LoginUserModel>(
success: true,
data: LoginUserModel(
Expand All @@ -33,7 +47,7 @@ final class MockHomeService: HomeServiceType {
return mockData
}

func fetchNearestPromise() -> ResponseBodyDTO<NearestPromiseModel> {
func fetchNearestPromise() async throws -> ResponseBodyDTO<NearestPromiseModel>? {
let mockData = ResponseBodyDTO<NearestPromiseModel>(
success: true,
data: NearestPromiseModel(
Expand All @@ -51,7 +65,7 @@ final class MockHomeService: HomeServiceType {
return mockData
}

func fetchUpcomingPromise() -> ResponseBodyDTO<UpcomingPromiseListModel> {
func fetchUpcomingPromise() async throws -> ResponseBodyDTO<UpcomingPromiseListModel>? {
let mockData = ResponseBodyDTO<UpcomingPromiseListModel>(
success: true,
data: UpcomingPromiseListModel(
Expand Down
2 changes: 1 addition & 1 deletion KkuMulKum/Source/Home/View/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ final class HomeView: BaseView {

promiseView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview()
$0.height.equalTo(646)
$0.height.equalTo(Screen.height(630))
$0.top.equalToSuperview().offset(396)
$0.bottom.equalTo(contentView)
}
Expand Down
65 changes: 38 additions & 27 deletions KkuMulKum/Source/Home/ViewController/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HomeViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white
view.backgroundColor = .maincolor
register()

updateUI()
Expand Down Expand Up @@ -170,10 +170,6 @@ extension HomeViewController: UICollectionViewDataSource {

extension HomeViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if rootView.scrollView.contentOffset.y < 0 {
rootView.scrollView.contentOffset.y = 0
}

let maxOffsetY = rootView.scrollView.contentSize.height - rootView.scrollView.bounds.height
if rootView.scrollView.contentOffset.y > maxOffsetY {
rootView.scrollView.contentOffset.y = maxOffsetY
Expand Down Expand Up @@ -257,35 +253,50 @@ private extension HomeViewController {
func updateNearestPromise() {
viewModel.nearestPromise.bind { [weak self] _ in
DispatchQueue.main.async {
let data = self?.viewModel.nearestPromise.value
self?.rootView.todayPromiseView.meetingNameLabel.setText(
data?.data?.meetingName ?? "",
style: .caption02,
color: .green3
)
self?.rootView.todayPromiseView.nameLabel.setText(
data?.data?.name ?? "",
style: .body03,
color: .gray8
)
self?.rootView.todayPromiseView.placeNameLabel.setText(
data?.data?.placeName ?? "",
style: .body06,
color: .gray7
)
self?.rootView.todayPromiseView.timeLabel.setText(
data?.data?.time ?? "",
style: .body06,
color: .gray7
)
guard let self = self else { return }
let data = self.viewModel.nearestPromise.value

if data?.data == nil {
self.rootView.todayPromiseView.isHidden = true
self.rootView.todayEmptyView.isHidden = false
} else {
self.rootView.todayPromiseView.meetingNameLabel.setText(
data?.data?.meetingName ?? "",
style: .caption02,
color: .green3
)
self.rootView.todayPromiseView.nameLabel.setText(
data?.data?.name ?? "",
style: .body03,
color: .gray8
)
self.rootView.todayPromiseView.placeNameLabel.setText(
data?.data?.placeName ?? "",
style: .body06,
color: .gray7
)
self.rootView.todayPromiseView.timeLabel.setText(
data?.data?.time ?? "",
style: .body06,
color: .gray7
)
}
}
}
}

func updateUpcomingPromise() {
viewModel.upcomingPromiseList.bind { [weak self] _ in
DispatchQueue.main.async {
self?.rootView.upcomingPromiseView.reloadData()
guard let self = self else { return }
let data = self.viewModel.nearestPromise.value

if data?.data == nil {
self.rootView.upcomingPromiseView.isHidden = true
self.rootView.upcomingEmptyView.isHidden = false
} else {
self.rootView.upcomingPromiseView.reloadData()
}
}
}
}
Expand Down
28 changes: 23 additions & 5 deletions KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,34 @@ final class HomeViewModel {
}

func requestLoginUser() {
loginUser.value = service.fetchLoginUser()
levelName.value = getLevelName(level: loginUser.value?.data?.level ?? 1)
levelCaption.value = getLevelCaption(level: loginUser.value?.data?.level ?? 1)
Task {
do {
loginUser.value = try await service.fetchLoginUser()
levelName.value = getLevelName(level: loginUser.value?.data?.level ?? 1)
levelCaption.value = getLevelCaption(level: loginUser.value?.data?.level ?? 1)
} catch {
print(">>> \(error.localizedDescription) : \(#function)")
}
}
}

func requestNearestPromise() {
nearestPromise.value = service.fetchNearestPromise()
Task {
do {
nearestPromise.value = try await service.fetchNearestPromise()
} catch {
print(">>> \(error.localizedDescription) : \(#function)")
}
}
}

func requestUpcomingPromise() {
upcomingPromiseList.value = service.fetchUpcomingPromise()
Task {
do {
upcomingPromiseList.value = try await service.fetchUpcomingPromise()
} catch {
print(">>> \(error.localizedDescription) : \(#function)")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import Foundation
import Moya

protocol MeetingListServiceType {
func fetchMeetingList() -> ResponseBodyDTO<MeetingListModel>
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>?
}

//extension MeetingService: MeetingListServiceType {
// func fetchMeetingList() -> ResponseBodyDTO<MeetingListModel> {
// <#code#>
// }
//}
extension MeetingService: MeetingListServiceType {
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? {
return try await request(with: .fetchMeetingList)
}
}

final class MockMeetingListService: MeetingListServiceType {
func fetchMeetingList() -> ResponseBodyDTO<MeetingListModel> {
func fetchMeetingList() async throws -> ResponseBodyDTO<MeetingListModel>? {
let mockData = ResponseBodyDTO<MeetingListModel>(
success: true,
data: MeetingListModel(
Expand Down
25 changes: 24 additions & 1 deletion KkuMulKum/Source/MeetingList/View/MeetingListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,23 @@ final class MeetingListView: BaseView {
$0.tableHeaderView = header
}

let emptyCharacter = UIImageView().then {
$0.image = .imgEmpty
$0.isHidden = true
}

let emptyLabel = UILabel().then {
$0.setText("아직 모임이 없네요!\n모임을 추가해 보세요.", style: .body05, color: .gray4)
$0.textAlignment = .center
$0.isHidden = true
}


// MARK: - UI Setting

override func setupView() {
self.backgroundColor = .gray0
addSubview(tableView)
addSubviews(tableView, emptyCharacter, emptyLabel)
header.addSubviews(infoLabel, addButton, addInfoView)
addInfoView.addArrangedSubviews(addIconImageView, addInfoLabel)
}
Expand All @@ -68,6 +79,18 @@ final class MeetingListView: BaseView {
$0.height.equalTo(Screen.height(48))
}

emptyCharacter.snp.makeConstraints {
$0.top.equalTo(addButton.snp.bottom).offset(94)
$0.centerX.equalToSuperview()
$0.height.equalTo(Screen.height(126))
$0.width.equalTo(Screen.width(73))
}

emptyLabel.snp.makeConstraints {
$0.top.equalTo(emptyCharacter.snp.bottom).offset(16)
$0.centerX.equalToSuperview()
}

addInfoView.snp.makeConstraints {
$0.centerY.equalTo(addButton.snp.centerY)
$0.centerX.equalTo(addButton.snp.centerX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ class MeetingListViewController: BaseViewController {
private func updateMeetingList() {
viewModel.meetingList.bind { [weak self] _ in
DispatchQueue.main.async {
self?.rootView.tableView.reloadData()
self?.rootView.infoLabel.setText(
"꾸물리안이 가입한 모임은\n\(self?.viewModel.meetingList.value?.data?.count ?? 0)개예요!",
guard let self = self else { return }
let data = self.viewModel.meetingList.value

self.rootView.infoLabel.setText(
"꾸물리안이 가입한 모임은\n\(self.viewModel.meetingList.value?.data?.count ?? 0)개예요!",
style: .head01,
color: .gray8
)

if data?.data?.count == 0 {
self.rootView.emptyLabel.isHidden = false
self.rootView.emptyCharacter.isHidden = false
} else {
self.rootView.tableView.reloadData()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ final class MeetingListViewModel {
}

func requestMeetingList() {
meetingList.value = service.fetchMeetingList()
Task {
do {
meetingList.value = try await service.fetchMeetingList()
} catch {
print(">>> \(error.localizedDescription) : \(#function)")
}
}
// meetingList.value = service.fetchMeetingList()
}
}

0 comments on commit c01882e

Please sign in to comment.