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

[Feat] 리뷰 수정 API 연결 #185

Merged
merged 9 commits into from
Jul 21, 2022
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
6 changes: 5 additions & 1 deletion HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
695758F928857FDC00E36789 /* ReviewWriteEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 695758F828857FDC00E36789 /* ReviewWriteEntity.swift */; };
69D7074B2888062E00C2C278 /* ReviewDeleteEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D7074A2888062E00C2C278 /* ReviewDeleteEntity.swift */; };
69D7074D28885B9900C2C278 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 69D7074C28885B9900C2C278 /* GoogleService-Info.plist */; };
69D7074F28888D6500C2C278 /* ReviewEditEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69D7074E28888D6500C2C278 /* ReviewEditEntity.swift */; };
A90CFDCF2885B4DC0018AB94 /* SearchDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90CFDCE2885B4DC0018AB94 /* SearchDataModel.swift */; };
A90CFDD12885B4E70018AB94 /* SearchResultDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90CFDD02885B4E70018AB94 /* SearchResultDataModel.swift */; };
A90ED6252886644400FCE149 /* SearchEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90ED6222886644400FCE149 /* SearchEntity.swift */; };
Expand Down Expand Up @@ -298,6 +299,7 @@
695758F828857FDC00E36789 /* ReviewWriteEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewWriteEntity.swift; sourceTree = "<group>"; };
69D7074A2888062E00C2C278 /* ReviewDeleteEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewDeleteEntity.swift; sourceTree = "<group>"; };
69D7074C28885B9900C2C278 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
69D7074E28888D6500C2C278 /* ReviewEditEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewEditEntity.swift; sourceTree = "<group>"; };
A90CFDC82885B1880018AB94 /* SearchEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEntity.swift; sourceTree = "<group>"; };
A90CFDCA2885B2730018AB94 /* SearchResultEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultEntity.swift; sourceTree = "<group>"; };
A90CFDCE2885B4DC0018AB94 /* SearchDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchDataModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1804,6 +1806,7 @@
children = (
EBFAEB2F2885F2F7009C569C /* MyReviewEntity.swift */,
69D7074A2888062E00C2C278 /* ReviewDeleteEntity.swift */,
69D7074E28888D6500C2C278 /* ReviewEditEntity.swift */,
);
path = MyReviewScene;
sourceTree = "<group>";
Expand Down Expand Up @@ -2216,6 +2219,7 @@
FD72FCBD28834A190092746F /* NicknameChangeVC.swift in Sources */,
EBF66AC1287227F500DE0ED1 /* UIStackView+.swift in Sources */,
EBF66AF1287227F500DE0ED1 /* ShowToast.swift in Sources */,
69D7074F28888D6500C2C278 /* ReviewEditEntity.swift in Sources */,
EBF66AC4287227F500DE0ED1 /* UIButton+.swift in Sources */,
A90ED6332886652B00FCE149 /* SearchResultEntity.swift in Sources */,
FDA3AEF82880612300D6CCB4 /* UserWithdrawalUseCase.swift in Sources */,
Expand Down Expand Up @@ -2503,7 +2507,7 @@
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.healthFoodMe.release;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = healthFood_dev;
PROVISIONING_PROFILE_SPECIFIER = HealthFoodMe_Dev;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protocol ModuleFactoryProtocol {
func makeCopingTabVC() -> CopingTabVC
func makeReviewDetailVC() -> ReviewDetailVC
func makeReviewWriteVC() -> ReviewWriteVC
func makeReviewWriteNavigationController(restaurantId: String) -> UINavigationController
func makeReviewWriteNavigationController(restaurantId: String, restaurantName: String) -> UINavigationController

// MARK: - Search
func makeSearchVC() -> SearchVC
Expand Down Expand Up @@ -152,9 +152,10 @@ class ModuleFactory: ModuleFactoryProtocol {
return vc
}

func makeReviewWriteNavigationController(restaurantId: String) -> UINavigationController {
func makeReviewWriteNavigationController(restaurantId: String, restaurantName: String) -> UINavigationController {
let vc = ReviewWriteVC.controllerFromStoryboard(.reviewWrite)
vc.restaurantID = restaurantId
vc.restaurantName = restaurantName
guard let nc = UINavigationController(rootViewController: vc) as? UINavigationController else { return UINavigationController() }

return nc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - Datum
struct MyReviewEntity: Codable {
let restaurant: String
let restaurant, restaurantId: String
let score: Float
let content, id: String
let image: [MyReviewImage]
Expand All @@ -29,6 +29,7 @@ struct MyReviewEntity: Codable {
imageList.append(img.url)
}
return MyReviewModel.init(reviewId: id, restaurantName: restaurant,
restaurantId: restaurantId,
starRate: score,
tagList: hashTagList,
reviewImageURLList: imageList,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ReviewEditEntity.swift
// HealthFoodMe
//
// Created by 최영린 on 2022/07/21.
//

struct ReviewEditEntity: Codable {
let id, restaurant, writer: String
let score: Double
let content: String
let image: [editImage]
let taste: String
let good: [String]
let v: Int

enum CodingKeys: String, CodingKey {
case id = "_id"
case restaurant, writer, score, content, image, taste, good
case v = "__v"
}
}

// MARK: - Image
struct editImage: Codable {
let name: String
let url: String
let id: String

enum CodingKeys: String, CodingKey {
case name, url
case id = "_id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum ReviewRouter {
case getBlogReviewList(restaurantName: String)
case requestReviewEnabled(userId: String, restaurantId: String)
case requestReviewDelete(reviewId: String)
case requestReviewEdit(reviewId: String, score: Double, taste: String, good: [String], content: String, image: [UIImage], nameList: [String])
}

extension ReviewRouter: BaseRouter {
Expand All @@ -24,6 +25,8 @@ extension ReviewRouter: BaseRouter {
return .post
case .requestReviewDelete:
return .delete
case .requestReviewEdit:
return .put
default:
return .get
}
Expand All @@ -43,6 +46,8 @@ extension ReviewRouter: BaseRouter {
return "/review/check/\(userId)/\(restaurantId)"
case .requestReviewDelete(let reviewId):
return "/review/\(reviewId)"
case .requestReviewEdit(let reviewId,_,_,_,_,_,_):
return "/review/\(reviewId)"
default:
return ""

Expand Down Expand Up @@ -95,7 +100,27 @@ extension ReviewRouter: BaseRouter {
multiPart.append(imageData, withName: "image", fileName: "image\(index).png", mimeType: "image/png")
}
}
return multiPart
case .requestReviewEdit(_,let score, let taste, let good, let content, let image, let nameList):
let multiPart = MultipartFormData()

multiPart.append(Data(String(score).utf8), withName: "score")
multiPart.append(Data(taste.utf8), withName: "taste")
good.forEach {
let data = Data(String($0).utf8)
multiPart.append(data, withName: "good")
}
multiPart.append(Data(content.utf8), withName: "content")
for (index, item) in image.enumerated() {
print(index, item)
if let imageData = item.pngData() {
multiPart.append(imageData, withName: "image", fileName: "image\(index).png", mimeType: "image/png")
}
}
nameList.forEach {
let data = Data(String($0).utf8)
multiPart.append(data, withName: "nameList")
}
return multiPart
default: return MultipartFormData()
}
Expand All @@ -111,7 +136,7 @@ extension ReviewRouter: BaseRouter {

var header: HeaderType {
switch self {
case .requestReviewWrite:
case .requestReviewWrite, .requestReviewEdit:
return .multiPartWithToken
default:
return .withToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension ReviewService {
}
}
}

func requestBlogReviewList(restaurantName: String,
completion: @escaping(NetworkResult<Any>) -> Void) {
requestObject(ReviewRouter.getBlogReviewList(restaurantName: restaurantName),
Expand All @@ -73,4 +74,34 @@ extension ReviewService {
decodingMode: .message,
completion: completion)
}

func requestReviewEdit(reviewId: String, score: Double, taste: String, good: [String], content: String, image: [UIImage], nameList: [String], completion: @escaping (NetworkResult<Any>) -> Void) {

AFManager.upload(multipartFormData: ReviewRouter.requestReviewEdit(reviewId: reviewId,
score: score,
taste: taste,
good: good,
content: content,
image: image,
nameList: nameList).multipart,
with: ReviewRouter.requestReviewEdit(reviewId: reviewId,
score: score,
taste: taste,
good: good,
content: content,
image: image,
nameList: nameList)).responseData { response in
switch(response.result) {
case .success(let data):
guard let statusCode = response.response?.statusCode else { return }
guard let reviewRequestData = response.data else { return }

let networkResult = self.judgeStatus(by: statusCode, reviewRequestData, type: ReviewEditEntity.self, decodingMode: .model)
completion(networkResult)

case .failure(let err) :
print("ERR")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
struct MyReviewModel {
let reviewId: String
let restaurantName: String
let restaurantId: String
let starRate: Float
let tagList: [String]
let reviewImageURLList: [String]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct I18N {
static let questionPhoto = "사진을 올려주세요"
static let questionPhotoOption = "(선택)"
static let questionPhotoSub = "해당 가게와 무관한 사진을 첨부하면 노출 제한 처리될 수 있습니다. \n사진첨부 시 개인정보가 노출되지 않도록 유의해주세요."
static let writeReview = "리뷰 쓰기"
static let writeReview = "작성 완료"
static let checkReviewToast = "별점과 맛 평가는 필수입니다."
static let checkPhotoToast = "사진 첨부는 최대 3장까지만 가능합니다!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class StarRatingSlider: UIView {
// MARK: - Properties
private var previousValue: CGFloat = -1
private var starWidth: CGFloat = 37
var initialValue: Double = 2.5
var sliderValue : ( (Double) -> Void )?

// MARK: - UI Components
Expand All @@ -35,7 +36,7 @@ final class StarRatingSlider: UIView {

lazy var starContainerView: StarRatingView = {
let starView = StarRatingView.init(starScale: starWidth)
starView.rate = 0
starView.rate = initialValue
return starView
}()

Expand All @@ -51,8 +52,6 @@ final class StarRatingSlider: UIView {
self.init()
self.starWidth = starWidth
setUI()


}
}

Expand All @@ -65,7 +64,12 @@ extension StarRatingSlider {
starRateSlider.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
starContainerView.rate = initialValue
}

func setSliderValue(rate: Double) {
starContainerView.rate = rate
}
}

extension StarRatingSlider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MainDetailVC: UIViewController {
private var mainInfoInitialReload: Bool = true
var userLocation: Location?
var restaurantId: String = ""
var restaurantName: String = ""
var location: Location?
var panGestureEnabled = true
var viewModel: MainDetailViewModel!
Expand Down Expand Up @@ -63,6 +64,7 @@ class MainDetailVC: UIViewController {

private var reviewWriteCTAButton: CTAButton = {
let button = CTAButton(enableState: true, title: I18N.Detail.Main.reviewWriteCTATitle)
var isEdited = false
button.isEnabled = true
return button
}()
Expand Down Expand Up @@ -180,7 +182,7 @@ extension MainDetailVC {

private func setButtonAction() {
reviewWriteCTAButton.press {
let writeVC = ModuleFactory.resolve().makeReviewWriteNavigationController(restaurantId: self.restaurantId)
let writeVC = ModuleFactory.resolve().makeReviewWriteNavigationController(restaurantId: self.restaurantId, restaurantName: self.restaurantName)
writeVC.modalPresentationStyle = .fullScreen
self.present(writeVC, animated: true)
}
Expand Down Expand Up @@ -497,6 +499,7 @@ extension MainDetailVC {
self.mainInfoTVC.setData(data: data)
self.menuTabVC.setData(data: data.menu)
self.reviewTabVC.restaurantName = data.restaurant.name
self.restaurantName = data.restaurant.name
}
default:
print("통신 에러")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ final class ListPhotoCVC: UICollectionViewCell, UICollectionViewRegisterable {
static var isFromNib = false
weak var delegate: ListPhotoCVCDelegate?
var indexPath: Int = 0
var isEdited = ReviewWriteVC().isEdited

// MARK: - UI Components

lazy var photoImageView: UIImageView = {
let imageView = UIImageView()
// imageView.image = ImageLiterals.ReviewWrite.addPhotoIcon
imageView.contentMode = .scaleAspectFill
imageView.layer.masksToBounds = true
return imageView
Expand All @@ -41,6 +41,7 @@ final class ListPhotoCVC: UICollectionViewCell, UICollectionViewRegisterable {
override init(frame: CGRect) {
super.init(frame: frame)
setLayout()
print("1️⃣\(self.isEdited)")
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -57,6 +58,16 @@ extension ListPhotoCVC {
photoImageView.image = image
}

func setImageURL(_ url: String) {
let url = URL(string: url)
DispatchQueue.global().async {
let data = try? Data(contentsOf: url!)
DispatchQueue.main.async {
self.photoImageView.image = UIImage(data: data!)
}
}
}

func setLayout() {
contentView.addSubviews(photoImageView, deleteBtn)

Expand Down
Loading