설정 페이지 추가

This commit is contained in:
Yu Sung
2023-08-10 22:05:14 +09:00
parent d06f4d6a36
commit dbeb15ba17
24 changed files with 1368 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
//
// Terms.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
struct Terms: Decodable {
let title: String
let description: String
}

View File

@@ -0,0 +1,42 @@
//
// TermsApi.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
import Moya
enum TermsApi {
case terms
case privacy
}
extension TermsApi: TargetType {
var baseURL: URL {
return URL(string: BASE_URL)!
}
var path: String {
switch self {
case .terms:
return "/stplat/terms_of_service"
case .privacy:
return "/stplat/privacy_policy"
}
}
var method: Moya.Method {
return .get
}
var task: Task {
return .requestPlain
}
var headers: [String : String]? {
return nil
}
}

View File

@@ -0,0 +1,23 @@
//
// TermsRepository.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
import CombineMoya
import Combine
import Moya
final class TermsRepository {
private let api = MoyaProvider<TermsApi>()
func getTermsOfService() -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.terms)
}
func getPrivacyPolicy() -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.privacy)
}
}

View File

@@ -0,0 +1,42 @@
//
// TermsView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
import RichText
struct TermsView: View {
let isPrivacyPolicy: Bool
@ObservedObject var viewModel = TermsViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: viewModel.title)
ScrollView(.vertical, showsIndicators: false) {
RichText(html: viewModel.description)
.frame(width: screenSize().width - 26.7)
}
}
}
.onAppear {
if isPrivacyPolicy {
viewModel.getPrivacyPolicy()
} else {
viewModel.getTermsOfService()
}
}
}
}
struct TermsView_Previews: PreviewProvider {
static var previews: some View {
TermsView(isPrivacyPolicy: false)
}
}

View File

@@ -0,0 +1,99 @@
//
// TermsViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
import Combine
final class TermsViewModel: ObservableObject {
private let repository = TermsRepository()
private var subscription = Set<AnyCancellable>()
@Published var title: String = ""
@Published var description: String = ""
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
func getTermsOfService() {
isLoading = true
repository.getTermsOfService()
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<Terms>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.title = data.title
self.description = data.description
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
func getPrivacyPolicy() {
isLoading = true
repository.getPrivacyPolicy()
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<Terms>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.title = data.title
self.description = data.description
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
}