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] 회원 탈퇴 / 닉네임 수정 / 닉네임 정보 불러오기 서버연결완료 #163

Merged
merged 17 commits into from
Jul 20, 2022
Merged
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
22 changes: 21 additions & 1 deletion HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
FD72FCC028834AB60092746F /* MainMapNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD72FCBF28834AB60092746F /* MainMapNavigationController.swift */; };
FDA3AEF82880612300D6CCB4 /* UserWithdrawalUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDA3AEF22880612300D6CCB4 /* UserWithdrawalUseCase.swift */; };
FDA54A3B287DEAB2009D5BCE /* CustomSegementControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDA54A3A287DEAB2009D5BCE /* CustomSegementControl.swift */; };
FDCB3CC12888338300E6FBCE /* NicknameEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCB3CC02888338300E6FBCE /* NicknameEntity.swift */; };
FDCB3CC328884F1700E6FBCE /* HamburgerBarNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCB3CC228884F1700E6FBCE /* HamburgerBarNavigationController.swift */; };
FDCB3CC52888565400E6FBCE /* UserEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCB3CC42888565400E6FBCE /* UserEntity.swift */; };
FDC46A25288326AC00F62D20 /* splash_iOS.json in Resources */ = {isa = PBXBuildFile; fileRef = FDC46A24288326AB00F62D20 /* splash_iOS.json */; };
FDCD5B452881ACC100EAEF51 /* LocationLiterals.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCD5B442881ACC100EAEF51 /* LocationLiterals.swift */; };
FDCD5B472882083200EAEF51 /* mapContainerViewCameraDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCD5B462882083200EAEF51 /* mapContainerViewCameraDelegateProxy.swift */; };
Expand Down Expand Up @@ -459,6 +462,9 @@
FD72FCBF28834AB60092746F /* MainMapNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMapNavigationController.swift; sourceTree = "<group>"; };
FDA3AEF22880612300D6CCB4 /* UserWithdrawalUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserWithdrawalUseCase.swift; sourceTree = "<group>"; };
FDA54A3A287DEAB2009D5BCE /* CustomSegementControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSegementControl.swift; sourceTree = "<group>"; };
FDCB3CC02888338300E6FBCE /* NicknameEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameEntity.swift; sourceTree = "<group>"; };
FDCB3CC228884F1700E6FBCE /* HamburgerBarNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HamburgerBarNavigationController.swift; sourceTree = "<group>"; };
FDCB3CC42888565400E6FBCE /* UserEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserEntity.swift; sourceTree = "<group>"; };
FDC46A24288326AB00F62D20 /* splash_iOS.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = splash_iOS.json; sourceTree = "<group>"; };
FDCD5B442881ACC100EAEF51 /* LocationLiterals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationLiterals.swift; sourceTree = "<group>"; };
FDCD5B462882083200EAEF51 /* mapContainerViewCameraDelegateProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = mapContainerViewCameraDelegateProxy.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -511,6 +517,7 @@
children = (
3B18D8AB287AB7CD009AF9E7 /* HamburgerBarVC.swift */,
3B18D8AD287AB7D8009AF9E7 /* HamburgerBar.storyboard */,
FDCB3CC228884F1700E6FBCE /* HamburgerBarNavigationController.swift */,
);
path = HamburgerBarScene;
sourceTree = "<group>";
Expand Down Expand Up @@ -820,7 +827,9 @@
A90CFDB228852C550018AB94 /* User */ = {
isa = PBXGroup;
children = (
FDCB3CBF2888336500E6FBCE /* NicknameScene */,
A90ED62D2886646600FCE149 /* ScrapScene */,
FDCB3CC42888565400E6FBCE /* UserEntity.swift */,
);
path = User;
sourceTree = "<group>";
Expand Down Expand Up @@ -1910,6 +1919,14 @@
path = Lottie;
sourceTree = "<group>";
};
FDCB3CBF2888336500E6FBCE /* NicknameScene */ = {
isa = PBXGroup;
children = (
FDCB3CC02888338300E6FBCE /* NicknameEntity.swift */,
);
path = NicknameScene;
sourceTree = "<group>";
};
FDF2E20C287F5CE80007D4F9 /* Auth */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2229,6 +2246,8 @@
3B723C912880037100822B7C /* ReviewPhotoCVC.swift in Sources */,
EBF66AE3287227F500DE0ED1 /* NetworkResult.swift in Sources */,
EB6A45262875C3A000749582 /* TabContainerCVC.swift in Sources */,
FDCB3CC12888338300E6FBCE /* NicknameEntity.swift in Sources */,
FDCB3CC52888565400E6FBCE /* UserEntity.swift in Sources */,
EBFAEB312885F2F7009C569C /* MyReviewRepository.swift in Sources */,
EBFAEB332885F2F7009C569C /* MyReviewVC.swift in Sources */,
A93252B1287F2AF9001EDF50 /* ScrapVC.swift in Sources */,
Expand Down Expand Up @@ -2260,6 +2279,7 @@
3BB0FCE3288705E200C3862C /* BlogReviewListEntity.swift in Sources */,
A93252C628808B82001EDF50 /* ReviewDeleteAlertView.swift in Sources */,
EBF66AD7287227F500DE0ED1 /* Presentable.swift in Sources */,
FDCB3CC328884F1700E6FBCE /* HamburgerBarNavigationController.swift in Sources */,
FD72FC9C288346480092746F /* UserWithdrawalViewModel.swift in Sources */,
A932527E287DD261001EDF50 /* SearchResultVC.swift in Sources */,
EBD19275287F256000EA053E /* EncodeURLKorean.swift in Sources */,
Expand Down Expand Up @@ -2481,7 +2501,7 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.healthFoodMe.release;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = HealthFoodMe_Dev;
PROVISIONING_PROFILE_SPECIFIER = healthFood_dev;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ final class URLSchemeManager: NSObject {
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
}

}

enum NaverTerms: String{
case serviceTerm = "policy.naver.com/rules/service_pre_20140317.html"
case naverMapTerm = "policy.naver.com/rules/service_location.html"
case naverMapOpensource = "policy.naver.com/rules/service_group.html"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protocol ModuleFactoryProtocol {
// MARK: - Map
func makeMainMapVC() -> MainMapVC
func makeHamburgerBarVC() -> HamburgerBarVC
func makeHamburgerBarNavigationController() -> HamburgerBarNavigationController
func makeSupplementMapVC(forSearchVC: Bool) -> SupplementMapVC
func makeMyReviewVC() -> MyReviewVC

Expand Down Expand Up @@ -96,6 +97,11 @@ class ModuleFactory: ModuleFactoryProtocol {

return vc
}
func makeHamburgerBarNavigationController() -> HamburgerBarNavigationController {
let nc = HamburgerBarNavigationController.controllerFromStoryboard(.hamburgerBar)
return nc
}


func makeHamburgerBarVC() -> HamburgerBarVC {
let vc = HamburgerBarVC.controllerFromStoryboard(.hamburgerBar)
Expand Down Expand Up @@ -178,8 +184,9 @@ class ModuleFactory: ModuleFactoryProtocol {
}

// MARK: - HelfmeAlert
func makeHelfmeAlertVC() -> HelfmeAlertVC {
func makeHelfmeAlertVC(type: AlertType) -> HelfmeAlertVC {
let vc = HelfmeAlertVC.controllerFromStoryboard(.helfmeAlert)
vc.alertType = type

return vc
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// NicknameEntity.swift
// HealthFoodMe
//
// Created by 송지훈 on 2022/07/20.
//

import Foundation

struct NicknameEntity: Codable {
let _id, name: String
}
13 changes: 13 additions & 0 deletions HealthFoodMe/HealthFoodMe/Data/Entity/User/UserEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UserDataEntity.swift
// HealthFoodMe
//
// Created by 송지훈 on 2022/07/21.
//

import Foundation

struct UserEntity: Codable {
let _id, name: String
let scrapRestaurants: [ScrapListEntity]
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class BaseService {
}
}

func judgeStatusWithEmptyReponse(by statusCode: Int?) -> NetworkResult<Any> {
guard let statusCode = statusCode else { return .pathErr }
switch statusCode {
case 200..<300: return .success(())
case 400..<500: return .requestErr(())
case 500: return .serverErr
default: return .networkFail
}
}

func requestObject<T: Codable>(_ target: BaseRouter, type: T.Type, decodingMode: DecodingMode, completion: @escaping (NetworkResult<Any>) -> Void) {
AFManager.request(target).responseData { response in
switch response.result {
Expand All @@ -84,4 +94,11 @@ class BaseService {
}
}
}

func requestObjectWithEmptyResponse(_ target: BaseRouter,completion: @escaping (NetworkResult<Any>) -> Void) {
AFManager.request(target).responseData { response in
completion(self.judgeStatusWithEmptyReponse(by: response.response?.statusCode))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ enum HTTPHeaderField: String {
enum HeaderContent: String {
case json = "application/json"
case multiPart = "multipart/form-data"
case tokenSerial = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZDRlODRmMGZmMmY5MDBlYTg4YmVjMyIsImlhdCI6MTY1ODMxMDc2MSwiZXhwIjoxNjU4NTY5OTYxfQ.OqkVjvD5pLEQ9keqFvOu0JIDjItrVuzLoGzo9o7Y2Bc"
case tokenSerial = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZDRlODRmMGZmMmY5MDBlYTg4YmVjMyIsImlhdCI6MTY1ODMyNTUwOCwiZXhwIjoxNjU4NTg0NzA4fQ.ND6-ZIthGE4LRjYtZnWyqc0pJluiUYO_Vb_9gkmETLw"
}

32 changes: 30 additions & 2 deletions HealthFoodMe/HealthFoodMe/Data/Network/Routers/UserRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ import Alamofire
enum UserRouter {
case getScrapList(userId: String)
case putScrap(userId: String, restaurantId: String)
case putUserNickname(userId: String, nickname: String)
case deleteUser(userId: String)
case getUserName(userId: String)
}

extension UserRouter: BaseRouter {
var method: HTTPMethod {
switch self {
switch self {
case .getScrapList:
return .get
case .putScrap:
case .putScrap, .putUserNickname:
return .put
case .deleteUser:
return .delete
case .getUserName:
return .get
}
}

Expand All @@ -28,6 +35,12 @@ extension UserRouter: BaseRouter {
return "/user/\(userId)/scrapList"
case .putScrap(let userId, let restaurantId):
return "/user/\(userId)/scrap/\(restaurantId)"
case .putUserNickname(let userID,_):
return "/user/\(userID)/profile"
case .deleteUser(let userID):
return "/auth/withdrawal/\(userID)"
case .getUserName(let userID):
return "/user/\(userID)/profile"
}
}

Expand All @@ -37,6 +50,15 @@ extension UserRouter: BaseRouter {
return .requestPlain
case .putScrap:
return .requestPlain
case .deleteUser:
return .requestPlain
case .putUserNickname(_,let nickname):
let body: [String: Any] = [
"name": nickname
]
return .requestBody(body)
case .getUserName(_):
return .requestPlain
}
}

Expand All @@ -46,6 +68,12 @@ extension UserRouter: BaseRouter {
return .withToken
case .putScrap:
return .withToken
case .deleteUser:
return .withToken
case .putUserNickname:
return .withToken
case .getUserName:
return .withToken
}
}
}
15 changes: 15 additions & 0 deletions HealthFoodMe/HealthFoodMe/Data/Network/Services/UserService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ extension UserService {
func putScrap(userId: String, restaurantId: String, completion: @escaping(NetworkResult<Any>) -> Void) {
requestObject(UserRouter.putScrap(userId: userId, restaurantId: restaurantId), type: ScrapEntity.self, decodingMode: .message, completion: completion)
}

func putUserNickname(userId: String,nickname: String, completion: @escaping(NetworkResult<Any>) -> Void) {
requestObject(UserRouter.putUserNickname(userId: userId,
nickname: nickname),
type: NicknameEntity.self, decodingMode: .model, completion: completion)
}

func deleteUserNickname(userId: String, completion: @escaping(NetworkResult<Any>) -> Void){
requestObjectWithEmptyResponse(UserRouter.deleteUser(userId: userId), completion: completion)
}

func getUserNickname(userId: String, completion: @escaping(NetworkResult<Any>) -> Void){
requestObject(UserRouter.getUserName(userId: userId),
type: UserEntity.self, decodingMode: .model, completion: completion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,45 @@
import RxSwift

protocol NicknameRepository {
func postNicknameInValidCheck(nickname: String) -> Observable<Bool?>
func getUserNickname() -> Observable<String?>
func putNicknameChange(nickname: String)
func getUserNickname()

var userNicknameChange: PublishSubject<NicknameChangeStatus> { get set }
var userNickname: PublishSubject<String> { get set }
}

// FIXME: - 실제 네트워크 나오면 바로 Service 프로토콜 주입 및 파일 붙일 예정
final class DefaultNicknameRepository {

// private let networkService: AuthServiceType
private let disposeBag = DisposeBag()

// init(service: AuthServiceType) {
// self.networkService = service
// }
var userNicknameChange = PublishSubject<NicknameChangeStatus>()
var userNickname = PublishSubject<String>()
private let networkService = UserService.shared
private let disposeBag = DisposeBag()
}

extension DefaultNicknameRepository: NicknameRepository {
func postNicknameInValidCheck(nickname: String) -> Observable<Bool?> {
// return self.networkService.checkNicknameDuplicated(nickname: nickname)
// 이후 실제로 쓸 코드 잠시 주석처리 해둠 (서버 되면 붙일 예정)

// 닉네임 중복 검사를 잠시 임시로 처리해둠
return .create { observer in
if nickname == "중복된닉네임" || nickname == "중복" {
observer.onNext(true)
}else {
observer.onNext(false)
func putNicknameChange(nickname: String) {
guard let userId = UserManager.shared.getUser?.id else { return }
networkService.putUserNickname(userId: userId,
nickname: nickname) { result in
switch(result)
{
case .success(_): self.userNicknameChange.onNext(.normal)
case .requestErr(_): self.userNicknameChange.onNext(.duplicated)
default : self.userNicknameChange.onNext(.networkFail)
}
}
return Disposables.create()
}
}

func getUserNickname() -> Observable<String?> {
return .create { observer in
observer.onNext("혜화동불가마")
return Disposables.create()
}

func getUserNickname() {
guard let userID = UserManager.shared.getUser?.id else { return }
UserService.shared.getUserNickname(userId: userID) { result in
switch(result) {
case .success(let result):
guard let result = result as? UserEntity else { return }
self.userNickname.onNext(result.name)
default: break
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ import RxRelay

protocol NicknameChangeUseCase {
func checkNicknameHasCharacter(nickname: String)
func checkNicknameDuplicated(nickname: String)

var nicknameDuplicated: PublishSubject<Bool> { get set }
var nicknameHasCharacter: PublishSubject<Bool> { get set }
var nicknameChangeState: PublishSubject<NicknameChangeStatus> { get set }
}

final class DefaultNicknameChangeUseCase {

private let repository: NicknameRepository
private let disposeBag = DisposeBag()

var nicknameDuplicated = PublishSubject<Bool>()
var nicknameHasCharacter = PublishSubject<Bool>()
var nicknameChangeState = PublishSubject<NicknameChangeStatus>()

init(repository: NicknameRepository) {
self.repository = repository
Expand All @@ -31,18 +30,20 @@ final class DefaultNicknameChangeUseCase {

extension DefaultNicknameChangeUseCase: NicknameChangeUseCase {
func checkNicknameHasCharacter(nickname: String) {
self.nicknameHasCharacter.onNext(hasCharacter(nickname))
if hasCharacter(nickname) {
self.nicknameHasCharacter.onNext(true)
} else {
putNicknameChange(nickname: nickname)
}
}

func checkNicknameDuplicated(nickname: String) {
repository.postNicknameInValidCheck(nickname: nickname)
.filter { $0 != nil }
private func putNicknameChange(nickname: String) {
repository.putNicknameChange(nickname: nickname)

.subscribe(onNext: { [weak self] duplicated in
guard let self = self else { return }
self.nicknameDuplicated.onNext(duplicated!)
repository.userNicknameChange.subscribe(onNext: { [weak self] changeState in
guard let self = self else { return }
self.nicknameChangeState.onNext(changeState)
}).disposed(by: self.disposeBag)

}

private func hasCharacter(_ nickname: String) -> Bool {
Expand Down
Loading