-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat #164: checkUsername 관련 Repository, UseCase 생성
- Loading branch information
1 parent
997c937
commit f050a52
Showing
9 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// UserRepository.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/09/01. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import Combine | ||
import CombineMoya | ||
|
||
final class UserRepository { | ||
private let api: TTProvider<UserAPI> | ||
|
||
init(api: TTProvider<UserAPI>) { | ||
self.api = api | ||
} | ||
|
||
func checkUsername(request: CheckUsernameRequest) -> AnyPublisher<CheckUsernameInfo, NetworkError> { | ||
return self.api.request(.checkUsername(request: request)) | ||
.map(CheckUsernameResponse.self) | ||
.map { $0.toDomain() } | ||
.catchDecodeError() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// CheckUsernameResponse.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/09/01. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CheckUsernameResponse: Decodable { | ||
let code: String | ||
let message: String | ||
let isPresent: Bool | ||
} | ||
|
||
extension CheckUsernameResponse { | ||
func toDomain() -> CheckUsernameInfo { | ||
return .init( | ||
detailInfo: .init(code: self.code, message: self.message), | ||
isNotExist: !self.isPresent | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CheckUsernameInfo.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/09/01. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CheckUsernameInfo { | ||
let detailInfo: TTResponseDetailInfo | ||
let isNotExist: Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TTResponseDetailInfo.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/09/01. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct TTResponseDetailInfo { | ||
let code: String? | ||
let message: String? | ||
} |
24 changes: 24 additions & 0 deletions
24
Project_Timer/Domain/UseCase/User/GetUsernameNotExistUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// GetUsernameNotExistUseCase.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/09/01. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
final class GetUsernameNotExistUseCase { | ||
private let repository: UserRepository // TODO: 프로토콜로 수정 | ||
|
||
init(repository: UserRepository) { | ||
self.repository = repository | ||
} | ||
|
||
func execute(username: String) -> AnyPublisher<CheckUsernameInfo, NetworkError> { | ||
return self.repository.checkUsername( | ||
request: .init(username: username) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters