Skip to content

Commit

Permalink
[Feat/#87] 모임 모집하기 POST API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
kms0233 committed Jan 22, 2025
1 parent 8f37c45 commit 91ba187
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 46 deletions.
12 changes: 12 additions & 0 deletions Gongbaek_iOS/Gongbaek_iOS/Global/Enum/CategoryState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ enum CategoryState: Int, CaseIterable {
}
}

var serverName: String {
switch self {
case .ALL: return "ALL"
case .STUDY: return "STUDY"
case .DINING: return "DINING"
case .EXERCISE: return "EXERCISE"
case .NETWORKING: return "NETWORKING"
case .PLAYING: return "PLAYING"
case .OTHERS: return "OTHERS"
}
}

var categoryImage: Image? {
switch self {
case .ALL: return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PostMeetingRequestDTO.swift
// Gongbaek_iOS
//
// Created by 김민서 on 1/22/25.
//

import Foundation

struct PostMeetingRequestDTO: Codable {
let groupType: String
let weekDate: String
let weekDay: String
let startTime: Double
let endTime: Double
let category: String
let coverImg: Int
let location: String
let maxPeopleCount: Int
let groupTitle: String
let introduction: String
}
1 change: 1 addition & 0 deletions Gongbaek_iOS/Gongbaek_iOS/Network/Service/Providers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Moya

struct Providers {
static let homeProvider = NetworkProvider<HomeTargetType>(withAuth: false)
static let fillingProvider = NetworkProvider<FillingTargetType>(withAuth: false)
}

extension MoyaProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// FillingTargetType.swift
// Gongbaek_iOS
//
// Created by 김민서 on 1/22/25.
//

import Moya

enum FillingTargetType {
case postMeeting(data: AddMeetingModel)
case getTimeTable
}

extension FillingTargetType: BaseTargetType {
var headers: Parameters? {
switch self {
case .postMeeting, .getTimeTable:
return APIConstants.hasTokenHeader
}
}

var path: String {
switch self {
case .postMeeting:
return "/api/v1/gongbaek"
case .getTimeTable:
return "/api/v1/my/timeTable"
}
}

var method: Moya.Method {
switch self {
case .postMeeting:
return .post
case .getTimeTable:
return .get
}
}

var task: Moya.Task {
switch self {
case .postMeeting(let data):
return .requestJSONEncodable(data)
case .getTimeTable:
return .requestPlain
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
// Created by 김민서 on 1/18/25.
//

import SwiftUI
import Foundation

struct AddMeetingModel {
var groupType: CycleState
var weekDate: String?
struct AddMeetingModel: Codable {
var groupType: String
var weekDate: String
var weekDay: String
var startTime: Double
var endTime: Double
var dueDate: String
var category: Category
var category: String
var coverImg: Int
var location: String
var maxPeopleCount: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
struct AddMeetingView: View {
@EnvironmentObject var navigationManager: NavigationManager
@StateObject var viewModel: AddMeetingViewModel
@State private var showAlert: Bool = false

@State private var showAlert: Bool = false
var body: some View {
ZStack {
VStack(alignment: .leading, spacing: 0) {
Expand Down Expand Up @@ -65,7 +65,7 @@ struct AddMeetingView: View {
isActivated: viewModel.isNextEnabled
) {
if isLastStep {
viewModel.checkFinalInfo()
viewModel.postMeeting()
showAlert = true
} else {
viewModel.goToNextPage()
Expand All @@ -75,9 +75,11 @@ struct AddMeetingView: View {
.padding(.horizontal, 16)
}

var image = viewModel.isSuccessGetData ? "img_success" : "img_fail"

if showAlert {
CustomedAlert(
alertImage: viewModel.isSuccessGetData ? "img_success" : "img_fail",
alertImage: image ,
titleText: viewModel.isSuccessGetData ? "모임 등록이 완료됐어요!" : "모임 등록에 실패했어요!",
orangeButtonText: "확인",
onTapOrangeButton: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import SwiftUI

class AddMeetingViewModel: ObservableObject {

let totalSteps: Int = 8

@Published var currentIndex: Int = 0

@Published var isNextEnabled: Bool = false
Expand Down Expand Up @@ -60,13 +63,12 @@ class AddMeetingViewModel: ObservableObject {
didSet { updateNextButtonState() }
}

@Published var isSuccessGetData: Bool = false
@Published var isSuccessGetData: Bool = true

init() {
getTimeTable()
}


var selectedFormattedDate: String? {
guard let date = selectedWeekDate else { return nil }
let formatter = DateFormatter()
Expand Down Expand Up @@ -139,11 +141,9 @@ class AddMeetingViewModel: ObservableObject {
default:
break
}

DispatchQueue.main.async { self.updateNextButtonState() }
}

// ✅ 선택된 날짜의 요일 업데이트
func updateSelectedWeekDay() {
guard let date = selectedWeekDate else {
selectedWeekDay = nil
Expand Down Expand Up @@ -200,32 +200,20 @@ class AddMeetingViewModel: ObservableObject {
guard let selectedDate = selectedWeekDate else { return "날짜 선택 필요" }

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "M월 d일 EEEE" // ex) "4월 8일 화요일"
dateFormatter.dateFormat = "M월 d일 EEEE"
dateFormatter.locale = Locale(identifier: "ko_KR")

let formattedDate = dateFormatter.string(from: selectedDate)
return "\(formattedDate) \(startHour)시 - \(endHour)"

} else if selectedCycle == .weekly {
// ✅ "매주(Weekly)" 선택 시 → "매주 수요일 12시 - 15시"
guard let selectedWeekDay = selectedWeekDay else { return "요일 선택 필요" }
return "매주 \(selectedWeekDay.rawValue) \(startHour)시 - \(endHour)"
}

return "날짜와 시간을 선택해주세요."
}

//TODO: 여기가 API 호출 메서드 부분
func checkFinalInfo() {
isSuccessGetData = true

print("📝 최종 입력된 모임 정보:")
print("▶ groupType: \(selectedCycle == .once ? "ONCE" : "WEEKLY")")

if let weekDate = selectedFormattedDate {
print("▶ weekDate: \(weekDate)")
} else {
print("▶ weekDate: nil")
func getTimeTable() {
Providers.fillingProvider.request(target: .getTimeTable, instance: BaseResponse<GetTimeTableResponseDTO>.self) { response in
guard response.success, let timeTableResponse = response.data else {
Expand All @@ -237,28 +225,44 @@ class AddMeetingViewModel: ObservableObject {
self.timeTable = timeTableResponse.timeTable
}
}

if let weekDay = selectedWeekDay?.englishName {
print("▶ weekDay: \(weekDay)") // ✅ 옵셔널 바인딩하여 안전하게 출력
} else {
print("▶ weekDay: 없음")
}

func postMeeting() {
guard let selectedCoverIndex = selectedCoverIndex else {
return
}

print("▶ startTime: \(selectedTimeRange.start)")
print("▶ endTime: \(selectedTimeRange.end)")
print("▶ dueDate: \(selectedFormattedDate ?? nil)")
let weekDate: String = selectedFormattedDate ?? ""

if let category = selectedCategory {
print("▶ category: \(category)")
} else {
print("▶ category: 없음")
}
print("🛠️ 최종 weekDate 값: \(weekDate)")

//이미지 인덱스는 + 1 해서 보내기
print("▶ coverImg: \(selectedCoverIndex ?? +1)")
print("▶ location: \(location)")
print("▶ maxPeopleCount: \(maxPeopleCount)")
print("▶ groupTitle: \(title)")
print("▶ introduction: \(introduction)")
let requestData = AddMeetingModel(
groupType: selectedCycle == .once ? "ONCE" : "WEEKLY",
weekDate: selectedFormattedDate ?? "" ,
weekDay: selectedWeekDay?.englishName ?? "MON",
startTime: selectedTimeRange.start,
endTime: selectedTimeRange.end,
category: selectedCategory?.serverName ?? "",
coverImg: selectedCoverIndex + 1,
location: location,
maxPeopleCount: maxPeopleCount,
groupTitle: title,
introduction: introduction
)

Providers.fillingProvider.request(target: .postMeeting(data: requestData), instance: BaseResponse<EmptyResponseDTO>.self) { response in
print(requestData)
DispatchQueue.main.async {
if response.success {
self.isSuccessGetData = true
print("✅ 모임 등록 성공!")
} else {
self.isSuccessGetData = false
print("❌ 모임 등록 실패: \(response.message ?? "알 수 없는 오류")")
}
}
}
}
}


0 comments on commit 91ba187

Please sign in to comment.