Skip to content

Commit

Permalink
Merge pull request #409 from School-of-Company/395-add-search-post-co…
Browse files Browse the repository at this point in the history
…de-feature

🔀 :: [#395] 강의 장소 우편번호 검색 기능 추가
  • Loading branch information
uuuunseo authored Aug 16, 2024
2 parents d1122c8 + 87d873a commit 3d08f52
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ final class InputLectureViewModel: BaseViewModel {
lectureDates: [],
lectureType: "상호학점인정교육과정",
credit: 0,
maxRegisteredUser: 0
maxRegisteredUser: 0,
address: "",
locationDetails: "",
essentialComplete: true
)

let lectureID: String
Expand Down Expand Up @@ -66,7 +69,10 @@ final class InputLectureViewModel: BaseViewModel {
lectureDates: detailInfo.lectureDates,
lectureType: detailInfo.lectureType,
credit: detailInfo.credit,
maxRegisteredUser: detailInfo.maxRegisteredUser
maxRegisteredUser: detailInfo.maxRegisteredUser,
address: detailInfo.address,
locationDetails: detailInfo.locationDetails,
essentialComplete: detailInfo.essentialComplete
)
}

Expand Down Expand Up @@ -106,7 +112,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: response.lectureType,
credit: response.credit,
maxRegisteredUser: response.credit
maxRegisteredUser: response.credit,
address: response.address,
locationDetails: response.locationDetails,
essentialComplete: response.essentialComplete
)
}

Expand Down Expand Up @@ -154,7 +163,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: lectureInfo.lectureType,
credit: lectureInfo.credit,
maxRegisteredUser: lectureInfo.maxRegisteredUser
maxRegisteredUser: lectureInfo.maxRegisteredUser,
address: lectureInfo.address,
locationDetails: lectureInfo.locationDetails,
essentialComplete: lectureInfo.essentialComplete
)
)
}
Expand All @@ -181,7 +193,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: lectureInfo.lectureType,
credit: lectureInfo.credit,
maxRegisteredUser: lectureInfo.maxRegisteredUser
maxRegisteredUser: lectureInfo.maxRegisteredUser,
address: lectureInfo.address,
locationDetails: lectureInfo.locationDetails,
essentialComplete: lectureInfo.essentialComplete
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public struct LectureDataModel: Equatable {
let lectureType: String
let credit: Int
let maxRegisteredUser: Int
let address: String
let locationDetails: String
let essentialComplete: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ApplicationPeriodView: View {

VStack(alignment: .leading, spacing: 8) {
BitgouelText(
text: "마감일",
text: "신청 마감일",
font: .text1
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SwiftUI

struct LectureLocationView: View {
@Binding var isShowingPostCodeSheet: Bool
@Binding var address: String
@Binding var locationDetail: String

var body: some View {
VStack(alignment: .leading, spacing: 8) {
BitgouelText(
text: "강의 장소",
font: .text1
)

PickerTextField(
"지번, 도로명 주소 검색",
text: address
) {
isShowingPostCodeSheet = true
}

BitgouelTextField(
"상세 주소 입력",
text: $locationDetail
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ struct LectureDetailSettingView: View {
)
)

LectureLocationView(
isShowingPostCodeSheet: $viewModel.isShowingPostCodeSheet,
address: $viewModel.selectedAddress,
locationDetail: $viewModel.enteredLocationDetail
)

LectureDatesView(
lectureDatesList: viewModel.lectureDatesList
) { completeDate, index in
Expand Down Expand Up @@ -217,6 +223,15 @@ struct LectureDetailSettingView: View {
viewModel.resetKeyword()
}
}
.sheet(isPresented: $viewModel.isShowingPostCodeSheet) {
if let url = viewModel.postCodeWebURL {
KakaoPostCodeView(
request: URLRequest(url: url),
isShowingKakaoWebSheet: $viewModel.isShowingPostCodeSheet,
address: $viewModel.selectedAddress
)
}
}
.onTapGesture {
hideKeyboard()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ final class LectureDetailSettingViewModel: BaseViewModel {
@Published var selectedMaxRegisteredUser: Int = 0
@Published var isShowingMaxRegisteredUserBottomSheet: Bool = false

// MARK: Location
@Published var isShowingPostCodeSheet: Bool = false
@Published var selectedAddress: String = ""
@Published var enteredLocationDetail: String = ""

@Published var isEssential: Bool = true
@Published var keyword: String = ""
@Published var detailInfo: LectureDataModel
let completion: (LectureDataModel) -> Void
let postCodeWebURL: URL? = URL(string: "https://uuuunseo.github.io/DaumWeb/")

private let searchInstructorUseCase: any SearchInstructorUseCase
private let searchLineUseCase: any SearchLineUseCase
Expand Down Expand Up @@ -240,7 +246,10 @@ final class LectureDetailSettingViewModel: BaseViewModel {
lectureDates: lectureDatesList,
lectureType: lectureTypeString,
credit: selectedCredit,
maxRegisteredUser: selectedMaxRegisteredUser
maxRegisteredUser: selectedMaxRegisteredUser,
address: selectedAddress,
locationDetails: enteredLocationDetail,
essentialComplete: isEssential
)

completion(detailInfo)
Expand All @@ -258,6 +267,7 @@ final class LectureDetailSettingViewModel: BaseViewModel {
updateLectureType(lectureType: detailInfo.lectureType)
updateCredit(credit: detailInfo.credit)
updateMaxRegisterUser(maxRegisterUser: detailInfo.maxRegisteredUser)
updateIsEssential(isEssential: detailInfo.essentialComplete)
}

@MainActor
Expand Down
90 changes: 90 additions & 0 deletions App/Sources/Utils/View/KakaoPostCodeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import SwiftUI
import WebKit

struct KakaoPostCodeView: UIViewRepresentable {
let request: URLRequest
var webView: WKWebView?
@Binding var isShowingKakaoWebSheet: Bool
@Binding var address: String

init(
request: URLRequest,
isShowingKakaoWebSheet: Binding<Bool>,
address: Binding<String>
) {
self.webView = WKWebView()
self.request = request
self._isShowingKakaoWebSheet = isShowingKakaoWebSheet
self._address = address
self.webView?.configuration.userContentController.add(KakaoWebController(isShowingkakaoWebSheet: _isShowingKakaoWebSheet, address: _address), name: "callBackHandler")
}

func makeUIView(context: Context) -> WKWebView {
return webView!
}

func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}

func makeCoordinator() -> Coordinator {
Coordinator(parent: self)
}

class Coordinator: NSObject, WKNavigationDelegate {
let parent: KakaoPostCodeView

init(parent: KakaoPostCodeView) {
self.parent = parent
}
}
}

class KakaoWebController: NSObject, WKScriptMessageHandler {
@Binding var isShowingKakaoWebSheet: Bool
@Binding var address: String

init(
isShowingkakaoWebSheet: Binding<Bool>,
address: Binding<String>
) {
self._isShowingKakaoWebSheet = isShowingkakaoWebSheet
self._address = address
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "callBackHandler", let data = message.body as? [String: Any] {
if message.name == "callBackHandler" {
print("message name : \(message.name)")
print("post Message : \(message.body)")

if let roadAddress = (data["roadAddress"]) as? String {
print("roadAddress: \(roadAddress)")
address = roadAddress
print(address)
}
isShowingKakaoWebSheet.toggle()
}
}
}
}


extension KakaoPostCodeView {
func callJS(_ args: Any = "") {
webView?.evaluateJavaScript("postMessageToiOS('\(args)')") { result, error in
if let error {
print("Error \(error.localizedDescription)")
return
}

if result == nil {
print("It's void function")
return
}

print("Received Data \(result ?? "")")
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public struct InputLectureRequestDTO: Encodable {
public let lectureType: String
public let credit: Int
public let maxRegisteredUser: Int
public let address: String
public let locationDetails: String
public let essentialComplete: Bool

public init(
name: String,
Expand All @@ -28,7 +31,10 @@ public struct InputLectureRequestDTO: Encodable {
lectureDates: [LectureDateInfo],
lectureType: String,
credit: Int,
maxRegisteredUser: Int
maxRegisteredUser: Int,
address: String,
locationDetails: String,
essentialComplete: Bool
) {
self.name = name
self.content = content
Expand All @@ -43,6 +49,9 @@ public struct InputLectureRequestDTO: Encodable {
self.lectureType = lectureType
self.credit = credit
self.maxRegisteredUser = maxRegisteredUser
self.address = address
self.locationDetails = locationDetails
self.essentialComplete = essentialComplete
}

enum CodingKeys: String, CodingKey {
Expand All @@ -59,6 +68,9 @@ public struct InputLectureRequestDTO: Encodable {
case lectureType
case credit
case maxRegisteredUser
case address
case locationDetails
case essentialComplete
}

public struct LectureDateInfo: Encodable {
Expand Down

0 comments on commit 3d08f52

Please sign in to comment.