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

[TNT-231] 트레이너-트레이니 연결 API, 화면 흐름 연결 완료 #72

Merged
merged 7 commits into from
Feb 10, 2025
12 changes: 12 additions & 0 deletions TnT/Projects/DIContainer/Sources/DIContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ private enum TraineeUseCaseKey: DependencyKey {
)
}

private enum TraineeRepoUseCaseKey: DependencyKey {
static let liveValue: TraineeRepository = DefaultTraineeUseCase(
trainerRepository: TrainerRepositoryImpl(),
traineeRepository: TraineeRepositoryImpl()
)
}

private enum SocialUseCaseKey: DependencyKey {
static let liveValue: SocialLoginUseCase = SocialLoginUseCase(socialLoginRepository: SocialLogInRepositoryImpl(loginManager: SNSLoginManager()))
}
Expand Down Expand Up @@ -60,6 +67,11 @@ public extension DependencyValues {
set { self[TraineeUseCaseKey.self] = newValue }
}

var traineeRepoUseCase: TraineeRepository {
get { self[TraineeRepoUseCaseKey.self] }
set { self[TraineeRepoUseCaseKey.self] = newValue }
}

var socialLogInUseCase: SocialLoginUseCase {
get { self[SocialUseCaseKey.self] }
set { self[SocialUseCaseKey.self] = newValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ public struct TraineeRepositoryImpl: TraineeRepository {

public init() {}

public func postConnectTrainer(_ info: TraineeConnectInfoEntity) async throws -> PostConnectTrainerResDTO {
let requestDTO = PostConnectTrainerReqDTO(
invitationCode: info.invitationCode,
startDate: info.startDate,
totalPtCount: info.totalPtCount,
finishedPtCount: info.finishedPtCount
)

public func postConnectTrainer(_ reqDTO: PostConnectTrainerReqDTO) async throws -> PostConnectTrainerResDTO {
return try await networkService.request(
TraineeTargetType.postConnectTrainer(reqDto: requestDTO),
TraineeTargetType.postConnectTrainer(reqDto: reqDTO),
decodingType: PostConnectTrainerResDTO.self
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct TrainerRepositoryImpl: TrainerRepository {

public func getDateSessionList(date: String) async throws -> GetDateSessionListDTO {
return try await networkService.request(
TrainerTargetType.getDateLessionList(date: date),
TrainerTargetType.getDateLessonList(date: date),
decodingType: GetDateSessionListDTO.self
)
}
Expand All @@ -52,4 +52,8 @@ public struct TrainerRepositoryImpl: TrainerRepository {
decodingType: GetMembersListDTO.self
)
}

public func getConnectedTraineeInfo(trainerId: Int, traineeId: Int) async throws -> GetConnectedTraineeInfoResponseDTO {
return try await networkService.request(TrainerTargetType.getConnectedTraineeInfo(trainerId: trainerId, traineeId: traineeId), decodingType: GetConnectedTraineeInfoResponseDTO.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public enum TrainerTargetType {
/// 트레이너 초대코드 불러오기
case getFirstInvitationCode
/// 트레이너 캘린더, 특정 날짜의 PT 리스트 불러오기
case getDateLessionList(date: String)
case getDateLessonList(date: String)
/// 트레이너 초대코드 재발급
case getReissuanceInvitationCode
/// 회원 조희
case getMemebersList
/// 연결 완료된 트레이니 최초로 정보 불러오기
case getConnectedTraineeInfo(trainerId: Int, traineeId: Int)
}

extension TrainerTargetType: TargetType {
Expand All @@ -36,12 +38,14 @@ extension TrainerTargetType: TargetType {
return "/invitation-code/verify/\(code)"
case .getFirstInvitationCode:
return "/invitation-code"
case .getDateLessionList(let date):
return "/lessions/\(date)"
case .getDateLessonList(let date):
return "/lessons/\(date)"
case .getReissuanceInvitationCode:
return "/invitation-code/reissue"
case .getMemebersList:
return "/members"
case .getConnectedTraineeInfo:
return "/first-connected-trainee"
}
}

Expand All @@ -51,12 +55,14 @@ extension TrainerTargetType: TargetType {
return .get
case .getFirstInvitationCode:
return .get
case .getDateLessionList:
case .getDateLessonList:
return .get
case .getReissuanceInvitationCode:
return .put
case .getMemebersList:
return .get
case .getConnectedTraineeInfo:
return .get
}
}

Expand All @@ -66,12 +72,17 @@ extension TrainerTargetType: TargetType {
return .requestPlain
case .getFirstInvitationCode:
return .requestPlain
case .getDateLessionList:
case .getDateLessonList:
return .requestPlain
case .getReissuanceInvitationCode:
return .requestPlain
case .getMemebersList:
return .requestPlain
case let .getConnectedTraineeInfo(trainerId, traineeId):
return .requestParameters(parameters: [
"trainerId": trainerId,
"traineeId": traineeId
], encoding: .url)
}
}

Expand All @@ -81,12 +92,14 @@ extension TrainerTargetType: TargetType {
return ["Content-Type": "application/json"]
case .getFirstInvitationCode:
return nil
case .getDateLessionList:
case .getDateLessonList:
return ["Content-Type": "application/json"]
case .getReissuanceInvitationCode:
return ["Content-Type": "application/json"]
case .getMemebersList:
return ["Content-Type": "application/json"]
case .getConnectedTraineeInfo:
return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import Foundation
/// 트레이너 연결 응답 DTO
public struct PostConnectTrainerResDTO: Decodable {
/// 트레이너 이름
let trainerName: String
public let trainerName: String
/// 트레이니 이름
let traineeName: String
public let traineeName: String
/// 트레이너 프로필 이미지 URL
let trainerProfileImageUrl: String
public let trainerProfileImageUrl: String
/// 트레이니 프로필 이미지 URL
let traineeProfileImageUrl: String
public let traineeProfileImageUrl: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// GetConnectedTraineeInfoResponseDTO.swift
// Domain
//
// Created by 박민서 on 2/11/25.
// Copyright © 2025 yapp25thTeamTnT. All rights reserved.
//

import Foundation

/// 연결 완료된 트레이니 정보 불러오기 응답 DTO
public struct GetConnectedTraineeInfoResponseDTO: Decodable {
/// 연결 트레이니 DTO
public let trainer: ConnectTrainerInfoDTO
/// 연결 트레이너 DTO
public let trainee: ConnectTraineeInfoDTO
}

public struct ConnectTrainerInfoDTO: Decodable {
/// 트레이너 이름
let trainerName: String
/// 트레이너 프로필 이미지
let trainerProfileImageUrl: String
}

public struct ConnectTraineeInfoDTO: Decodable {
/// 트레이니 이름
let traineeName: String
/// 트레이니 프로필 이미지 url
let traineeProfileImageUrl: String
/// 나이
let age: Int?
/// 키
let height: Double
/// 몸무게
let weight: Double
/// PT 목표
let ptGoal: String
/// 주의 사항
let cautionNote: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
import Foundation

public struct GetReissuanceInvitationCodeDTO: Decodable {
public let trainerId: String
public let invitationCode: String

public init(
trainerId: String,
invitationCode: String
) {
self.trainerId = trainerId
public init(invitationCode: String) {
self.invitationCode = invitationCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ import Foundation
public struct GetVerifyInvitationCodeResDTO: Decodable {
/// 초대 코드 인증 여부
public let isVerified: Bool
/// 트레이너 이름
public let trainerName: String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// ConnectedTraineeProfileEntity.swift
// Domain
//
// Created by 박민서 on 2/11/25.
// Copyright © 2025 yapp25thTeamTnT. All rights reserved.
//

import Foundation

/// 연결 완료된 트레이니의 프로필
public struct ConnectedTraineeProfileEntity: Equatable, Sendable {
/// 트레이니 이름
public let traineeName: String
/// 트레이니 프로필 이미지 url
public let imageUrl: String
/// 나이
public let age: Int?
/// 키
public let height: Double
/// 몸무게
public let weight: Double
/// PT 목표
public let ptGoal: String
/// 주의 사항
public let cautionNote: String?

public init(
traineeName: String,
imageUrl: String,
age: Int?,
height: Double,
weight: Double,
ptGoal: String,
cautionNote: String?
) {
self.traineeName = traineeName
self.imageUrl = imageUrl
self.age = age
self.height = height
self.weight = weight
self.ptGoal = ptGoal
self.cautionNote = cautionNote
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// 트레이너와 트레이니가 연결된 정보
public struct ConnectionInfoEntity {
public struct ConnectionInfoEntity: Equatable, Sendable {
/// 트레이너 이름
public let trainerName: String
/// 트레이니 이름
Expand Down
21 changes: 0 additions & 21 deletions TnT/Projects/Domain/Sources/Entity/TraineeConnectInfoEntity.swift

This file was deleted.

34 changes: 34 additions & 0 deletions TnT/Projects/Domain/Sources/Mapper/TrainerMapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// TrainerMapper.swift
// Domain
//
// Created by 박민서 on 2/11/25.
// Copyright © 2025 yapp25thTeamTnT. All rights reserved.
//

import Foundation

public extension ConnectTraineeInfoDTO {
func toEntity() -> ConnectedTraineeProfileEntity {
return .init(
traineeName: self.traineeName,
imageUrl: self.traineeProfileImageUrl,
age: self.age,
height: self.height,
weight: self.weight,
ptGoal: self.ptGoal,
cautionNote: self.cautionNote
)
}
}

public extension GetConnectedTraineeInfoResponseDTO {
func toEntity() -> ConnectionInfoEntity {
return .init(
trainerName: self.trainer.trainerName,
traineeName: self.trainee.traineeName,
trainerProfileImageUrl: self.trainer.trainerProfileImageUrl,
traineeProfileImageUrl: self.trainee.traineeProfileImageUrl
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Foundation
/// - 실제 네트워크 요청은 이 인터페이스를 구현한 `TraineeRepositoryImpl`에서 수행됩니다.
public protocol TraineeRepository {
/// 트레이너와 트레이니의 연결을 요청합니다.
/// - Parameter info: 트레이너 연결을 위한 연결 정보 (`TraineeConnectInfo`)
/// - Parameter info: 트레이너 연결을 위한 연결 정보 (`PostConnectTrainerReqDTO`)
/// - Returns: 연결 성공 시, 연결된 트레이너 정보가 포함된 응답 DTO (`PostConnectTrainerResDTO`)
/// - Throws: 네트워크 오류 또는 잘못된 요청 데이터로 인한 서버 오류 발생 가능
func postConnectTrainer(_ info: TraineeConnectInfoEntity) async throws -> PostConnectTrainerResDTO
func postConnectTrainer(_ reqDTO: PostConnectTrainerReqDTO) async throws -> PostConnectTrainerResDTO
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public protocol TrainerRepository {

/// 회원 조희
func getMembersList() async throws -> GetMembersListDTO

/// 연결 완료된 트레이니 정보 불러오기
func getConnectedTraineeInfo(trainerId: Int, traineeId: Int) async throws -> GetConnectedTraineeInfoResponseDTO
}
13 changes: 10 additions & 3 deletions TnT/Projects/Domain/Sources/UseCase/TraineeUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public protocol TraineeUseCase {
/// API Call - 트레이너 초대 코드 인증 API 호출
func verifyTrainerInvitationCode(_ code: String) async throws -> Bool
/// API Call - 트레이니 - 트레이너 연결 API 호출
func connectTrainer(_ info: TraineeConnectInfoEntity) async throws -> ConnectionInfoEntity
func connectTrainer(_ reqDTO: PostConnectTrainerReqDTO) async throws -> ConnectionInfoEntity
}

// MARK: - Default 구현체
Expand Down Expand Up @@ -50,8 +50,8 @@ public struct DefaultTraineeUseCase: TraineeUseCase {
return result.isVerified
}

public func connectTrainer(_ info: TraineeConnectInfoEntity) async throws -> ConnectionInfoEntity {
let resDTO: PostConnectTrainerResDTO = try await traineeRepository.postConnectTrainer(info)
public func connectTrainer(_ reqDTO: PostConnectTrainerReqDTO) async throws -> ConnectionInfoEntity {
let resDTO: PostConnectTrainerResDTO = try await traineeRepository.postConnectTrainer(reqDTO)
return ConnectionInfoEntity(
trainerName: resDTO.trainerName,
traineeName: resDTO.traineeName,
Expand All @@ -60,3 +60,10 @@ public struct DefaultTraineeUseCase: TraineeUseCase {
)
}
}

// MARK: Repository
extension DefaultTraineeUseCase: TraineeRepository {
public func postConnectTrainer(_ reqDTO: PostConnectTrainerReqDTO) async throws -> PostConnectTrainerResDTO {
return try await traineeRepository.postConnectTrainer(reqDTO)
}
}
4 changes: 4 additions & 0 deletions TnT/Projects/Domain/Sources/UseCase/TrainerUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public struct DefaultTrainerUseCase: TrainerRepository {
public func getMembersList() async throws -> GetMembersListDTO {
return try await trainerRepository.getMembersList()
}

public func getConnectedTraineeInfo(trainerId: Int, traineeId: Int) async throws -> GetConnectedTraineeInfoResponseDTO {
return try await trainerRepository.getConnectedTraineeInfo(trainerId: trainerId, traineeId: traineeId)
}
}
Loading