Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 회원가입 서버 세팅 #67

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MEEW-Client/MEEW-Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
F203E64328AD5C3000F620A6 /* AlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F203E64228AD5C3000F620A6 /* AlertViewController.swift */; };
F203E64528AD5FED00F620A6 /* AlertTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F203E64428AD5FED00F620A6 /* AlertTableViewCell.xib */; };
F22A7C2E284A3732006C6572 /* LoadingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F22A7C2D284A3732006C6572 /* LoadingView.xib */; };
F2A0A45128C8DCD80027E18C /* SignUpDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2A0A45028C8DCD80027E18C /* SignUpDataModel.swift */; };
F2A0A45328C8DDA40027E18C /* SignUpService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2A0A45228C8DDA40027E18C /* SignUpService.swift */; };
F2AC126A28AE2FCD00B844AC /* AlertTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AC126928AE2FCD00B844AC /* AlertTableViewCell.swift */; };
F2AC126D28AE306D00B844AC /* AlertDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2AC126C28AE306D00B844AC /* AlertDataModel.swift */; };
F2C6770A27C7DA320020B8F4 /* SelectCarouselLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2C6770927C7DA320020B8F4 /* SelectCarouselLayout.swift */; };
Expand Down Expand Up @@ -135,6 +137,8 @@
F203E64228AD5C3000F620A6 /* AlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertViewController.swift; sourceTree = "<group>"; };
F203E64428AD5FED00F620A6 /* AlertTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertTableViewCell.xib; sourceTree = "<group>"; };
F22A7C2D284A3732006C6572 /* LoadingView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LoadingView.xib; sourceTree = "<group>"; };
F2A0A45028C8DCD80027E18C /* SignUpDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpDataModel.swift; sourceTree = "<group>"; };
F2A0A45228C8DDA40027E18C /* SignUpService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpService.swift; sourceTree = "<group>"; };
F2AC126928AE2FCD00B844AC /* AlertTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertTableViewCell.swift; sourceTree = "<group>"; };
F2AC126C28AE306D00B844AC /* AlertDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertDataModel.swift; sourceTree = "<group>"; };
F2C6770927C7DA320020B8F4 /* SelectCarouselLayout.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = SelectCarouselLayout.swift; sourceTree = "<group>"; tabWidth = 4; };
Expand Down Expand Up @@ -329,6 +333,7 @@
children = (
BD339A3627493F3A00021E91 /* GenericResponse.swift */,
F2EC3A102749A47B00805FE3 /* CharacterRequestDataModel.swift */,
F2A0A45028C8DCD80027E18C /* SignUpDataModel.swift */,
);
path = APIModels;
sourceTree = "<group>";
Expand All @@ -338,6 +343,7 @@
children = (
BD339A3427493EEB00021E91 /* NetworkResult.swift */,
F2EC3A0E2749A1D400805FE3 /* CharacterListService.swift */,
F2A0A45228C8DDA40027E18C /* SignUpService.swift */,
);
path = APIServices;
sourceTree = "<group>";
Expand Down Expand Up @@ -788,8 +794,10 @@
BD3B54742852038F003D91D3 /* ProfileView.swift in Sources */,
BD339A1F27493B9E00021E91 /* BaseVC.swift in Sources */,
BD339A2827493C5600021E91 /* Palette.swift in Sources */,
F2A0A45328C8DDA40027E18C /* SignUpService.swift in Sources */,
BD45C415274947C600229D35 /* SelectVC.swift in Sources */,
6F673C042837F26400B7E0D3 /* MyCell.swift in Sources */,
F2A0A45128C8DCD80027E18C /* SignUpDataModel.swift in Sources */,
BD339A3027493D6500021E91 /* Reusable.swift in Sources */,
6F257EEC2749A3E00055EE43 /* GetToDoService.swift in Sources */,
BD45C41F2749482800229D35 /* ResultVC.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BD3399FE27493ABF00021E91"
BuildableName = "MEEW-Client.app"
BlueprintName = "MEEW-Client"
ReferencedContainer = "container:MEEW-Client.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BD3399FE27493ABF00021E91"
BuildableName = "MEEW-Client.app"
BlueprintName = "MEEW-Client"
ReferencedContainer = "container:MEEW-Client.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BD3399FE27493ABF00021E91"
BuildableName = "MEEW-Client.app"
BlueprintName = "MEEW-Client"
ReferencedContainer = "container:MEEW-Client.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion MEEW-Client/MEEW-Client/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>SelectVC</string>
<string>NicknameVC</string>
</dict>
</array>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import Foundation

enum APIConstants {
// Base url
static let baseURL = "https://asia-northeast3-sopt-hackathon.cloudfunctions.net/api"
static let baseURL = "https://asia-northeast3-meew-server.cloudfunctions.net/api"

static let todoURL = baseURL + "/user/1"

//MARK: - SelectURL
static let readCharacterURL = baseURL + "/personality/list"
static let readCharacterURL = baseURL + "/personality"

//MARK: - SignUpURL
static let signUpURL = baseURL + "/auth/signup"


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
//

import Foundation
import Metal

// MARK: - CharacterData
struct CharacterRequestData: Codable {
let status: Int
let success: Bool
let message: String
let data: [CharacterRequestResultData]?
let data: PersonalityData?
}
struct PersonalityData : Codable {
let personalities: [CharacterRequestResultData]?
}

// MARK: - CharacterResultData
struct CharacterRequestResultData: Codable {
let id: Int
let name, description, imageUrl: String
let name, description, createdAt, updatedAt, mainImg: String
let imgUrl : [String]

enum CodingKeys: String, CodingKey {
case id, name, description
case imageUrl
}
}

24 changes: 24 additions & 0 deletions MEEW-Client/MEEW-Client/Networks/APIModels/SignUpDataModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SignUpDataModel.swift
// MEEW-Client
//
// Created by 안현주 on 2022/09/07.
//

import Foundation

// MARK: - SignUpData
struct SignUpData: Codable {
let status: Int
let success: Bool
let message: String
let data: UserData?
}
struct UserData: Codable {
let userId: Int
let token: Token?
}
struct Token: Codable {
let accessToken: String
let refreshToken: String
}
78 changes: 78 additions & 0 deletions MEEW-Client/MEEW-Client/Networks/APIServices/SignUpService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// SignUpService.swift
// MEEW-Client
//
// Created by 안현주 on 2022/09/07.
//


import Foundation
import Alamofire

class SignUpService {

static let shared = SignUpService()

func signUp(socialToken: String, socialType: String, nickname: String, personalityId: Int, completion: @escaping (NetworkResult<Any>) -> (Void)){

let url = APIConstants.signUpURL

let header: HTTPHeaders = [
"Content-Type" : "application/json"
]

let body: Parameters = [
"socialToken": socialToken,
"socialType": socialType,
"nickname": nickname,
"personalityId": personalityId
]

let dataRequest = AF.request(url,
method: .post,
parameters: body,
encoding: JSONEncoding.default,
headers: header)

dataRequest.responseData {dataResponse in
switch dataResponse.result {
case .success:
guard let statusCode = dataResponse.response?.statusCode else {return}
guard let value = dataResponse.value else {return}
let networkResult = self.judgeLoginStatus(by: statusCode, value)
completion(networkResult)

case .failure(let err):
completion(.networkFail)
}
}

}

private func judgeLoginStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
switch statusCode {
case 200: return isValidData(data: data)
case 400: return isUsedPathErrData(data: data)
case 500: return .serverErr
default: return .networkFail
}
}


private func isValidData(data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(CharacterRequestData.self, from: data)
else {
return .pathErr}
return .success(decodedData)
}


private func isUsedPathErrData(data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(CharacterRequestData.self, from: data)
else {return .pathErr}
return .requestErr(decodedData)
}

}
14 changes: 7 additions & 7 deletions MEEW-Client/MEEW-Client/Networks/GetToDoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Alamofire

struct GetToDoService {
static let shared = GetToDoService()

func getToDoInfo(completion: @escaping (NetworkResult<Any>) -> Void) {

//통신할 API주소
let URL = APIConstants.todoURL

//요청헤더
let header: HTTPHeaders = ["Content-Type" : "application/json"]

//요청서
let dataRequest = AF.request(URL,
method: .get,
Expand All @@ -36,7 +36,7 @@ struct GetToDoService {
}
}
}

//받은 statusCode를 바탕으로 어떻게 결과값을 처리할 건지 정의
private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
switch statusCode {
Expand All @@ -46,13 +46,13 @@ struct GetToDoService {
default: return .networkFail
}
}

private func isValidData(data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(DataModel.self, from: data) else { return .pathErr}
//성공적으로 decode를 마치면 success에다가 data 부분을 담아서 completion 호출
return .success(decodedData.data)

}

}
Loading