Skip to content

Commit

Permalink
Merge pull request #121 from BudgetBuddiesTeam/feature/116-ModifyComm…
Browse files Browse the repository at this point in the history
…entsApi

[Feat] 댓글 수정, 댓글 개수 api 연결
  • Loading branch information
SeungWon1125 authored Aug 20, 2024
2 parents 48fc609 + 7c95f99 commit 16748f5
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// InfoRequest.swift
// InfoRequestDTO.swift
// BudgetBuddies
//
// Created by 김승원 on 8/17/24.
//

import Foundation

struct InfoRequest {
struct InfoRequestDTO {
let year: Int
let month: Int
let page: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ final class CommentManager {
Result<GetOneSupportsCommentsResponseDTO, Error>
) -> Void

// 댓글 하나 수정하기
typealias PutDiscountsCommentsNetworkCompletion = (Result<Response, Error>) -> Void
typealias PutSupportsCommentsNetworkCompletion = (Result<Response, Error>) -> Void

// MARK: - 할인정보 전체 댓글 불러오기
func fetchDiscountsComments(
discountInfoId: Int, request: CommentRequest,
discountInfoId: Int, request: PostCommentRequestDTO,
completion: @escaping (DiscountsCommentsNetworkCompletion)
) {
CommentProvider.request(.getDiscountsComments(discountInfoId: discountInfoId, request: request))
Expand All @@ -61,7 +65,7 @@ final class CommentManager {

// MARK: - 지원정보 전체 댓글 불러오기
func fetchSupportsComments(
supportsInfoId: Int, request: CommentRequest,
supportsInfoId: Int, request: PostCommentRequestDTO,
completion: @escaping (SupportsCommentsNetworkCompletion)
) {
CommentProvider.request(.getSupportsComments(supportInfoId: supportsInfoId, request: request)) {
Expand Down Expand Up @@ -190,4 +194,38 @@ final class CommentManager {
}

}

// MARK: - 할인정보 댓글 수정
func modifyDiscountsComments(
request: PutCommentRequestDTO, completion: @escaping (PutDiscountsCommentsNetworkCompletion)
) {
CommentProvider.request(.putDiscountsComments(request: request)) { result in
switch result {
case .success(let response):
print("통신 성공")
completion(.success(response))

case .failure(let error):
print("통신 에러 발생")
completion(.failure(error))
}
}
}

// MARK: - 지원정보 댓글 수정
func modifySupportsComments(
request: PutCommentRequestDTO, completion: @escaping (PutSupportsCommentsNetworkCompletion)
) {
CommentProvider.request(.putSupportsComments(request: request)) { result in
switch result {
case .success(let response):
print("통신 성공")
completion(.success(response))

case .failure(let error):
print("통신 에러 발생")
completion(.failure(error))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// CommentRequest.swift
// CommentRequestDTO.swift
// BudgetBuddies
//
// Created by 김승원 on 8/17/24.
//

import Foundation

struct CommentRequest {
struct PostCommentRequestDTO {
let page: Int
let size: Int
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// PutCommentRequestDTO.swift
// BudgetBuddies
//
// Created by 김승원 on 8/20/24.
//

import Foundation

struct PutCommentRequestDTO {
let content: String
let commentId: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import Foundation
import Moya

enum CommentRouter {
case getDiscountsComments(discountInfoId: Int, request: CommentRequest)
case getSupportsComments(supportInfoId: Int, request: CommentRequest)
case getDiscountsComments(discountInfoId: Int, request: PostCommentRequestDTO)
case getSupportsComments(supportInfoId: Int, request: PostCommentRequestDTO)
case addDiscountsComments(userId: Int, request: DiscountsCommentsRequestDTO)
case addSupportsComments(userId: Int, request: SupportsCommentsRequestDTO)
case deleteComments(commentId: Int)
case getOneDiscountsComments(commentId: Int)
case getOneSupportsComments(commentId: Int)
case putDiscountsComments(request: PutCommentRequestDTO)
case putSupportsComments(request: PutCommentRequestDTO)
}

extension CommentRouter: TargetType {
Expand Down Expand Up @@ -45,6 +47,12 @@ extension CommentRouter: TargetType {

case .getOneSupportsComments(let commentId):
return "supports/comments/getOne/\(commentId)"

case .putDiscountsComments:
return "discounts/comments/modify"

case .putSupportsComments:
return "supports/comments/modify"
}
}

Expand All @@ -70,6 +78,12 @@ extension CommentRouter: TargetType {

case .getOneSupportsComments:
return .get

case .putDiscountsComments:
return .put

case .putSupportsComments:
return .put
}
}

Expand All @@ -80,7 +94,7 @@ extension CommentRouter: TargetType {
"page": request.page,
"size": request.size,
]
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
return .requestParameters(parameters: parameters, encoding: URLEncoding.default) // url에 담아 보내기

case .getSupportsComments(_, let request):
let parameters: [String: Any] = [
Expand Down Expand Up @@ -111,6 +125,20 @@ extension CommentRouter: TargetType {

case .getOneSupportsComments:
return .requestPlain

case .putDiscountsComments(let request):
let parameters: [String: Any] = [
"content": request.content,
"commentId": request.commentId,
]
return .requestParameters(parameters: parameters, encoding: JSONEncoding.default) // 바디에 담아 보내기

case .putSupportsComments(let request):
let parameters: [String: Any] = [
"content": request.content,
"commentId": request.commentId,
]
return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ final class DiscountInfoManager {

typealias DiscountInfoNetworkCompletion = (Result<DiscountsResponseDTO, Error>) -> Void

func fetchDiscounts(request: InfoRequest, completion: @escaping (DiscountInfoNetworkCompletion)) {
func fetchDiscounts(
request: InfoRequestDTO, completion: @escaping (DiscountInfoNetworkCompletion)
) {
DiscountInfoProvider.request(.getDiscounts(request: request)) { result in

switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Moya

enum DiscountInfoRouter {
case getDiscounts(request: InfoRequest)
case getDiscounts(request: InfoRequestDTO)
}

extension DiscountInfoRouter: TargetType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ final class SupportInfoManager {

typealias SupportInfoNetworkCompletion = (Result<SupportsResponseDTO, Error>) -> Void

func fetchSupports(request: InfoRequest, completion: @escaping (SupportInfoNetworkCompletion)) {
func fetchSupports(request: InfoRequestDTO, completion: @escaping (SupportInfoNetworkCompletion))
{
SupportInfoProvider.request(.getSupports(request: request)) { result in

switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Moya
// 입력할 파라미터 값

enum SupportInfoRouter {
case getSupports(request: InfoRequest)
case getSupports(request: InfoRequestDTO)
}

extension SupportInfoRouter: TargetType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ extension ConsumedHistoryDetailViewController {
do {
let decodedData = try JSONDecoder().decode(ExpenseResponseDTO.self, from: response.data)
} catch {
let postUpdatedFailureUIAlertController = UIAlertController(
title: "다시 시도하세요", message: "소비 내역 업데이트 실패", preferredStyle: .alert)
let confirmedButtonAction = UIAlertAction(title: "확인", style: .default)
postUpdatedFailureUIAlertController.addAction(confirmedButtonAction)
let postUpdatedFailureUIAlertController = UIAlertController(
title: "다시 시도하세요", message: "소비 내역 업데이트 실패", preferredStyle: .alert)
let confirmedButtonAction = UIAlertAction(title: "확인", style: .default)
postUpdatedFailureUIAlertController.addAction(confirmedButtonAction)

}
let postUpdatedConfirmedUIAlertController = UIAlertController(
title: "알림", message: "업데이트 성공", preferredStyle: .alert)
Expand Down
Loading

0 comments on commit 16748f5

Please sign in to comment.