Skip to content

Commit

Permalink
Merge pull request #82 from manito-project/Feat/#76
Browse files Browse the repository at this point in the history
[Feat/#76] 미션하기 추가 로직 구현
  • Loading branch information
HELLOHIDI authored Nov 2, 2024
2 parents d77fbf7 + 8b811a6 commit a2df4c7
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 31 deletions.
4 changes: 4 additions & 0 deletions SantaManito-iOS/SantaManito-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
87E514372CBF88A700FFF2E1 /* EditNicknameReqeust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E514362CBF88A700FFF2E1 /* EditNicknameReqeust.swift */; };
87E514392CBF930B00FFF2E1 /* WindowRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E514382CBF930B00FFF2E1 /* WindowRouter.swift */; };
87E5143C2CBFABF000FFF2E1 /* WindowDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E5143B2CBFABF000FFF2E1 /* WindowDestination.swift */; };
D2267D1C2CC539E80049C8A8 /* MatchedUserResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2267D1B2CC539E80049C8A8 /* MatchedUserResponse.swift */; };
D229FE782CA7CEA200979421 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = D229FE772CA7CEA200979421 /* HTTPMethod.swift */; };
D229FE7E2CA7D0F700979421 /* URLRequestTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D229FE7D2CA7D0F700979421 /* URLRequestTargetType.swift */; };
D229FE802CA7D17600979421 /* ParameterEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D229FE7F2CA7D17600979421 /* ParameterEncoding.swift */; };
Expand Down Expand Up @@ -215,6 +216,7 @@
87E514362CBF88A700FFF2E1 /* EditNicknameReqeust.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditNicknameReqeust.swift; sourceTree = "<group>"; };
87E514382CBF930B00FFF2E1 /* WindowRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowRouter.swift; sourceTree = "<group>"; };
87E5143B2CBFABF000FFF2E1 /* WindowDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowDestination.swift; sourceTree = "<group>"; };
D2267D1B2CC539E80049C8A8 /* MatchedUserResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchedUserResponse.swift; sourceTree = "<group>"; };
D229FE772CA7CEA200979421 /* HTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = "<group>"; };
D229FE7D2CA7D0F700979421 /* URLRequestTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLRequestTargetType.swift; sourceTree = "<group>"; };
D229FE7F2CA7D17600979421 /* ParameterEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParameterEncoding.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -467,6 +469,7 @@
874017A52CA1ABBE0096E847 /* UserResponse.swift */,
871D873C2CB8F0560050858A /* MemberResponse.swift */,
87E514362CBF88A700FFF2E1 /* EditNicknameReqeust.swift */,
D2267D1B2CC539E80049C8A8 /* MatchedUserResponse.swift */,
);
path = User;
sourceTree = "<group>";
Expand Down Expand Up @@ -1061,6 +1064,7 @@
D2BC1AA32C90A29200CB32B8 /* CheckRoomInfoViewModel.swift in Sources */,
87873BE12CAFF29600E368BF /* AppService.swift in Sources */,
D28568AE2CAD033C0044C231 /* ErrorHandler.swift in Sources */,
D2267D1C2CC539E80049C8A8 /* MatchedUserResponse.swift in Sources */,
87873BFE2CB2EE8900E368BF /* AuthAPI.swift in Sources */,
877EA23D2C88AB8D0073FFBD /* UserService.swift in Sources */,
874017CB2CA7E6970096E847 /* SMPasteBoard.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ struct RoomStateFactory {
guard dto.matchingDate != nil else { return .notStarted }
return .inProgress
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MatchedUserResponse.swift
// SantaManito-iOS
//
// Created by 류희재 on 10/20/24.
//

import Foundation

struct MatchedUserResult: Decodable {
let manitto: UserResponse
let mission: MissionResponse
}

extension MatchedUserResult {
func toEntity() -> (User, Mission) {
return (manitto.toEntity(), mission.toEntity())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

struct MemberResponse: Decodable {
let santa: UserResponse
let santa: SantaUserResponse
let manitto: UserResponse?
}

Expand Down
13 changes: 13 additions & 0 deletions SantaManito-iOS/SantaManito-iOS/Data/DTO/User/UserResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ struct UserResponse: Decodable {
let username: String
}

struct SantaUserResponse: Decodable {
let id: String
let username: String
let missionId: String
}

extension UserResponse {
func toEntity() -> User {
.init(id: id, username: username)
}
}

extension SantaUserResponse {
func toEntity() -> SantaUser {
.init(id: id, username: username, missionId: missionId)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

struct Member: Hashable {
var santa: User
var santa: SantaUser
var manitto: User?
}

Expand Down
23 changes: 20 additions & 3 deletions SantaManito-iOS/SantaManito-iOS/Data/Entity/Room/Mission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ import Foundation

public struct Mission: Identifiable, Hashable, Decodable {
var content: String
public var id = UUID() // TODO: 추후 서버로 부터 DTO어떻게 올지에 따라 달라짐
// public var id = UUID() // TODO: 추후 서버로 부터 DTO어떻게 올지에 따라 달라짐
public var id = String()
}

extension Mission {
static var stub: Mission {
.init(content: "손 잡기", id: UUID())
static var stub1: Mission {
// .init(content: "손 잡기", id: UUID())
.init(content: "손 잡기", id: "1")
}

static var stub2: Mission {
// .init(content: "손 잡기", id: UUID())
.init(content: "손 잡기", id: "2")
}

static var stub3: Mission {
// .init(content: "손 잡기", id: UUID())
.init(content: "손 잡기", id: "3")
}

static var stub4: Mission {
// .init(content: "손 잡기", id: UUID())
.init(content: "손 잡기", id: "4")
}

static func dummy() -> [Mission] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ extension RoomDetail {
creatorID: User.stub1.id,
creatorName: User.stub1.username,
members: .stub1,
mission: [],
mission: [
.stub1,
.stub2,
.stub3,
.stub4
],
createdAt: Date(),
expirationDate: Date()
)
Expand Down
25 changes: 25 additions & 0 deletions SantaManito-iOS/SantaManito-iOS/Data/Entity/User/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ struct User: Hashable {
let username: String
}

struct SantaUser: Hashable {
let id: String
let username: String
let missionId: String
}


extension User {
static var stub1: User {
Expand All @@ -30,3 +36,22 @@ extension User {
return .init(id: "userID4", username: "이한나")
}
}

extension SantaUser {
static var stub1: SantaUser {
return .init(id: "userID1", username: "류희재", missionId: "1")
}

static var stub2: SantaUser {
return .init(id: "userID2", username: "장석우" , missionId: "2")
}

static var stub3: SantaUser {
return .init(id: "userID3", username: "박상수", missionId: "3")
}

static var stub4: SantaUser {
return .init(id: "userID4", username: "이한나", missionId: "4")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ protocol RoomServiceType {
// For Guset
func enterRoom(at: String) -> AnyPublisher<String, SMNetworkError>
func exitRoom(with roomID: String) -> AnyPublisher<Void, SMNetworkError>
// func getMyInfo(roomID: String) -> AnyPublisher<Void, SMNetworkError>
func getMyInfo(with roomID: String) -> AnyPublisher<(User, Mission) , SMNetworkError>
}

extension RoomService: RoomServiceType {
// For All
func getEnteredRooms() -> AnyPublisher<[RoomDetail], SMNetworkError> {
requestWithResult(.getEnteredAllRoom, [RoomDetailResponse].self)
.map {
Expand All @@ -50,6 +51,7 @@ extension RoomService: RoomServiceType {
requestWithNoResult(.deleteHistoryRoom(roomID: roomID))
}

// For Host
func createRoom(request: CreateRoomRequest) -> AnyPublisher<String, SMNetworkError> {
requestWithResult(.createRoom(request: request), CreateRoomResult.self)
.map { $0.invitationCode }
Expand All @@ -68,6 +70,7 @@ extension RoomService: RoomServiceType {
requestWithNoResult(.deleteRoom(roomID: roomID))
}

// For Guset
func enterRoom(at invitationCode: String) -> AnyPublisher<String, SMNetworkError> {
requestWithResult(.enterRoom(request: .init(invitationCode: invitationCode)), EnterRoomResult.self)
.map { $0.roomId }
Expand All @@ -78,11 +81,15 @@ extension RoomService: RoomServiceType {
requestWithNoResult(.exitRoom(roomID: roomID))
}


func getMyInfo(with roomID: String) -> AnyPublisher<(User, Mission), SMNetworkError> {
requestWithResult(.getMyInfo(roomID: roomID), MatchedUserResult.self)
.map { $0.toEntity() }
.eraseToAnyPublisher()
}
}

struct StubRoomService: RoomServiceType {

// For All
func getEnteredRooms() -> AnyPublisher<[RoomDetail], SMNetworkError> {
Just([.stub1, .stub2, .stub3, .stub4, .stub5]).setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}
Expand All @@ -95,6 +102,7 @@ struct StubRoomService: RoomServiceType {
Just(()).setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}

// For Host
func createRoom(request: CreateRoomRequest) -> AnyPublisher<String, SMNetworkError> {
Just("초대코드1").setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}
Expand All @@ -111,6 +119,7 @@ struct StubRoomService: RoomServiceType {
Just(()).setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}

// For Guset
func enterRoom(at invitationCode: String) -> AnyPublisher<String, SMNetworkError> {
Just("roomID1").setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}
Expand All @@ -119,5 +128,7 @@ struct StubRoomService: RoomServiceType {
Just(()).setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}


func getMyInfo(with roomID: String) -> AnyPublisher<(User, Mission), SMNetworkError> {
Just((.stub1, .stub1)).setFailureType(to: SMNetworkError.self).eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fileprivate struct ParticipateListView: View {
}

fileprivate struct ParticipateCellView: View {
var user: User
var user: SantaUser
var body: some View {
HStack {
Image(.graphicsRudolphCircle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class CheckRoomInfoViewModel: ObservableObject {
UIPasteboard.general.string = inviteCode
state.isPresented = false
navigationRounter.popToRootView()

break
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EditMissionViewModel: ObservableObject {

case .ignoreMissionButtonDidTap, .makeMissionButtonDidTap:
state.isPresented = false
navigationRouter.push(to: .roomInfo(roomInfo: roomInfo, missionList: missionList)) //TODO: string.empty인 미션도 같이 넘어가는 오류 해결해야함.
navigationRouter.push(to: .roomInfo(roomInfo: roomInfo, missionList: []))

case .dismissAlert:
state.isPresented = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fileprivate struct FinishResultView: View {
.lineSpacing(2)

Spacer()
.frame(height: 30)
.frame(height: 16)

HStack {
Spacer()
Expand Down Expand Up @@ -167,6 +167,7 @@ fileprivate struct FinishResultView: View {
.frame(width: 54, height: 73)
}
}
.padding(.horizontal, 16)
.background(.smWhite)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class FinishViewModel: ObservableObject {
}

var mission: String {
return "미션" // TODO: 미션 고르는 로직 구현해야함.
let missionId = member.santa.missionId
guard let mission = roomInfo.mission.first(where: {$0.id == missionId}) else {
return "미션이 없습니다."
}
return mission.content
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class MatchingResultViewModel: ObservableObject {
return roomInfo.members[내가마니또인멤버Index]
}

var me: User {
var me: SantaUser {
member.santa
}
var mannito: User {
member.manitto ?? .stub1
}

var mission: String {
roomInfo.mission.first?.content ?? "" //TODO: 내 미션 찾는 로직 필요
}
var isAnimating: Bool = false

fileprivate var matchedInfo: (User, Mission) = (.stub1, .stub1)

var mannito: User { matchedInfo.0 }
var mission: String { matchedInfo.1.content }
}

//MARK: Dependency
Expand Down Expand Up @@ -73,9 +73,17 @@ class MatchingResultViewModel: ObservableObject {
//MARK: Methods

func send(action: Action) {
weak var owner = self
guard let owner else { return }

switch action {
case .onAppear:
return
Just(roomDetail.id)
.flatMap(roomService.getMyInfo)
.assignLoading(to: \.state.isAnimating, on: owner)
.catch { _ in Empty() }
.assign(to: \.state.matchedInfo, on: owner)
.store(in: cancelBag)

case .goHomeButtonDidTap:
navigationRouter.popToRootView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MatchingViewModel: ObservableObject {
case .onAppear:
Just(roomID)
.flatMap(roomService.matchRoom)
.map { owner.roomID}
.map { owner.roomID }
.flatMap(roomService.getRoomInfo)
.receive(on: RunLoop.main)
.assignLoading(to: \.state.isAnimating, on: owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
case .invalidRequest(let requestError):
return "요청 시 발생된 " + requestError.description
case .invalidResponse(let responseError):
return "응답 시 발생된 " + responseError.description
return responseError.description
case .decodingFailed(let decodeError):
return decodeError.description
case .unknown(let error):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
////
//// RoomStateFactoryTests.swift
//// SantaManitoUnitTests
////
//// Created by 장석우 on 10/14/24.
////
//
// RoomStateFactoryTests.swift
// SantaManitoUnitTests
//import XCTest
//@testable import SantaManito_iOS
//
// Created by 장석우 on 10/14/24.
//final class RoomStateFactoryTests: XCTestCase {
//
// let sut = RoomStateFactory.self
//

import XCTest
Expand Down

0 comments on commit a2df4c7

Please sign in to comment.