Skip to content

Commit

Permalink
Merge branch 'Dev' into HZ
Browse files Browse the repository at this point in the history
  • Loading branch information
dlguszoo committed Nov 23, 2024
2 parents 2ccc95f + 0cf441a commit ac583d2
Show file tree
Hide file tree
Showing 59 changed files with 2,163 additions and 373 deletions.
10 changes: 10 additions & 0 deletions DropDrug/Sources/APIServices/Auth/LoginService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ enum LoginService {
// SNS 로그인
case postGoogleLogin(param: OAuthSocialLoginRequest)
case postKakaoLogin(param: OAuthSocialLoginRequest)
case postAppleLogin(param: OAuthAppleLoginRequest)

// 기타
case postLogOut(accessToken: String)
case postQuit(token: String)

//리프레시
case refreshAccessToken(token: String)
}

extension LoginService: TargetType {
Expand All @@ -32,8 +36,10 @@ extension LoginService: TargetType {
case .postRegister: return "auth/signup/pw"
case .postKakaoLogin: return "auth/login/kakao"
case .postGoogleLogin: return "auth/login/google"
case .postAppleLogin: return "auth/login/apple"
case .postLogOut: return "auth/logout"
case .postQuit: return "auth/quit"
case .refreshAccessToken: return "auth/refresh"
}
}

Expand All @@ -51,10 +57,14 @@ extension LoginService: TargetType {
return .requestJSONEncodable(param)
case .postKakaoLogin(let param) :
return .requestJSONEncodable(param)
case .postAppleLogin(let param) :
return .requestJSONEncodable(param)
case .postLogOut(let accessToken) :
return .requestParameters(parameters: ["accessToken": accessToken], encoding: JSONEncoding.default)
case .postQuit(let accessToken) :
return .requestParameters(parameters: ["token": accessToken], encoding: JSONEncoding.default)
case .refreshAccessToken(let accessToken) :
return .requestParameters(parameters: ["token": accessToken], encoding: JSONEncoding.default)
}
}

Expand Down
2 changes: 1 addition & 1 deletion DropDrug/Sources/APIServices/BearerToken+Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Moya

final class BearerTokenPlugin: PluginType {
private var accessToken: String? {
return SelectLoginTypeVC.keychain.get("serverRefreshToken")
return SelectLoginTypeVC.keychain.get("serverAccessToken")
}

func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
Expand Down
36 changes: 13 additions & 23 deletions DropDrug/Sources/APIServices/MyPage/MemberAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ enum MemberAPI {
case purchaseCharacter(characterId: Int) // 캐릭터 구매
case updateCharacter(characterId: Int) // 캐릭터 변경
case updateNickname(newNickname: String) // 닉네임 변경
case updateNotificationSettings(disposal: Bool, noticeboard: Bool, reward: Bool) // 알림 설정 변경
case updateNotificationSettings(param: NotificationSetting) // 알림 설정 변경
}

extension MemberAPI: TargetType {
var baseURL: URL {
return URL(string: "http://54.180.45.153:8080")!
guard let url = URL(string: Constants.NetworkManager.baseURL) else {
fatalError("fatal error - invalid url")
}
return url
}

var path: String {
switch self {
case .fetchMemberInfo:
return "/members"
return "members"
case .purchaseCharacter(let characterId):
return "/members/character/\(characterId)"
return "members/character/\(characterId)"
case .updateCharacter(let characterId):
return "/members/character/\(characterId)"
return "members/character/\(characterId)"
case .updateNickname(let newNickname):
return "/members/nickname/\(newNickname)"
return "members/nickname/\(newNickname)"
case .updateNotificationSettings:
return "/members/notification"
return "members/notification"
}
}

Expand All @@ -53,25 +56,12 @@ extension MemberAPI: TargetType {
return .requestPlain
case .updateNickname:
return .requestPlain
case .updateNotificationSettings(let disposal, let noticeboard, let reward):
let parameters: [String: Any] = [
"disposal": disposal,
"noticeboard": noticeboard,
"reward": reward
]
return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
case .updateNotificationSettings(let param) :
return .requestJSONEncodable(param)
}
}

var headers: [String: String]? {
let keychain = KeychainSwift()
if let accessToken = keychain.get("serverRefreshToken") {
return [
"Authorization": "Bearer \(accessToken)",
"Accept": "*/*",
"Content-Type": "application/json"
]
}
return ["Accept": "*/*"]
return ["Content-Type": "application/json"]
}
}
41 changes: 41 additions & 0 deletions DropDrug/Sources/APIServices/OCR/OCRService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright © 2024 RT4. All rights reserved

import Foundation
import Moya

enum OCRService {
case postImage(data : OCRRequest)
}

extension OCRService : TargetType {
var baseURL: URL {
guard let url = URL(string: Constants.NetworkManager.OCRAPIURL) else {
fatalError("fatal error - none url")
}
return url
}

var path: String {
return "/general"
}

var method: Moya.Method {
return .post
}

var task: Moya.Task {
switch self {
case .postImage(let data) :
return .requestJSONEncodable(data)
}
}

var headers: [String : String]? {
return [
"Content-Type": "application/json",
"X-OCR-SECRET": "\(Constants.NetworkManager.OCRSecretKey)"
]
}


}
60 changes: 60 additions & 0 deletions DropDrug/Sources/APIServices/PointAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright © 2024 RT4. All rights reserved

import Foundation
import Moya
import KeychainSwift

enum PointAPI {
case getPoint
case postPoint(param: AddPointRequest)
case getPointHistory
case getMonthlyStats
}

extension PointAPI: TargetType {
var baseURL: URL {
guard let url = URL(string: Constants.NetworkManager.baseURL) else {
fatalError("fatal error - invalid url")
}
return url
}

var path: String {
switch self {
case .getPoint:
return "points"
case .postPoint:
return "points"
case .getPointHistory:
return "points/history"
case .getMonthlyStats:
return "points/monthly"
}
}

var method: Moya.Method {
switch self {
case .getPoint, .getPointHistory, .getMonthlyStats:
return .get
case .postPoint:
return .post
}
}

var task: Task {
switch self {
case .getPoint:
return .requestPlain
case .postPoint(let param):
return .requestJSONEncodable(param)
case .getPointHistory:
return .requestPlain
case .getMonthlyStats:
return .requestPlain
}
}

var headers: [String: String]? {
return ["Content-Type": "application/json"]
}
}
53 changes: 53 additions & 0 deletions DropDrug/Sources/APIServices/Register/DrugAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright © 2024 RT4. All rights reserved

import Foundation
import Moya
import KeychainSwift

enum DrugAPI {
case getDrug
case postDrug(param: drugSaveRequest)
case deleteDrug(param: drugDeleteRequest)
}

extension DrugAPI: TargetType {
var baseURL: URL {
guard let url = URL(string: Constants.NetworkManager.baseURL) else {
fatalError("fatal error - invalid url")
}
return url
}

var path: String {
switch self {
case .getDrug, .postDrug, .deleteDrug:
return "drugs"
}
}

var method: Moya.Method {
switch self {
case .getDrug:
return .get
case .postDrug:
return .post
case .deleteDrug:
return .delete
}
}

var task: Task {
switch self {
case .getDrug:
return .requestPlain
case .postDrug(let param):
return .requestJSONEncodable(param)
case .deleteDrug(let param):
return .requestJSONEncodable(param)
}
}

var headers: [String: String]? {
return ["Content-Type": "application/json"]
}
}
9 changes: 8 additions & 1 deletion DropDrug/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if let kakaoAPIkey = Bundle.main.object(forInfoDictionaryKey: "KAKAO_NATIVE_APP_KEY") as? String {
KakaoSDK.initSDK(appKey: "\(kakaoAPIkey)")
}

FirebaseApp.configure()
if FirebaseApp.app() == nil {
print("FirebaseApp is not initialized. Configuring now...")
FirebaseApp.configure()
} else {
print("FirebaseApp is initialized successfully.")
}

UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] // 필요한 알림 권한을 설정
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
Expand Down Expand Up @@ -119,6 +125,7 @@ extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")
SelectLoginTypeVC.keychain.set(fcmToken!, forKey: "FCMToken")
// print(SelectLoginTypeVC.keychain.get("appleUserFullName") ?? "저장된 이름 없음")

let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
Expand Down
63 changes: 63 additions & 0 deletions DropDrug/Sources/Cells/NotificationCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright © 2024 RT4. All rights reserved

import UIKit
import SnapKit

class NotificationCell: UITableViewCell {
// UI Components
private lazy var iconImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(systemName: "circle.fill") // SF Symbol 설정
imageView.contentMode = .scaleAspectFit // 적절한 크기 유지
imageView.tintColor = Constants.Colors.pink
return imageView
}()

private lazy var titleLabel: UILabel = {
let label = UILabel()
label.text = "Title Label" // 기본 텍스트
label.textColor = Constants.Colors.gray700
label.font = UIFont.ptdRegularFont(ofSize: 16)
label.numberOfLines = 1 // 한 줄로 제한
return label
}()

// MARK: - Initializers
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupViews()
setupConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Setup Methods
private func setupViews() {
contentView.addSubview(iconImageView)
contentView.addSubview(titleLabel)
}

private func setupConstraints() {
iconImageView.snp.makeConstraints { make in
make.top.equalTo(contentView.safeAreaLayoutGuide).offset(16) // safeArea Top + 16
make.leading.equalTo(contentView.safeAreaLayoutGuide).offset(20) // safeArea Leading + 20
make.width.height.equalTo(10) // 정사각형 크기 설정
}

titleLabel.snp.makeConstraints { make in
make.top.equalTo(iconImageView) // 이미지뷰와 동일한 Top
make.leading.equalTo(iconImageView.snp.trailing).offset(8) // 이미지뷰의 trailing + 8
make.trailing.equalTo(contentView.safeAreaLayoutGuide).offset(-20) // safeArea Trailing - 20
make.bottom.equalTo(contentView.safeAreaLayoutGuide).offset(-16)
}
}

// MARK: - Configure Method

func configure(with title: String) {
titleLabel.text = title
}

}
Loading

0 comments on commit ac583d2

Please sign in to comment.