-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuthAPI.swift
More file actions
110 lines (98 loc) · 2.69 KB
/
OAuthAPI.swift
File metadata and controls
110 lines (98 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// OAuthAPI.swift
// Data
//
// Created by Claude on 3/15/26.
// Copyright © 2026 com.photi. All rights reserved.
//
import Foundation
import Core
import DTO
import PhotiNetwork
public enum OAuthAPI {
case login(provider: String, idToken: String)
case setUsername(dto: OAuthUsernameRequestDTO)
/// 카카오/구글 탈퇴 - 클라이언트에서 unlink 후 호출
case withdrawKakaoGoogle(dto: OAuthWithdrawRequestDTO)
/// 애플 탈퇴 - 서버에서 revoke 처리
case withdrawApple(accessToken: String)
}
extension OAuthAPI: TargetType {
public var baseURL: URL {
return ServiceConfiguration.shared.baseUrl
}
public var path: String {
switch self {
case let .login(provider, _):
return "oauth/\(provider)/login"
case .setUsername:
return "oauth/username"
case .withdrawKakaoGoogle:
return "oauth/withdraw"
case .withdrawApple:
return "oauth/apple/withdraw"
}
}
public var method: HTTPMethod {
switch self {
case .login:
return .get
case .setUsername:
return .post
case .withdrawKakaoGoogle, .withdrawApple:
return .patch
}
}
public var task: TaskType {
switch self {
case let .login(_, idToken):
let parameters = ["id_token": idToken]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case let .setUsername(dto):
return .requestJSONEncodable(dto)
case let .withdrawKakaoGoogle(dto):
return .requestJSONEncodable(dto)
case let .withdrawApple(accessToken):
let parameters = ["access_token": accessToken]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
}
}
public var sampleResponse: EndpointSampleResponse {
switch self {
case .login:
let data = """
{
"code": "200 OK",
"message": "성공",
"data": {
"username": null
}
}
"""
let jsonData = data.data(using: .utf8)
return .networkResponse(200, jsonData ?? Data(), "", "")
case .setUsername:
let data = """
{
"code": "200 OK",
"message": "성공",
"data": null
}
"""
let jsonData = data.data(using: .utf8)
return .networkResponse(200, jsonData ?? Data(), "", "")
case .withdrawKakaoGoogle, .withdrawApple:
let data = """
{
"code": "200 OK",
"message": "성공",
"data": {
"successMessage": "string"
}
}
"""
let jsonData = data.data(using: .utf8)
return .networkResponse(200, jsonData ?? Data(), "", "")
}
}
}