Skip to content

Commit 5228bfa

Browse files
authored
[Merge] #219 - 1차 QA 반영
2 parents 752a6fc + addf2f1 commit 5228bfa

23 files changed

Lines changed: 166 additions & 114 deletions

CERTI-iOS/Data/Network/Comment/CommentAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import Moya
1111

1212
enum CommentAPI {
13-
case getComment(certificationId: Int, page: Int, size: Int, sort: String)
13+
case getComment(certificationId: Int, page: Int, size: Int, commentSortType: String)
1414
case addComment(request: CommentRequestDTO)
1515
case deleteComment(commentId: Int)
1616
case likeComment(commentId: Int)
@@ -52,12 +52,12 @@ extension CommentAPI: BaseTargetType {
5252

5353
var task: Moya.Task {
5454
switch self {
55-
case .getComment(let certificationId, let page, let size, let sort):
55+
case .getComment(let certificationId, let page, let size, let commentSortType):
5656
return .requestParameters(parameters: [
5757
"certificationId": certificationId,
5858
"page": page,
5959
"size": size,
60-
"sort": sort
60+
"commentSortType": commentSortType
6161
], encoding: URLEncoding.queryString)
6262
case .addComment(let request):
6363
return .requestJSONEncodable(request)

CERTI-iOS/Data/Network/Comment/CommentService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import Moya
1111

1212
protocol CommentServiceProtocol {
13-
func getComment(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentListResponseDTO, NetworkError>
13+
func getComment(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentListResponseDTO, NetworkError>
1414
func addComment(request: CommentRequestDTO) async ->Result<Void, NetworkError>
1515
func deleteComment(commentId: Int) async ->Result<Void, NetworkError>
1616
func likeComment(commentId: Int) async -> Result<Void, NetworkError>
@@ -19,8 +19,8 @@ protocol CommentServiceProtocol {
1919
final class CommentService: BaseService, CommentServiceProtocol {
2020
private let provider = MoyaProvider<CommentAPI>.init(plugins: [MoyaPlugin()])
2121

22-
func getComment(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentListResponseDTO, NetworkError> {
23-
return await requestDecodable(provider, .getComment(certificationId: certificationId, page: page, size: size, sort: sort))
22+
func getComment(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentListResponseDTO, NetworkError> {
23+
return await requestDecodable(provider, .getComment(certificationId: certificationId, page: page, size: size, commentSortType: commentSortType))
2424
}
2525

2626
func addComment(request: CommentRequestDTO) async -> Result<Void, NetworkError> {

CERTI-iOS/Data/Repositories/DefaultCommentRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ final class DefaultCommentRepository: CommentRepository {
1616
self.service = service
1717
}
1818

19-
func getComment(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentEntity, NetworkError> {
20-
let result = await service.getComment(certificationId: certificationId, page: page, size: size, sort: sort)
19+
func getComment(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentEntity, NetworkError> {
20+
let result = await service.getComment(certificationId: certificationId, page: page, size: size, commentSortType: commentSortType)
2121

2222
switch result {
2323
case .success(let dto):

CERTI-iOS/Domain/Interfaces/Repositories/CommentRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import Moya
1111

1212
protocol CommentRepository {
13-
func getComment(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentEntity, NetworkError>
13+
func getComment(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentEntity, NetworkError>
1414
func addComment(request: AddCommentEntity) async -> Result<Void, NetworkError>
1515
func deleteComment(commentId: Int) async -> Result<Void, NetworkError>
1616
func likeComment(commentId: Int) async -> Result<Void, NetworkError>

CERTI-iOS/Domain/UseCases/Comment/FetchCommentUseCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
protocol FetchCommentUseCase {
11-
func execute(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentEntity, NetworkError>
11+
func execute(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentEntity, NetworkError>
1212
}
1313

1414
final class DefaultFetchCommentUseCase: FetchCommentUseCase {
@@ -18,7 +18,7 @@ final class DefaultFetchCommentUseCase: FetchCommentUseCase {
1818
self.repository = repository
1919
}
2020

21-
func execute(certificationId: Int, page: Int, size: Int, sort: String) async -> Result<CommentEntity, NetworkError> {
22-
return await repository.getComment(certificationId: certificationId, page: page, size: size, sort: sort)
21+
func execute(certificationId: Int, page: Int, size: Int, commentSortType: String) async -> Result<CommentEntity, NetworkError> {
22+
return await repository.getComment(certificationId: certificationId, page: page, size: size, commentSortType: commentSortType)
2323
}
2424
}

CERTI-iOS/Global/Components/DatePickerBox.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ struct DatePickerBox: View {
1818
formatter.locale = Locale(identifier: "ko_KR")
1919
return formatter
2020
}
21+
private var today: Date {
22+
Calendar.current.startOfDay(for: Date())
23+
}
2124

2225
var body: some View {
2326
VStack(alignment: .leading, spacing: 0) {
@@ -64,7 +67,7 @@ struct DatePickerBox: View {
6467
self.isCalendarVisible = false
6568
}
6669
}
67-
), displayedComponents: .date)
70+
), in: today..., displayedComponents: .date)
6871
.datePickerStyle(.graphical)
6972
.background(
7073
RoundedRectangle(cornerRadius: 12)

CERTI-iOS/Global/Extensions/String+.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ extension String {
8080
return "\(outputFormatter.string(from: date))"
8181
}
8282

83+
func toCommentDateString() -> String {
84+
let inputFormatter = DateFormatter()
85+
inputFormatter.locale = Locale(identifier: "ko_KR")
86+
inputFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
87+
88+
guard let date = inputFormatter.date(from: self) else {
89+
return self
90+
}
91+
92+
let outputFormatter = DateFormatter()
93+
outputFormatter.locale = Locale(identifier: "ko_KR")
94+
outputFormatter.dateFormat = "yyyy.MM.dd"
95+
96+
return outputFormatter.string(from: date)
97+
}
98+
8399
func toBirthDateString() -> String {
84100
let inputFormatter = DateFormatter()
85101
inputFormatter.dateFormat = "yyyy-MM-dd"

CERTI-iOS/Presentation/CertificateDetail/Components/CommentComponent.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ struct CommentComponent: View {
4646

4747
// MARK: - Properties
4848

49-
private var dateFormatter: DateFormatter {
50-
let formatter = DateFormatter()
51-
formatter.dateFormat = "yyyy.MM.dd"
52-
formatter.locale = Locale(identifier: "ko_KR")
53-
return formatter
54-
}
55-
5649
let model: Comment
5750
let certificationState: CertificationType
5851
let userName: UserType
@@ -67,7 +60,6 @@ struct CommentComponent: View {
6760
VStack(alignment: .leading, spacing: 0) {
6861

6962
userInfomation
70-
.padding(.top, 8)
7163

7264
Text(model.content.antiAppleBySangyup)
7365
.applyCertiFont(.caption_regular_14)
@@ -157,7 +149,7 @@ extension CommentComponent {
157149
.padding(.leading, 8)
158150
}
159151

160-
Text(dateFormatter.string(from: Date()))
152+
Text(model.createdTime.toCommentDateString())
161153
.applyCertiFont(.caption_semibold_12)
162154
.foregroundStyle(.grayscale400)
163155
.padding(.leading, 8)

CERTI-iOS/Presentation/CertificateDetail/View/CertificateCommentView.swift

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,66 @@ struct CertificateCommentView: View {
1717
var body: some View {
1818
VStack(alignment: .center, spacing: 0) {
1919
ScrollView(.vertical) {
20-
HStack(alignment: .center, spacing: 0) {
21-
CommentSortButton(isSelectedPopularity: isSelectedPopularity) {
22-
isSelectedPopularity.toggle()
23-
Task {
24-
await viewModel.refreshComments(certificationId: certificationId)
20+
VStack(alignment: .center, spacing: 0) {
21+
HStack(alignment: .center, spacing: 0) {
22+
CommentSortButton(isSelectedPopularity: isSelectedPopularity) {
23+
isSelectedPopularity.toggle()
24+
Task {
25+
await viewModel.refreshComments(certificationId: certificationId)
26+
}
2527
}
28+
.padding(.leading, 20)
29+
30+
Spacer()
31+
32+
Text("댓글 (\(totalCommentCount))")
33+
.applyCertiFont(.caption_regular_14)
34+
.foregroundStyle(.grayscale400)
35+
.padding(.trailing, 20)
2636
}
27-
.padding(.leading, 20)
37+
.padding(.top, 36)
2838

29-
Spacer()
30-
31-
Text("댓글 (\(totalCommentCount))")
32-
.applyCertiFont(.caption_regular_14)
33-
.foregroundStyle(.grayscale400)
34-
.padding(.trailing, 20)
35-
}
36-
.padding(.bottom, 12)
37-
.padding(.top, 36)
38-
39-
LazyVStack(spacing: 0) {
40-
if viewModel.comments.isEmpty {
41-
VStack(alignment: .center, spacing: 0) {
42-
Image(.imageEmpty)
43-
.padding(.top, 134)
44-
45-
Text("아직 댓글이 없습니다.\n가장 먼저 댓글을 작성해보세요.")
46-
.multilineTextAlignment(.center)
47-
.applyCertiFont(.caption_regular_14)
48-
.foregroundStyle(.grayscale400)
49-
.frame(height: 40)
39+
LazyVStack(spacing: 0) {
40+
if viewModel.comments.isEmpty {
41+
VStack(alignment: .center, spacing: 0) {
42+
Image(.imageEmpty)
43+
.padding(.top, 134)
44+
45+
Text("아직 댓글이 없습니다.\n가장 먼저 댓글을 작성해보세요.")
46+
.multilineTextAlignment(.center)
47+
.applyCertiFont(.caption_regular_14)
48+
.foregroundStyle(.grayscale400)
49+
.frame(height: 40)
50+
.padding(.top, 20)
51+
}
52+
.frame(maxWidth: .infinity)
53+
} else {
54+
ForEach(viewModel.comments) { comment in
55+
CommentComponent(
56+
model: comment,
57+
certificationState: comment.state == "취득 완료" ? .completed : .expected,
58+
userName: comment.nickName == nil ? .unknown : .normal(userName:comment.nickName!),
59+
canDelete: comment.userId == viewModel.currentUserId,
60+
onTapLike: {
61+
Task{
62+
await viewModel.toggleLike(commentId: comment.commentId)
63+
}
64+
}, onTapDelete: {
65+
viewModel.showDeleteCommentModal(commentId: comment.commentId)
66+
}, onTapReport: {
67+
viewModel.showCommentReportModal(commentId: comment.commentId)
68+
}
69+
)
5070
.padding(.top, 20)
51-
}
52-
.frame(maxWidth: .infinity)
53-
} else {
54-
ForEach(viewModel.comments) { comment in
55-
CommentComponent(
56-
model: comment,
57-
certificationState: comment.state == "취득 완료" ? .completed : .expected,
58-
userName: comment.nickName == nil ? .unknown : .normal(userName:comment.nickName!),
59-
canDelete: comment.userId == viewModel.currentUserId,
60-
onTapLike: {
61-
Task{
62-
await viewModel.toggleLike(commentId: comment.commentId)
71+
.padding(.horizontal, 20)
72+
}
73+
if !viewModel.isLastPage {
74+
ProgressView()
75+
.padding(.vertical, 16)
76+
.task {
77+
await viewModel.fetchComment(certificationId: certificationId)
6378
}
64-
}, onTapDelete: {
65-
viewModel.showDeleteCommentModal(commentId: comment.commentId)
66-
}, onTapReport: {
67-
viewModel.showCommentReportModal(commentId: comment.commentId)
68-
}
69-
)
70-
.padding(.horizontal, 20)
71-
}
72-
if !viewModel.isLastPage {
73-
ProgressView()
74-
.padding(.vertical, 16)
75-
.task {
76-
await viewModel.fetchComment(certificationId: certificationId)
77-
}
79+
}
7880
}
7981
}
8082
}

CERTI-iOS/Presentation/CertificateDetail/View/CertificationDetailPlanModalView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extension CertificationDetailPlanModalView {
155155
Text("나중에 입력하기")
156156
.applyCertiFont(.caption_semibold_12)
157157
.foregroundStyle(.grayscale300)
158+
.padding(.top, 48)
158159

159160
Rectangle()
160161
.frame(width: 97, height: 1)

0 commit comments

Comments
 (0)