Skip to content

Commit 8d98d3c

Browse files
authored
[NL-69]: 마이페이지 API 부분 연동 (#37)
* [NL-69]: 마이페이지 API 부분 연동 * [NL-69]: 피드백 반영
1 parent 08c6ad0 commit 8d98d3c

File tree

16 files changed

+222
-63
lines changed

16 files changed

+222
-63
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// AppDelegate+Assembly.swift
3+
// Satto
4+
//
5+
// Created by ttozzi on 8/15/25.
6+
//
7+
8+
import Foundation
9+
import DIInjector
10+
import Setting
11+
import Auth
12+
import NetworkCore
13+
import Lib
14+
15+
extension AppDelegate {
16+
func dependencyInjection() {
17+
DependencyInjector.shared.assemble([
18+
SettingAssembly(),
19+
AuthAssembly(),
20+
NetworkCoreAssembly(),
21+
LibAssembly()
22+
])
23+
}
24+
}

App/Sources/AppDelegate.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Auth
2-
import DIInjector
32
import Lib
43
import Onboarding
54
import Setting
@@ -12,9 +11,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1211
_ application: UIApplication,
1312
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
1413
) -> Bool {
15-
DeviceUUIDManager.setup()
14+
dependencyInjection()
1615
registRouter()
17-
1816
return true
1917
}
2018

@@ -37,13 +35,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3735
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
3836
}
3937

40-
private func dependencyInjection() {
41-
DependencyInjector.shared.assemble([
42-
CoreLayerAssembly(),
43-
SettingAssembly(),
44-
])
45-
}
46-
4738
private func registRouter() {
4839
let appRouter = AppRouter.shared
4940

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// AuthAssembly.swift
3+
// Auth
4+
//
5+
// Created by ttozzi on 8/15/25.
6+
//
7+
8+
import DIInjector
9+
import Foundation
10+
11+
public final class AuthAssembly: Assembly {
12+
public func assemble(container: Container) {
13+
container.register(DeviceUUIDManager.self) { _ in
14+
return DeviceUUIDManager.shared
15+
}
16+
container.register(UserDataManager.self) { _ in
17+
return UserDataManager.shared
18+
}
19+
}
20+
21+
public init() {}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// AuthTarget.swift
3+
// Lib
4+
//
5+
// Created by ttozzi on 8/15/25.
6+
//
7+
8+
import Base
9+
import Foundation
10+
import NetworkCore
11+
12+
enum AuthTarget {
13+
14+
struct GetUser: BaseTargetType {
15+
16+
typealias Response = UserDTO
17+
18+
var path: String { "users/\(userID)" }
19+
var httpTask: HTTPTask { .requestPlain }
20+
var httpMethod: HTTPMethod { .get }
21+
var headers: [String : String]? { nil }
22+
let userID: String
23+
}
24+
}

Common/Auth/Sources/DeviceUUIDManager.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import Foundation
99
import Lib
1010

11-
public final class DeviceUUIDManager {
11+
final class DeviceUUIDManager {
1212

1313
private enum Constant {
1414
static let uuidKey = "device-uuid"
1515
}
1616

17-
public static let shared = DeviceUUIDManager()
18-
public var deviceUUID: String {
17+
static let shared = DeviceUUIDManager()
18+
var deviceUUID: String {
1919
do {
2020
return try KeyChainService.getString(forKey: Constant.uuidKey)
2121
} catch {
@@ -37,9 +37,3 @@ public final class DeviceUUIDManager {
3737
try? KeyChainService.remove(forKey: Constant.uuidKey)
3838
}
3939
}
40-
41-
extension DeviceUUIDManager {
42-
public static func setup() {
43-
_ = shared.deviceUUID
44-
}
45-
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// UserDataManager.swift
3+
// Auth
4+
//
5+
// Created by ttozzi on 8/15/25.
6+
//
7+
8+
import Base
9+
import DIInjector
10+
import Foundation
11+
import NetworkCore
12+
13+
public final class UserDataManager {
14+
15+
public static let shared = UserDataManager()
16+
@Injected private var deviceUUIDManager: DeviceUUIDManager
17+
@Injected private var networkProvider: NetworkProvider
18+
public var user: UserDTO?
19+
20+
@discardableResult
21+
public func fetch() async throws -> UserDTO {
22+
let userID = user?.id ?? deviceUUIDManager.deviceUUID
23+
let target = AuthTarget.GetUser(userID: userID)
24+
do {
25+
let user = try await networkProvider.request(target: target)
26+
self.user = user
27+
return user
28+
} catch {
29+
// TODO: 에러 처리?
30+
throw error
31+
}
32+
}
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// UserData.swift
3+
// Auth
4+
//
5+
// Created by ttozzi on 8/15/25.
6+
//
7+
8+
import Foundation
9+
10+
public struct UserDTO: Decodable {
11+
12+
enum CodingKeys: String, CodingKey {
13+
case id, name, gender
14+
case birthDate = "birth_date"
15+
}
16+
17+
public let id: String
18+
public let name: String
19+
public let birthDate: String?
20+
public let gender: GenderDTO
21+
22+
// TODO: 사주 정보?
23+
}
24+
25+
public enum GenderDTO: String, Codable {
26+
case male = "M"
27+
case female = "F"
28+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
//
2-
// CoreLayerAssembly.swift
3-
// Satto
2+
// LibAssembly.swift
3+
// Lib
44
//
55
// Created by 최재혁 on 7/23/25.
66
//
77

88
import DIInjector
99
import Foundation
10-
import Lib
1110

12-
public class CoreLayerAssembly: Assembly {
11+
public final class LibAssembly: Assembly {
1312
public func assemble(container: Container) {
1413
container.register(AppRouter.self) { _ in
1514
return AppRouter.shared
1615
}
1716
}
17+
18+
public init() {}
1819
}

Common/Project.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ struct CommonLayer: Layer {
1515
.target(name: "Base"),
1616
.target(name: "Constant"),
1717
.target(name: "Lib"),
18-
.project(target: "CoreLayer", path: "../Core"),
1918
],
2019
settings: .settings(
2120
base: [
@@ -27,15 +26,17 @@ struct CommonLayer: Layer {
2726
.createTarget(
2827
name: "Auth",
2928
dependencies: [
30-
.target(name: "Lib")
29+
.target(name: "Lib"),
30+
.target(name: "Base"),
31+
.project(target: "CoreLayer", path: "../Core"),
3132
]
3233
),
3334
.createTarget(
3435
name: "Base",
3536
dependencies: [
37+
.target(name: "Lib"),
3638
.project(target: "DesignSystem", path: "../DesignSystem"),
37-
.external(name: "Then"),
38-
.external(name: "SnapKit"),
39+
.project(target: "CoreLayer", path: "../Core"),
3940
]
4041
),
4142
.createTarget(name: "Constant"),
@@ -44,6 +45,7 @@ struct CommonLayer: Layer {
4445
dependencies: [
4546
.external(name: "Then"),
4647
.external(name: "SnapKit"),
48+
.project(target: "CoreLayer", path: "../Core"),
4749
]
4850
),
4951
.createTarget(

Core/NetworkCore/Sources/BaseTargetTyoe.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)