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-227] Trainer API 최신화 작성 #79

Merged
merged 1 commit into from
Feb 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct TrainerRepositoryImpl: TrainerRepository {

public func getReissuanceInvitationCode() async throws -> GetReissuanceInvitationCodeDTO {
return try await networkService.request(
TrainerTargetType.getReissuanceInvitationCode,
TrainerTargetType.putReissuanceInvitationCode,
decodingType: GetReissuanceInvitationCodeDTO.self
)
}
Expand All @@ -46,6 +46,10 @@ public struct TrainerRepositoryImpl: TrainerRepository {
)
}

public func getMonthlyLessonList(year: Int, month: Int) async throws -> GetMonthlyLessonListResDTO {
return try await networkService.request(TrainerTargetType.getMonthlyLessonList(year: year, month: month), decodingType: GetMonthlyLessonListResDTO.self)
}

public func getMembersList() async throws -> GetMembersListDTO {
return try await networkService.request(
TrainerTargetType.getMemebersList,
Expand All @@ -56,4 +60,16 @@ public struct TrainerRepositoryImpl: TrainerRepository {
public func getConnectedTraineeInfo(trainerId: Int, traineeId: Int) async throws -> GetConnectedTraineeInfoResponseDTO {
return try await networkService.request(TrainerTargetType.getConnectedTraineeInfo(trainerId: trainerId, traineeId: traineeId), decodingType: GetConnectedTraineeInfoResponseDTO.self)
}

public func getActiveTraineesList() async throws -> GetActiveTraineesListResDTO {
return try await networkService.request(TrainerTargetType.getActiveTraineesList, decodingType: GetActiveTraineesListResDTO.self)
}

public func postLesson(reqDTO: PostLessonReqDTO) async throws -> PostLessonResDTO {
return try await networkService.request(TrainerTargetType.postLesson(reqDTO: reqDTO), decodingType: PostLessonResDTO.self)
}

public func putCompleteLesson(lessonId: Int) async throws -> PutCompleteLessonResDTO {
return try await networkService.request(TrainerTargetType.putCompleteLesson(lessonId: lessonId), decodingType: PutCompleteLessonResDTO.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ public enum TrainerTargetType {
case getFirstInvitationCode
/// 트레이너 캘린더, 특정 날짜의 PT 리스트 불러오기
case getDateLessonList(date: String)
/// 달력 스케줄 카운트 표시에 필요한 PT 리스트 불러오기
case getMonthlyLessonList(year: Int, month: Int)
/// 트레이너 초대코드 재발급
case getReissuanceInvitationCode
case putReissuanceInvitationCode
/// 회원 조희
case getMemebersList
/// 연결 완료된 트레이니 최초로 정보 불러오기
case getConnectedTraineeInfo(trainerId: Int, traineeId: Int)
/// 관리 중인 회원 목록 요청
case getActiveTraineesList
/// PT 수업 추가
case postLesson(reqDTO: PostLessonReqDTO)
/// PT 수업 완료 처리
case putCompleteLesson(lessonId: Int)
}

extension TrainerTargetType: TargetType {
Expand All @@ -40,65 +48,64 @@ extension TrainerTargetType: TargetType {
return "/invitation-code"
case .getDateLessonList(let date):
return "/lessons/\(date)"
case .getReissuanceInvitationCode:
case .getMonthlyLessonList:
return "/lessons/calendar"
case .putReissuanceInvitationCode:
return "/invitation-code/reissue"
case .getMemebersList:
return "/members"
case .getConnectedTraineeInfo:
return "/first-connected-trainee"
case .getActiveTraineesList:
return "/active-trainees"
case .postLesson:
return "lessons"
case .putCompleteLesson(let lessonId):
return "lessons/\(lessonId)/complete"
}
}

var method: HTTPMethod {
switch self {
case .getVerifyInvitationCode:
case .getVerifyInvitationCode, .getFirstInvitationCode, .getDateLessonList, .getMemebersList, .getConnectedTraineeInfo, .getMonthlyLessonList, .getActiveTraineesList:
return .get
case .getFirstInvitationCode:
return .get
case .getDateLessonList:
return .get
case .getReissuanceInvitationCode:

case .putReissuanceInvitationCode, .putCompleteLesson:
return .put
case .getMemebersList:
return .get
case .getConnectedTraineeInfo:
return .get

case .postLesson:
return .post
}
}

var task: RequestTask {
switch self {
case .getVerifyInvitationCode:
return .requestPlain
case .getFirstInvitationCode:
return .requestPlain
case .getDateLessonList:
return .requestPlain
case .getReissuanceInvitationCode:
return .requestPlain
case .getMemebersList:
case .getVerifyInvitationCode, .getFirstInvitationCode, .getDateLessonList, .putReissuanceInvitationCode, .getMemebersList, .getActiveTraineesList, .putCompleteLesson:
return .requestPlain

case let .getMonthlyLessonList(year, month):
return .requestParameters(parameters: [
"year": year,
"month": month
], encoding: .url)

case let .getConnectedTraineeInfo(trainerId, traineeId):
return .requestParameters(parameters: [
"trainerId": trainerId,
"traineeId": traineeId
], encoding: .url)

case .postLesson(let reqDTO):
return .requestJSONEncodable(encodable: reqDTO)
}
}

var headers: [String: String]? {
switch self {
case .getVerifyInvitationCode:
case .getVerifyInvitationCode, .getDateLessonList, .putReissuanceInvitationCode, .getMemebersList, .getMonthlyLessonList, .postLesson, .getActiveTraineesList:
return ["Content-Type": "application/json"]
case .getFirstInvitationCode:
return nil
case .getDateLessonList:
return ["Content-Type": "application/json"]
case .getReissuanceInvitationCode:
return ["Content-Type": "application/json"]
case .getMemebersList:
return ["Content-Type": "application/json"]
case .getConnectedTraineeInfo:

case .getFirstInvitationCode, .getConnectedTraineeInfo, .putCompleteLesson:
return nil
}
}
Expand Down
10 changes: 10 additions & 0 deletions TnT/Projects/Domain/Sources/DTO/Trainer/TrainerRequestDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
//

import Foundation

/// 수업 추가 요청 시 사용되는 DTO
public struct PostLessonReqDTO: Encodable {
/// 시작 시각
let start: String
/// 종료 시각
let end: String
/// 트레이니 id
let traineeId: Int
}
33 changes: 33 additions & 0 deletions TnT/Projects/Domain/Sources/DTO/Trainer/TrainerResponseDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,36 @@ public struct GetVerifyInvitationCodeResDTO: Decodable {
/// 트레이너 이름
public let trainerName: String?
}

/// 달력 스케줄 카운트 표시에 필요한 PT 리스트 불러오기 응답 DTO
public struct GetMonthlyLessonListResDTO: Decodable {
public let calendarPtLessonCounts: [DailyLessonCountResDTO]
}

/// 일별 스케줄 카운트 표시용 응답 DTO
public struct DailyLessonCountResDTO: Decodable {
public let date: String
public let count: Int
}

/// 관리 중인 회원 목록 응답 DTO
public struct GetActiveTraineesListResDTO: Decodable {
public let trainees: [ActiveTraineeInfoResDTO]
}

/// 관리 중인 회원 정보 DTO
public struct ActiveTraineeInfoResDTO: Decodable {
public let id: Int
public let name: String
public let profileImageUrl: String
public let finishedPtCount: Int
public let totalPtCount: Int
public let memo: String
public let ptGoals: [String]
}

/// PT 수업 추가 응답 DTO
public typealias PostLessonResDTO = EmptyResponse

/// PT 수업 완료 처리 응답 DTO
public typealias PutCompleteLessonResDTO = EmptyResponse
12 changes: 12 additions & 0 deletions TnT/Projects/Domain/Sources/Repository/TrainerRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ public protocol TrainerRepository {
/// 트레이너 캘린더에 특정 날짜의 수업 정보 가져오기
func getDateSessionList(date: String) async throws -> GetDateSessionListDTO

/// 달력 스케줄 카운트 표시에 필요한 PT 리스트 불러오기
func getMonthlyLessonList(year: Int, month: Int) async throws -> GetMonthlyLessonListResDTO

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

/// 연결 완료된 트레이니 정보 불러오기
func getConnectedTraineeInfo(trainerId: Int, traineeId: Int) async throws -> GetConnectedTraineeInfoResponseDTO

/// 관리 중인 회원 목록 요청
func getActiveTraineesList() async throws -> GetActiveTraineesListResDTO

/// PT 수업 추가
func postLesson(reqDTO: PostLessonReqDTO) async throws -> PostLessonResDTO

/// PT 수업 완료 처리
func putCompleteLesson(lessonId: Int) async throws -> PutCompleteLessonResDTO
}