Skip to content

Commit aac7d5f

Browse files
committed
[#60] 오늘의 코디 룩북에 추가 api 적용
#60
1 parent a1eb14d commit aac7d5f

6 files changed

Lines changed: 89 additions & 1 deletion

File tree

Codive/Features/Home/Data/DataSources/HomeDatasource.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ protocol HomeDatasourceProtocol {
3939

4040
/// 코디 수정
4141
func patchUpdateCoordinates(coordinateId: Int64, request: EditCoordinateRequestDTO) async throws
42+
43+
/// 이전 일일 코디로 자동 생성
44+
func createAutoDailyCoordinate(request: CreateAutoDailyCoordinateAPIRequestDTO) async throws -> CreateAutoDailyCoordinateAPIResponseDTO
4245
}
4346

4447
final class HomeDatasource: HomeDatasourceProtocol {
@@ -218,6 +221,11 @@ final class HomeDatasource: HomeDatasourceProtocol {
218221

219222
return urlInfo.finalUrl
220223
}
224+
225+
/// 이전 일일 코디로 자동 생성
226+
func createAutoDailyCoordinate(request: CreateAutoDailyCoordinateAPIRequestDTO) async throws -> CreateAutoDailyCoordinateAPIResponseDTO {
227+
return try await apiService.createAutoDailyCoordinate(request: request)
228+
}
221229

222230
private func uploadImageToS3(
223231
presignedUrl: String,

Codive/Features/Home/Data/Repositories/HomeRepositoryImpl.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ final class HomeRepositoryImpl: HomeRepository {
8989
try await dataSource.patchUpdateCoordinates(coordinateId: coordinateId, request: request)
9090
}
9191

92+
/// 이전 일일 코디로 자동 생성
93+
func createAutoDailyCoordinate(
94+
request: CreateAutoDailyCoordinateAPIRequestDTO
95+
) async throws -> AutoDailyCoordinateEntity {
96+
let dto = try await dataSource.createAutoDailyCoordinate(request: request)
97+
return dto.toEntity()
98+
}
99+
92100
/// 이미지 업로드
93101
func uploadCodiImage(jpgData: Data) async throws -> String {
94102
return try await dataSource.uploadCodiImage(jpgData: jpgData)

Codive/Features/Home/Data/Services/HomeAPIService.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ protocol HomeAPIServiceProtocol {
3737
/// 코디 수정
3838
func patchUpdateCoordinates(coordinateId: Int64, request: EditCoordinateRequestDTO) async throws
3939

40+
func createAutoDailyCoordinate(request: CreateAutoDailyCoordinateAPIRequestDTO) async throws -> CreateAutoDailyCoordinateAPIResponseDTO
41+
4042
/// 이미지 url 생성
4143
func getPresignedUrls(for images: [Data]) async throws -> [PresignedUrlInfo]
4244
}
@@ -291,6 +293,34 @@ extension HomeAPIService {
291293
throw LookBookAPIError.serverError(statusCode: code, message: "코디 수정 실패")
292294
}
293295
}
296+
297+
func createAutoDailyCoordinate(request: CreateAutoDailyCoordinateAPIRequestDTO) async throws -> CreateAutoDailyCoordinateAPIResponseDTO {
298+
let requestBody = Components.Schemas.CoordinateAutoCreateRequest(
299+
name: request.name,
300+
memo: request.memo,
301+
dailyCoordinateId: request.dailyCoordinateId,
302+
lookBookId: request.lookBookId
303+
)
304+
let input = Operations.Coordinate_createCoordinateAuto.Input(body: .json(requestBody))
305+
let response = try await client.Coordinate_createCoordinateAuto(input)
306+
307+
switch response {
308+
case .ok(let okResponse):
309+
let data = try await Data(collecting: okResponse.body.any, upTo: .max)
310+
let decoded = try jsonDecoder.decode(
311+
Components.Schemas.BaseResponseCoordinateCreateResponse.self,
312+
from: data
313+
)
314+
315+
guard let coordinateId = decoded.result?.coordinateId else {
316+
throw LookBookAPIError.invalidResponse
317+
}
318+
return CreateAutoDailyCoordinateAPIResponseDTO(coordinateId: coordinateId)
319+
320+
case .undocumented(statusCode: let code, _):
321+
throw LookBookAPIError.serverError(statusCode: code, message: "이전 일일 코디 자동 생성 실패")
322+
}
323+
}
294324
}
295325

296326
private extension HomeAPIService {

Codive/Features/Home/Domain/Protocols/HomeRepository.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ protocol HomeRepository {
4848
/// 코디 수정
4949
func patchUpdateCoordinates(coordinateId: Int64, request: EditCoordinateRequestDTO) async throws
5050

51+
/// 이전 일일 코디로 자동 생성
52+
func createAutoDailyCoordinate(request: CreateAutoDailyCoordinateAPIRequestDTO) async throws -> AutoDailyCoordinateEntity
53+
5154
func getToday() -> DateEntity
5255

5356
// MARK: - 카테고리 수정 관련

Codive/Features/Home/Domain/UseCases/AddToLookBookUseCase.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ final class AddToLookBookUseCase {
2626
direction: direction
2727
)
2828
}
29+
30+
/// 이전 일일 코디로 자동 생성
31+
func createAutoDailyCoordinate(
32+
request: CreateAutoDailyCoordinateAPIRequestDTO
33+
) async throws -> AutoDailyCoordinateEntity {
34+
try await repository.createAutoDailyCoordinate(request: request)
35+
}
2936
}

Codive/Features/Home/Presentation/ViewModel/HomeViewModel+.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,40 @@ extension HomeViewModel {
3535
}
3636
}
3737
/// 바텀시트에서 특정 룩북을 선택
38+
// func selectLookBook(_ entity: LookBookBottomSheetEntity) {
39+
// showLookBookSheet = false
40+
// }
41+
3842
func selectLookBook(_ entity: LookBookBottomSheetEntity) {
39-
showLookBookSheet = false
43+
// 1. 필요한 데이터(오늘의 코디 ID)가 있는지 확인
44+
guard let dailyCodiId = todayCodiPreview?.coordinateId else {
45+
print("⚠️ [Lookbook] 추가할 오늘의 코디 정보가 없습니다.")
46+
return
47+
}
48+
49+
Task {
50+
do {
51+
// 2. 요청 DTO 구성
52+
let request = CreateAutoDailyCoordinateAPIRequestDTO(
53+
name: "\(todayString) 코디", // 현재 날짜 기반 이름
54+
memo: "", // nil 대신 빈 문자열 (필요시 DTO 구조에 따라 조정)
55+
dailyCoordinateId: dailyCodiId,
56+
lookBookId: entity.lookbookId
57+
)
58+
59+
// 3. 유스케이스 호출
60+
let result = try await addToLookBookUseCase.createAutoDailyCoordinate(request: request)
61+
62+
print("✅ [Lookbook] 룩북 추가 성공: CoordinateID \(result.coordinateId)")
63+
64+
await MainActor.run {
65+
self.showLookBookSheet = false
66+
// 성공 피드백 알림 등을 여기에 추가할 수 있습니다.
67+
}
68+
} catch {
69+
print("❌ [Lookbook] 룩북 추가 실패: \(error.localizedDescription)")
70+
}
71+
}
4072
}
4173
}
4274

0 commit comments

Comments
 (0)