-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #327 콕찌르기 메인 - API 연결
- Loading branch information
Showing
30 changed files
with
561 additions
and
93 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
SOPT-iOS/Projects/Data/Sources/Repository/PokeMainRepository.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,43 @@ | ||
// | ||
// PokeMainRepository.swift | ||
// Data | ||
// | ||
// Created by sejin on 12/19/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Core | ||
import Domain | ||
import Networks | ||
|
||
public class PokeMainRepository { | ||
|
||
private let pokeService: PokeService | ||
private let cancelBag = CancelBag() | ||
|
||
public init(service: PokeService) { | ||
self.pokeService = service | ||
} | ||
} | ||
|
||
extension PokeMainRepository: PokeMainRepositoryInterface { | ||
public func getWhoPokeToMe() -> AnyPublisher<Domain.PokeUserModel?, Error> { | ||
pokeService.getWhoPokedToMe() | ||
.map { $0?.toDomain() } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
public func getFriend() -> AnyPublisher<[PokeUserModel], Error> { | ||
pokeService.getFriend() | ||
.map { $0.map { $0.toDomain() } } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
public func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error> { | ||
pokeService.getFriendRandomUser() | ||
.map { $0.map { $0.toDomain() } } | ||
.eraseToAnyPublisher() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
SOPT-iOS/Projects/Data/Sources/Transform/PokeFriendRandomUserTransform.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,21 @@ | ||
// | ||
// PokeFriendRandomUserTransform.swift | ||
// Data | ||
// | ||
// Created by sejin on 12/20/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
import Networks | ||
|
||
extension PokeFriendRandomUserEntity { | ||
public func toDomain() -> PokeFriendRandomUserModel { | ||
return PokeFriendRandomUserModel(friendId: friendId, | ||
friendName: friendName, | ||
friendProfileImage: friendProfileImage, | ||
friendList: friendList.map { $0.toDomain() }) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
SOPT-iOS/Projects/Data/Sources/Transform/PokeUserTransform.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,29 @@ | ||
// | ||
// PokeUserTransform.swift | ||
// Data | ||
// | ||
// Created by sejin on 12/19/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
import Networks | ||
|
||
extension PokeUserEntity { | ||
public func toDomain() -> PokeUserModel { | ||
return PokeUserModel(userId: userId, | ||
playgroundId: playgroundId, | ||
profileImage: profileImage, | ||
name: name, | ||
generation: generation, | ||
part: part, | ||
pokeNum: pokeNum, | ||
message: message, | ||
relationName: relationName, | ||
mutual: mutual, | ||
isFirstMeet: isFirstMeet, | ||
isAlreadyPoke: isAlreadyPoke) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
SOPT-iOS/Projects/Domain/Sources/Model/PokeFriendRandomUserModel.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,22 @@ | ||
// | ||
// PokeFriendRandomUserModel.swift | ||
// Domain | ||
// | ||
// Created by sejin on 12/20/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct PokeFriendRandomUserModel { | ||
public let friendId: Int | ||
public let friendName, friendProfileImage: String | ||
public let friendList: [PokeUserModel] | ||
|
||
public init(friendId: Int, friendName: String, friendProfileImage: String, friendList: [PokeUserModel]) { | ||
self.friendId = friendId | ||
self.friendName = friendName | ||
self.friendProfileImage = friendProfileImage | ||
self.friendList = friendList | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
SOPT-iOS/Projects/Domain/Sources/Model/PokeUserModel.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,38 @@ | ||
// | ||
// PokeUserModel.swift | ||
// Domain | ||
// | ||
// Created by sejin on 12/19/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Empty | ||
public struct PokeUserModel: Codable { | ||
public let userId: Int | ||
public let playgroundId: Int | ||
public let profileImage, name: String | ||
public let generation: Int | ||
public let part: String | ||
public let pokeNum: Int | ||
public let message: String | ||
public let relationName: String | ||
public let mutual: [String] | ||
public let isFirstMeet, isAlreadyPoke: Bool | ||
|
||
public init(userId: Int, playgroundId: Int, profileImage: String, name: String, generation: Int, part: String, pokeNum: Int, message: String, relationName: String, mutual: [String], isFirstMeet: Bool, isAlreadyPoke: Bool) { | ||
self.userId = userId | ||
self.playgroundId = playgroundId | ||
self.profileImage = profileImage | ||
self.name = name | ||
self.generation = generation | ||
self.part = part | ||
self.pokeNum = pokeNum | ||
self.message = message | ||
self.relationName = relationName | ||
self.mutual = mutual | ||
self.isFirstMeet = isFirstMeet | ||
self.isAlreadyPoke = isAlreadyPoke | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/PokeMainRepositoryInterface.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,15 @@ | ||
// | ||
// PokeMainRepositoryInterface.swift | ||
// Domain | ||
// | ||
// Created by sejin on 12/19/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
public protocol PokeMainRepositoryInterface { | ||
func getWhoPokeToMe() -> AnyPublisher<PokeUserModel?, Error> | ||
func getFriend() -> AnyPublisher<[PokeUserModel], Error> | ||
func getFriendRandomUser() -> AnyPublisher<[PokeFriendRandomUserModel], Error> | ||
} |
67 changes: 67 additions & 0 deletions
67
SOPT-iOS/Projects/Domain/Sources/UseCase/PokeMainUseCase.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,67 @@ | ||
// | ||
// PokeMainUseCase.swift | ||
// Domain | ||
// | ||
// Created by sejin on 12/19/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Combine | ||
|
||
import Core | ||
|
||
public protocol PokeMainUseCase { | ||
var pokedToMeUser: PassthroughSubject<PokeUserModel?, Never> { get } | ||
var myFriend: PassthroughSubject<[PokeUserModel], Never> { get } | ||
var friendRandomUsers: PassthroughSubject<[PokeFriendRandomUserModel], Never> { get } | ||
|
||
func getWhoPokedToMe() | ||
func getFriend() | ||
func getFriendRandomUser() | ||
} | ||
|
||
public class DefaultPokeMainUseCase { | ||
public let repository: PokeMainRepositoryInterface | ||
public let cancelBag = CancelBag() | ||
|
||
public let pokedToMeUser = PassthroughSubject<PokeUserModel?, Never>() | ||
public let myFriend = PassthroughSubject<[PokeUserModel], Never>() | ||
public let friendRandomUsers = PassthroughSubject<[PokeFriendRandomUserModel], Never>() | ||
|
||
|
||
public init(repository: PokeMainRepositoryInterface) { | ||
self.repository = repository | ||
} | ||
} | ||
|
||
extension DefaultPokeMainUseCase: PokeMainUseCase { | ||
public func getWhoPokedToMe() { | ||
repository.getWhoPokeToMe() | ||
.catch { _ in | ||
Just<PokeUserModel?>(nil) | ||
} | ||
.sink { event in | ||
print("GetPokedToMe State: \(event)") | ||
} receiveValue: { [weak self] pokeUser in | ||
self?.pokedToMeUser.send(pokeUser) | ||
}.store(in: cancelBag) | ||
} | ||
|
||
public func getFriend() { | ||
repository.getFriend() | ||
.sink { event in | ||
print("GetFriend State: \(event)") | ||
} receiveValue: { [weak self] friend in | ||
self?.myFriend.send(friend) | ||
}.store(in: cancelBag) | ||
} | ||
|
||
public func getFriendRandomUser() { | ||
repository.getFriendRandomUser() | ||
.sink { event in | ||
print("GetFriendRandomUser State: \(event)") | ||
} receiveValue: { [weak self] randomUsers in | ||
self?.friendRandomUsers.send(randomUsers) | ||
}.store(in: cancelBag) | ||
} | ||
} |
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
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
Oops, something went wrong.