Skip to content

Commit

Permalink
feat/#215 모임 상세 화면 API 연결 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JinUng41 committed Jul 17, 2024
1 parent 78a21f6 commit 28892e1
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MeetingMembersModel: ResponseModelType {

struct Member: Codable {
let memberID: Int
let name: String
let name: String?
let profileImageURL: String?

enum CodingKeys: String, CodingKey {
Expand Down
11 changes: 10 additions & 1 deletion KkuMulKum/Network/DTO/Model/Promises/MeetingPromisesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ struct MeetingPromisesModel: ResponseModelType {
}

struct MeetingPromise: Codable {
let id: Int
let promiseID: Int
let name: String
let dDay: Int
let date: String
let time: String
let placeName: String

enum CodingKeys: String, CodingKey {
case promiseID = "promiseId"
case name
case dDay
case date
case time
case placeName
}
}
7 changes: 5 additions & 2 deletions KkuMulKum/Network/TargetType/MeetingTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum MeetingTargetType {
case fetchMeetingList
case fetchMeetingInfo(meetingID: Int)
case fetchMeetingMember(meetingID: Int)
case fetchmeetingPromiseList(meetingID: Int)
}

extension MeetingTargetType: TargetType {
Expand All @@ -39,14 +40,16 @@ extension MeetingTargetType: TargetType {
return "/api/v1/meetings/\(meetingID)"
case .fetchMeetingMember(meetingID: let meetingID):
return "/api/v1/meetings/\(meetingID)/members"
case .fetchmeetingPromiseList(let meetingID):
return "/api/v1/meetings/\(meetingID)/promises"
}
}

var method: Moya.Method {
switch self {
case .createMeeting, .joinMeeting:
return .post
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember:
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchmeetingPromiseList:
return .get
}
}
Expand All @@ -57,7 +60,7 @@ extension MeetingTargetType: TargetType {
return .requestJSONEncodable(request)
case .joinMeeting(request: let request):
return .requestJSONEncodable(request)
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember:
case .fetchMeetingList, .fetchMeetingInfo, .fetchMeetingMember, .fetchmeetingPromiseList:
return .requestPlain
}
}
Expand Down
12 changes: 5 additions & 7 deletions KkuMulKum/Network/TargetType/PromiseTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum PromiseTargetType {
case updatePreparationStatus(promiseID: Int)
case updateDepartureStatus(promiseID: Int)
case updateArrivalStatus(promiseID: Int)
case fetchmeetingPromiseList(meetingID: Int, request: PromiseInfoModel)
case fetchmeetingPromiseList(meetingID: Int)
case addPromise(meetingID: Int, request: AddPromiseRequestModel)
case fetchPromiseInfo(promiseID: Int)
case fetchMyReadyStatus(promiseID: Int)
Expand Down Expand Up @@ -47,10 +47,10 @@ extension PromiseTargetType: TargetType {
return "/api/v1/promises/\(promiseID)/departure"
case .updateArrivalStatus(let promiseID):
return "/api/v1/promises/\(promiseID)/arrival"
case .fetchmeetingPromiseList(let meetingID, _):
return "/api/v1/promises/\(meetingID)/promises"
case .fetchmeetingPromiseList(let meetingID):
return "/api/v1/meetings/\(meetingID)/promises"
case .addPromise(let meetingID, _):
return "/api/v1/promises/\(meetingID)/promises"
return "/api/v1/meetings/\(meetingID)/promises"
case .fetchPromiseInfo(let promiseID):
return "/api/v1/promises/\(promiseID)"
case .fetchMyReadyStatus(let promiseID):
Expand Down Expand Up @@ -85,10 +85,8 @@ extension PromiseTargetType: TargetType {
case .fetchTodayNextPromise, .fetchUpcomingPromiseList, .updatePreparationStatus,
.updateDepartureStatus, .updateArrivalStatus, .fetchPromiseInfo,
.fetchMyReadyStatus, .fetchPromiseParticipantList, .updateMyPromiseReadyStatus,
.fetchTardyInfo, .updatePromiseCompletion:
.fetchTardyInfo, .updatePromiseCompletion, .fetchmeetingPromiseList:
return .requestPlain
case .fetchmeetingPromiseList(_, let request):
return .requestJSONEncodable(request)
case .addPromise(_, let request):
return .requestJSONEncodable(request)
}
Expand Down
2 changes: 1 addition & 1 deletion KkuMulKum/Source/AddPromise/Cell/SelectMemberCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension SelectMemberCell {
func configure(with member: Member) {
self.member = member

nameLabel.setText(member.name, style: .body06, color: .gray6)
nameLabel.setText(member.name ?? " ", style: .body06, color: .gray6)
profileImageView.image = .imgProfile.withRenderingMode(.alwaysOriginal)
guard let imageURL = URL(string: member.profileImageURL ?? "") else { return }
profileImageView.kf.setImage(with: imageURL)
Expand Down
2 changes: 1 addition & 1 deletion KkuMulKum/Source/MeetingInfo/Cell/MeetingMemberCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private extension MeetingMemberCell {
let name = member.name
let imageURL = member.profileImageURL

nameLabel.setText(name, style: .caption02, color: .gray6)
nameLabel.setText(name ?? " ", style: .caption02, color: .gray6)
profileImageButton.setImage(
.imgProfile.withRenderingMode(.alwaysOriginal),
for: .normal
Expand Down
121 changes: 97 additions & 24 deletions KkuMulKum/Source/MeetingInfo/Service/MeetingInfoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,86 @@
import Foundation

protocol MeetingInfoServiceType {
func fetchMeetingInfo(with meetingID: Int) -> MeetingInfoModel?
func fetchMeetingMemberList(with meetingID: Int) -> MeetingMembersModel?
func fetchMeetingPromiseList(with meetingID: Int) -> MeetingPromisesModel?
func fetchMeetingInfo(with meetingID: Int) async throws -> ResponseBodyDTO<MeetingInfoModel>?
func fetchMeetingMemberList(
with meetingID: Int
) async throws -> ResponseBodyDTO<MeetingMembersModel>?
func fetchMeetingPromiseList(
with meetingID: Int
) async throws -> ResponseBodyDTO<MeetingPromisesModel>?
}

extension MeetingService: MeetingInfoServiceType {
func fetchMeetingInfo(with meetingID: Int) async throws -> ResponseBodyDTO<MeetingInfoModel>? {
try await withCheckedThrowingContinuation { continuation in
provider.request(.fetchMeetingInfo(meetingID: meetingID)) { result in
switch result {
case .success(let response):
do {
let decodedData = try JSONDecoder().decode(
ResponseBodyDTO<MeetingInfoModel>.self,
from: response.data
)
continuation.resume(returning: decodedData)
} catch {
continuation.resume(throwing: error)
}
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func fetchMeetingMemberList(
with meetingID: Int
) async throws -> ResponseBodyDTO<MeetingMembersModel>? {
try await withCheckedThrowingContinuation { continuation in
provider.request(.fetchMeetingMember(meetingID: meetingID)) { result in
switch result {
case .success(let response):
do {
let decodedData = try JSONDecoder().decode(
ResponseBodyDTO<MeetingMembersModel>.self,
from: response.data
)
continuation.resume(returning: decodedData)
} catch {
continuation.resume(throwing: error)
}
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func fetchMeetingPromiseList(
with meetingID: Int
) async throws -> ResponseBodyDTO<MeetingPromisesModel>? {
try await withCheckedThrowingContinuation { continuation in
provider.request(.fetchmeetingPromiseList(meetingID: meetingID)) { result in
switch result {
case .success(let response):
do {
let decodedData = try JSONDecoder().decode(
ResponseBodyDTO<MeetingPromisesModel>.self,
from: response.data
)
continuation.resume(returning: decodedData)
} catch {
continuation.resume(throwing: error)
}
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
}

final class MockMeetingInfoService: MeetingInfoServiceType {
func fetchMeetingInfo(with meetingID: Int) -> MeetingInfoModel? {
func fetchMeetingInfo(with meetingID: Int) -> ResponseBodyDTO<MeetingInfoModel>? {
let mockData = MeetingInfoModel(
meetingID: 1,
name: "웅웅난진웅",
Expand All @@ -23,10 +96,10 @@ final class MockMeetingInfoService: MeetingInfoServiceType {
invitationCode: "WD56CQ"
)

return mockData
return ResponseBodyDTO(success: true, data: mockData, error: nil)
}

func fetchMeetingMemberList(with meetingID: Int) -> MeetingMembersModel? {
func fetchMeetingMemberList(with meetingID: Int) -> ResponseBodyDTO<MeetingMembersModel>? {
let mockData = MeetingMembersModel(
memberCount: 14,
members: [
Expand Down Expand Up @@ -103,126 +176,126 @@ final class MockMeetingInfoService: MeetingInfoServiceType {
]
)

return mockData
return ResponseBodyDTO(success: true, data: mockData, error: nil)
}

func fetchMeetingPromiseList(with meetingID: Int) -> MeetingPromisesModel? {
func fetchMeetingPromiseList(with meetingID: Int) -> ResponseBodyDTO<MeetingPromisesModel>? {
let mockData = MeetingPromisesModel(
promises: [
MeetingPromise(
id: 1,
promiseID: 1,
name: "꾸물 리프레시 데이",
dDay: 0,
date: "2024.07.20",
time: "PM 2:00",
placeName: "DMC역"
),
MeetingPromise(
id: 2,
promiseID: 2,
name: "꾸물 잼얘 나이트",
dDay: 10,
date: "2024.07.30",
time: "PM 6:00",
placeName: "홍대입구"
),
MeetingPromise(
id: 3,
promiseID: 3,
name: "친구 생일 파티",
dDay: 5,
date: "2024.07.25",
time: "PM 7:00",
placeName: "강남역"
),
MeetingPromise(
id: 4,
promiseID: 4,
name: "주말 산책",
dDay: 3,
date: "2024.07.23",
time: "AM 10:00",
placeName: "서울숲"
),
MeetingPromise(
id: 5,
promiseID: 5,
name: "프로젝트 미팅",
dDay: 1,
date: "2024.07.21",
time: "AM 9:00",
placeName: "삼성역"
),
MeetingPromise(
id: 6,
promiseID: 6,
name: "독서 모임",
dDay: 7,
date: "2024.07.27",
time: "PM 3:00",
placeName: "합정역"
),
MeetingPromise(
id: 7,
promiseID: 7,
name: "헬스클럽 모임",
dDay: 2,
date: "2024.07.22",
time: "AM 8:00",
placeName: "신촌역"
),
MeetingPromise(
id: 8,
promiseID: 8,
name: "영화 관람",
dDay: 4,
date: "2024.07.24",
time: "PM 8:00",
placeName: "잠실역"
),
MeetingPromise(
id: 9,
promiseID: 9,
name: "저녁 식사",
dDay: 6,
date: "2024.07.26",
time: "PM 7:30",
placeName: "이태원역"
),
MeetingPromise(
id: 10,
promiseID: 10,
name: "아침 조깅",
dDay: 14,
date: "2024.08.03",
time: "AM 6:00",
placeName: "한강공원"
),
MeetingPromise(
id: 11,
promiseID: 11,
name: "커피 브레이크",
dDay: 8,
date: "2024.07.28",
time: "PM 4:00",
placeName: "을지로입구"
),
MeetingPromise(
id: 12,
promiseID: 12,
name: "스터디 그룹",
dDay: 12,
date: "2024.08.01",
time: "PM 5:00",
placeName: "강남역"
),
MeetingPromise(
id: 13,
promiseID: 13,
name: "뮤직 페스티벌",
dDay: 9,
date: "2024.07.29",
time: "PM 2:00",
placeName: "난지공원"
),
MeetingPromise(
id: 14,
promiseID: 14,
name: "낚시 여행",
dDay: 11,
date: "2024.07.31",
time: "AM 5:00",
placeName: "속초항"
),
MeetingPromise(
id: 15,
promiseID: 15,
name: "가족 모임",
dDay: 13,
date: "2024.08.02",
Expand All @@ -232,6 +305,6 @@ final class MockMeetingInfoService: MeetingInfoServiceType {
]
)

return mockData
return ResponseBodyDTO(success: true, data: mockData, error: nil)
}
}
Loading

0 comments on commit 28892e1

Please sign in to comment.