Skip to content

Commit

Permalink
Merge pull request #125 from tukcomCD2024/DeviOS
Browse files Browse the repository at this point in the history
Devi os
  • Loading branch information
realhsb authored May 16, 2024
2 parents 131319e + 5c7ada0 commit 50af019
Show file tree
Hide file tree
Showing 24 changed files with 728 additions and 309 deletions.
86 changes: 67 additions & 19 deletions iOS/RollTheDice/RollTheDice.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions iOS/RollTheDice/RollTheDice/Resources/Font/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension Font {

// Regular
static let pretendardRegular20: Font = .custom("Pretendard-Regular", size: 20)
static let pretendardRegular16: Font = .custom("Pretendard-Regular", size: 16)
static let pretendardRegular14: Font = .custom("Pretendard-Regular", size: 14)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIAppFonts</key>
<array>
<string>Pretendard-Black.otf</string>
Expand Down
6 changes: 3 additions & 3 deletions iOS/RollTheDice/RollTheDice/RollTheDiceApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct RollTheDiceApp: App {
@StateObject var appState = AppState()
@StateObject private var pathModel = PathModel()

@StateObject var newsListViewModel = NewsListViewModel()
var newsListViewModel = NewsListViewModel()
@StateObject var bookmarkListViewModel = BookmarkListViewModel()

var body: some Scene {
Expand All @@ -33,8 +33,8 @@ struct RollTheDiceApp: App {
case .chatView(isAiMode: false):
Text("user")
.navigationBarBackButtonHidden()
case .detailNewsView:
DetailCardNews()
case .detailNewsView(let newsId):
DetailCardNews(newsId: newsId)
case .typeReportView:
TypeReportView()
case .dailyReportView:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

import Foundation

public class APIHeaderManger {
public class APIHeaderManager {

static let shared = APIHeaderManger()
static let shared = APIHeaderManager()

let contentType: String = "application/json"
let rtdHost: String = "localhost:8080"
let scoopHost: String = "ec2-13-124-191-244.ap-northeast-2.compute.amazonaws.com:8080"
}


// http://ec2-13-124-191-244.ap-northeast-2.compute.amazonaws.com:8080/swagger-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
import Foundation

struct APIConstants{
// static var viewModel: BoardViewModel = BoardViewModel()
static let contentType = "Content-Type"
static let host = "Host"
// static let Cookie = "Cookie"

}

extension APIConstants {
static var baseHeader: Dictionary<String, String> {
[
contentType : APIHeaderManger.shared.contentType,
host : APIHeaderManger.shared.rtdHost,
// Cookie : "accessToken=\(viewModel.authCodeToken)"
contentType : APIHeaderManager.shared.contentType,
host : APIHeaderManager.shared.scoopHost,
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol BaseTargetType: TargetType {}

extension BaseTargetType {
public var baseURL: URL {
return URL(string: RollTheDiceAPI.baseURL)!
return URL(string: ScoopAPI.baseURL)!
}

public var headers: [String : String]? {
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions iOS/RollTheDice/RollTheDice/Source/Domain/ScoopAPI/ScoopAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// RollTheDiceAPI.swift
// RollTheDice
//
// Created by Subeen on 3/21/24.
//

import Foundation

enum ScoopAPI {
static let baseURL = "http://ec2-13-124-191-244.ap-northeast-2.compute.amazonaws.com:8080"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

public enum RollTheDiceAPINews {
public enum ScoopAPINews {
public static let newsFetch = String("/news")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Extension+Log.swift
// RollTheDice
//
// Created by Subeen on 5/14/24.
//

import Foundation

public extension Log {
//MARK: - 디버그
static func debug(_ message: Any, _ arguments: Any...) {
log(message, arguments, level: .debug)
}

//MARK: - 문제 해결시 활용할 수 있는, 도움이 되지만 필수적이지 않은 정보 로거
/**
# info
- Authors : suni
- Note : 문제 해결시 활용할 수 있는, 도움이 되지만 필수적이지 않은 정보
*/
static func info(_ message: Any, _ arguments: Any...) {
log(message, arguments, level: .info)
}


//MARK: - 네트워크 로거
static func network(_ message: Any, _ arguments: Any...) {
log(message, arguments, level: .network)
}

//MARK: - 에러 로거
static func error(_ message: Any, _ arguments: Any...) {
log(message, arguments, level: .error)
}

//MARK: - 커스텀 로거
static func custom(category: String, _ message: Any, _ arguments: Any...) {
log(message, arguments, level: .custom(category: category))
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Extension+OSLog.swift
// RollTheDice
//
// Created by Subeen on 5/14/24.
//

import Foundation
import OSLog

extension OSLog {
static let subsystem = Bundle.main.bundleIdentifier!
static let network = OSLog(subsystem: subsystem, category: "Network")
static let debug = OSLog(subsystem: subsystem, category: "Debug")
static let info = OSLog(subsystem: subsystem, category: "Info")
static let error = OSLog(subsystem: subsystem, category: "Error")
}

99 changes: 99 additions & 0 deletions iOS/RollTheDice/RollTheDice/Source/Domain/Service/Log/Log.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// Log.swift
// RollTheDice
//
// Created by Subeen on 5/14/24.
//

import Foundation
import OSLog

public struct Log {
public init(){}

public enum LogLevel {
/// 디버깅 로그
case debug
/// 문제 해결 정보
case info
/// 네트워크 로그
case network
/// 오류 로그
case error
case custom(category: String)

fileprivate var category: String {
switch self {
case .debug:
return "🟡 DEBUG"
case .info:
return "🟠 INFO"
case .network:
return "🔵 NETWORK"
case .error:
return "🔴 ERROR"
case .custom(let category):
return "🟢 \(category)"
}
}

fileprivate var osLog: OSLog {
switch self {
case .debug:
return OSLog.debug
case .info:
return OSLog.info
case .network:
return OSLog.network
case .error:
return OSLog.error
case .custom:
return OSLog.debug
}
}

fileprivate var osLogType: OSLogType {
switch self {
case .debug:
return .debug
case .info:
return .info
case .network:
return .default
case .error:
return .error
case .custom:
return .debug
}
}


}


static func log(_ message: Any, _ arguments: [Any], level: LogLevel) {
#if DEBUG
if #available(iOS 14.0, *) {
let extraMessage: String = arguments.map({ String(describing: $0) }).joined(separator: " ")
let logger = Logger(subsystem: OSLog.subsystem, category: level.category)
let logMessage = "\(message) \(extraMessage)"
switch level {
case .debug,
.custom:
logger.debug("\(logMessage, privacy: .public)")
case .info:
logger.info("\(logMessage, privacy: .public)")
case .network:
logger.log("\(logMessage, privacy: .public)")
case .error:
logger.error("\(logMessage, privacy: .public)")
}
} else {
let extraMessage: String = arguments.map({ String(describing: $0) }).joined(separator: " ")
os_log("%{public}@", log: level.osLog, type: level.osLogType, "\(message) \(extraMessage)")
}
#endif
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// MoyaLoggingPlugin.swift
// RollTheDice
//
// Created by Subeen on 5/14/24.
//

// 네트워킹 로그 확인

import UIKit
import Moya
import OSLog

public class MoyaLoggingPlugin: PluginType {

public init() {}

public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
return request
}
// Request를 보낼 때 호출
public func willSend(_ request: RequestType, target: TargetType) {
guard let httpRequest = request.request else {
#if DEBUG
Log.network("--> 유효하지 않은 요청", (Any).self)
#endif
return
}

let url = httpRequest.description
let method = httpRequest.httpMethod ?? "메소드값이 nil입니다."
var log = """
⎡---------------------서버통신을 시작합니다.----------------------⎤
[\(method)] \(url)
API: \(target) \n
"""
if let headers = httpRequest.allHTTPHeaderFields, !headers.isEmpty {
log.append("header:\n \(headers) \n")
}
if let body = httpRequest.httpBody, let bodyString = String(bytes: body, encoding: String.Encoding.utf8) {
log.append("\(bodyString)\n")
}

log.append("⎣------------------ Request END -------------------------⎦")
#if DEBUG
Log.network("", log)
#endif
}
// Response가 왔을 때
public func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
switch result {
case let .success(response):
onSucceed(response, target: target, isFromError: false)
case let .failure(error):
onFail(error, target: target)
}
}

public func process(_ result: Result<Response, MoyaError>, target: TargetType) -> Result<Response, MoyaError> {
return result
}

public func onSucceed(_ response: Response, target: TargetType, isFromError: Bool) {
let request = response.request
let url = request?.url?.absoluteString ?? "nil"
let statusCode = response.statusCode
var log = "⎡------------------서버에게 Response가 도착했습니다. ------------------⎤\n"
log.append("API: \(target)\n")
log.append("Status Code: [\(statusCode)]\n")
log.append("URL: \(url)\n")
if let responseData = String(bytes: response.data.map{$0}, encoding: String.Encoding.utf8) {
log.append("Data: \n \(responseData)\n")
}
log.append("⎣------------------ END HTTP (\(response.data.count)-byte body) ------------------⎦")
#if DEBUG

Log.network("", log)
#endif

}

public func onFail(_ error: MoyaError, target: TargetType) {
if let response = error.response {
onSucceed(response, target: target, isFromError: true)
return
}
var log = "네트워크 오류"
log.append("<-- \(error.errorCode) \(target)\n")
log.append("\(error.failureReason ?? error.errorDescription ?? "unknown error")\n")
log.append("<-- END HTTP")
#if DEBUG
Log.network("", log)
#endif

}
}
Loading

0 comments on commit 50af019

Please sign in to comment.