Skip to content

Commit

Permalink
Merge pull request #342 from OMZigak/refactor/#337-promise-api
Browse files Browse the repository at this point in the history
[feat] 약속 관련 API 연결 및 명세 반영
  • Loading branch information
youz2me authored Aug 27, 2024
2 parents 77e13a6 + 93656ff commit c458604
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 114 deletions.
12 changes: 1 addition & 11 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@
DD8626522C4606A300E4F980 /* SetReadyInfoViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetReadyInfoViewModel.swift; sourceTree = "<group>"; };
DD8626552C4606A300E4F980 /* EnterReadyInfoButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnterReadyInfoButtonView.swift; sourceTree = "<group>"; };
DD8626562C4606A300E4F980 /* ReadyPlanInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadyPlanInfoView.swift; sourceTree = "<group>"; };
DD8626572C4606A300E4F980 /* OurReadyStatusCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OurReadyStatusCollectionViewCell.swift; sourceTree = "<group>"; };
DD8626582C4606A300E4F980 /* ReadyStatusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadyStatusView.swift; sourceTree = "<group>"; };
DD8626592C4606A300E4F980 /* SetReadyInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetReadyInfoView.swift; sourceTree = "<group>"; };
DD86265A2C4606A300E4F980 /* ReadyStatusButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadyStatusButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -690,7 +689,6 @@
children = (
78B9286A2C29402C006D9942 /* KkuMulKum */,
78B928692C29402C006D9942 /* Products */,
DD9F59642C7C7E3B00E928DF /* Recovered References */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -1213,14 +1211,6 @@
path = Tardy;
sourceTree = "<group>";
};
DD9F59642C7C7E3B00E928DF /* Recovered References */ = {
isa = PBXGroup;
children = (
DD8626572C4606A300E4F980 /* OurReadyStatusCollectionViewCell.swift */,
);
name = "Recovered References";
sourceTree = "<group>";
};
DD9F59652C7C7E5C00E928DF /* Cell */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1255,6 +1245,7 @@
DD1FD0322C5CCF7700D0A72C /* PromiseInfo */,
DD1FD02D2C5CCB1E00D0A72C /* ReadyStatus */,
DD931B682C3D9DAD00526452 /* Tardy */,
DD34664B2C7B020400E62284 /* EditPromise */,
);
path = Promise;
sourceTree = "<group>";
Expand Down Expand Up @@ -1369,7 +1360,6 @@
DECB844E2C43FB200022A003 /* AddPromise */,
DD7AB15F2C513B66008308DE /* SetReadyInfo */,
DDAF1C872C3D6E3D008A37D3 /* Promise */,
DD34664B2C7B020400E62284 /* EditPromise */,
DE159D312C406E1600425101 /* MyPage */,
);
path = Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import Foundation
// MARK: 약속 상세 정보 조회

struct PromiseInfoModel: ResponseModelType {
let isParticipant: Bool
let promiseID: Int
let promiseName, placeName, address, roadAddress, time, dressUpLevel, penalty: String
let promiseName, placeName, time, dressUpLevel, penalty: String
let address, roadAddress: String?
let x, y: Double

enum CodingKeys: String, CodingKey {
case isParticipant
case promiseID = "promiseId"
case promiseName
case placeName
case x
case y
case address
case roadAddress
case time
Expand Down
41 changes: 32 additions & 9 deletions KkuMulKum/Network/Service/PromiseService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ extension PromiseService: PromiseServiceProtocol {
func fetchPromiseParticipantList(with promiseID: Int) async throws -> ResponseBodyDTO<PromiseParticipantListModel>? {
return try await request(with: .fetchPromiseParticipantList(promiseID: promiseID))
}
}

extension PromiseService: EditPromiseServiceProtocol {
func fetchPromiseAvailableMember(with promiseID: Int) async throws -> ResponseBodyDTO<ParticipateAvailabilityResponseModel>? {
return try await self.request(with: .fetchPromiseAvailableMember(promiseID: promiseID))
}

func deletePromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return try await self.request(with: .deletePromise(promiseID: promiseID))
Expand All @@ -86,23 +80,52 @@ extension PromiseService: EditPromiseServiceProtocol {
func exitPromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return try await self.request(with: .exitPromise(promiseID: promiseID))
}
}

extension PromiseService: EditPromiseServiceProtocol {
func fetchPromiseAvailableMember(with promiseID: Int) async throws -> ResponseBodyDTO<ParticipateAvailabilityResponseModel>? {
return try await self.request(with: .fetchPromiseAvailableMember(promiseID: promiseID))
}

func putPromiseInfo(with promiseID: Int, request: EditPromiseRequestModel) async throws -> ResponseBodyDTO<AddPromiseResponseModel>? {
return try await self.request(with: .putPromiseInfo(promiseID: promiseID, request: request))
}
}

final class MockPromiseService: PromiseServiceProtocol {
func deletePromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
let mockData = EmptyModel()

return ResponseBodyDTO<EmptyModel>.init(
success: true,
data: mockData,
error: nil
)
}

func exitPromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
let mockData = EmptyModel()

return ResponseBodyDTO<EmptyModel>.init(
success: true,
data: mockData,
error: nil
)
}

func fetchPromiseInfo(with promiseId: Int) async throws -> ResponseBodyDTO<PromiseInfoModel>? {
let mockData = PromiseInfoModel(
isParticipant: true,
promiseID: 1,
promiseName: "냐미",
placeName: "우리집 앞",
time: "2024-07-07 15:00:00",
dressUpLevel: "LV 2. 냐미",
penalty: "냐미",
address: "경기도 용인시 수지구 대지로 72",
roadAddress: "경기도 용인시 수지구 대지로 72",
time: "2024년 7월 24일 오후 10시 30분",
dressUpLevel: "LV 2. 냐미",
penalty: "냐미"
x: 127.00090541880259,
y: 37.55808646250296
)

return ResponseBodyDTO<PromiseInfoModel>.init(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "receipt-subtract--shop-shopping-pay-payment-store-cash-bill-receipt-subtract-minus-remove.svg",
"idiom" : "universal"
}
],
"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.
4 changes: 3 additions & 1 deletion KkuMulKum/Source/AddPromise/Cell/SelectMemberCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class SelectMemberCell: BaseCollectionViewCell {
didSet {
let color: UIColor = isSelected ? .maincolor : .gray2
layer.borderColor = color.cgColor
backgroundColor = isSelected ? .green1 : .white
}
}

Expand Down Expand Up @@ -59,8 +60,9 @@ final class SelectMemberCell: BaseCollectionViewCell {
}

extension SelectMemberCell {
func configure(with member: Member) {
func configure(with member: Member, isSelect: Bool = false) {
self.member = member
self.isSelected = isSelect

nameLabel.updateText(member.name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ protocol EditPromiseServiceProtocol {
/// 약속 수정
func fetchPromiseAvailableMember(with promiseID: Int) async throws -> ResponseBodyDTO<ParticipateAvailabilityResponseModel>?
func putPromiseInfo(with promiseID: Int, request: EditPromiseRequestModel) async throws -> ResponseBodyDTO<AddPromiseResponseModel>?
func deletePromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>?
func exitPromise(promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class EditPromiseViewController: BaseViewController {
let viewModel: EditPromiseViewModel

private let rootView: AddPromiseView = AddPromiseView()
private let findPlaceViewController = FindPlaceViewController(viewModel: FindPlaceViewModel(service: UtilService()))
private let findPlaceViewController = FindPlaceViewController(
viewModel: FindPlaceViewModel(
service: UtilService()
)
)


// MARK: - LifeCycle
Expand Down Expand Up @@ -47,12 +51,6 @@ class EditPromiseViewController: BaseViewController {
navigationController?.isNavigationBarHidden = false
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

navigationController?.isNavigationBarHidden = true
}


// MARK: - Setup

Expand Down Expand Up @@ -142,7 +140,8 @@ private extension EditPromiseViewController {

@objc
func placeTextFieldDidTap() {
navigationController?.pushViewController(findPlaceViewController, animated: true)
findPlaceViewController.navigationController?.isNavigationBarHidden = false
self.navigationController?.pushViewController(findPlaceViewController, animated: true)
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,4 @@ extension EditPromiseViewModel {
}
}
}


func deletePromise() {
Task {
do {
let result = try await service.deletePromise(promiseID: promiseID)

guard let success = result?.success, success == true else {
return
}
}
}
}

func exitPromise() {
Task {
do {
let result = try await service.exitPromise(promiseID: promiseID)

guard let success = result?.success, success == true else {
return
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class PromiseViewController: BaseViewController {
init(viewModel: PromiseViewModel) {
self.viewModel = viewModel

viewModel.fetchPromiseInfo(promiseID: viewModel.promiseID)

promiseInfoViewController = PromiseInfoViewController(viewModel: viewModel)
promiseReadyStatusViewController = ReadyStatusViewController(viewModel: viewModel)
promiseTardyViewController = TardyViewController(viewModel: viewModel)
Expand Down Expand Up @@ -125,7 +123,6 @@ class PromiseViewController: BaseViewController {
for: .touchUpInside
)

// TODO: 버튼 안눌리는 문제 해결하기
removePromiseViewContoller.exitButton.addTarget(
self,
action: #selector(exitButtonDidTap),
Expand All @@ -151,11 +148,12 @@ class PromiseViewController: BaseViewController {

private extension PromiseViewController {
func setupBindings() {
viewModel.promiseInfo.bind { info in
DispatchQueue.main.async {
self.setupNavigationBarTitle(with: info?.promiseName ?? "")
self.removePromiseViewContoller.promiseNameLabel.text = info?.promiseName ?? ""
}
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
owner.setupNavigationBarTitle(with: info?.promiseName ?? "")
owner.promiseInfoViewController.rootView.editButton.isHidden = !(info?.isParticipant ?? false)
owner.promiseInfoViewController.setupContent()
owner.promiseInfoViewController.setUpTimeContent()
owner.removePromiseViewContoller.promiseNameLabel.text = info?.promiseName ?? ""
}
}

Expand Down Expand Up @@ -229,16 +227,22 @@ private extension PromiseViewController {
extension PromiseViewController: CustomActionSheetDelegate {
func actionButtonDidTap(for kind: ActionSheetKind) {
if kind == .deletePromise {
// TODO: 약속 삭제 API 연결

dismiss(animated: false)
navigationController?.popViewController(animated: true)

viewModel.deletePromise() {
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)
}
}
}
else {
// TODO: 약속 나가기 API 연결

dismiss(animated: false)
navigationController?.popViewController(animated: true)

viewModel.exitPromise() {
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)
}
}
}
}
}
Expand Down
Loading

0 comments on commit c458604

Please sign in to comment.