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

댓글 date 타입 수정 #63

Merged
merged 3 commits into from
Jan 11, 2024
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
2 changes: 1 addition & 1 deletion pins/Domain/Entity/CommentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ struct CommentRequest: Codable {
let pinId: String
let userId: String
let content: String
let createdAt: String
let createdAt: Date
}
2 changes: 1 addition & 1 deletion pins/Domain/Entity/CommentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ struct CommentResponse {
self.userProfile = profile
self.userDescription = user.description ?? ""
self.content = commentRequest.content
self.createdAt = commentRequest.createdAt.convertDaysAgo()
self.createdAt = commentRequest.createdAt.currentDateTimeAsString().convertDaysAgo()
}
}
17 changes: 9 additions & 8 deletions pins/Domain/UseCase/DetailUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class DetailUseCase: DetailUseCaseProtocol {
pinId: pinId,
userId: userId,
content: text,
createdAt: Date().currentDateTimeAsString()))
createdAt: Date()))
} catch {
throw error
}
Expand All @@ -52,19 +52,20 @@ final class DetailUseCase: DetailUseCaseProtocol {

func getComments(pinId: String) async throws -> [CommentResponse] {
let commentRequests = try await fetchCommentRequests(pinId: pinId)
return try await withThrowingTaskGroup(of: CommentResponse?.self, returning: [CommentResponse].self) { group in
var commentResponses: [CommentResponse] = []
for commentRequest in commentRequests {
return try await withThrowingTaskGroup(of: (Int, CommentResponse?).self, returning: [CommentResponse].self) { group in
var commentResponses: [(Int, CommentResponse)] = []
for (index, commentRequest) in commentRequests.enumerated() {
group.addTask { [weak self] in
return try await self?.processCommentRequest(commentRequest)
let response = try await self?.processCommentRequest(commentRequest)
return (index, response)
}
}
for try await response in group {
for try await (index, response) in group {
if let response = response {
commentResponses.append(response)
commentResponses.append((index, response))
}
}
return commentResponses
return commentResponses.sorted(by: { $0.0 < $1.0 }).map { $0.1 }
}
}
}
6 changes: 3 additions & 3 deletions pins/Extension/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ extension String {

func birthDateToAge() -> Int {
String.dateFormatter.dateFormat = "yyMMdd"
let birthDate = String.dateFormatter.date(from: self)
let birthDate = String.dateFormatter.date(from: self) ?? Date()
let calendar = Calendar.current
let ageComponents = calendar.dateComponents([.year], from: birthDate!, to: Date())
let age = ageComponents.year!
let ageComponents = calendar.dateComponents([.year], from: birthDate, to: Date())
let age = ageComponents.year ?? 0
return age
}
}
2 changes: 1 addition & 1 deletion pinsTests/MockClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class MockFirestorageService: FirestorageServiceProtocol {
}

final class MockCommentService: CommentServiceProtocol {
var mockComment: [CommentRequest] = [CommentRequest(id: "testId", pinId: "testPin", userId: "testUserId", content: "testComment", createdAt: "")]
var mockComment: [CommentRequest] = [CommentRequest(id: "testId", pinId: "testPin", userId: "testUserId", content: "testComment", createdAt: Date())]
func getComments(pinId: String) async -> [pins.CommentRequest] {
return mockComment
}
Expand Down