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 연결 #146

Merged
merged 5 commits into from
Jul 19, 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
23 changes: 21 additions & 2 deletions HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
695758EC28830E3000E36789 /* SplashVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 695758EB28830E3000E36789 /* SplashVC.swift */; };
695758EE28830E3F00E36789 /* Splash.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 695758ED28830E3F00E36789 /* Splash.storyboard */; };
695758F4288545CC00E36789 /* CopingTabEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 695758F3288545CC00E36789 /* CopingTabEntity.swift */; };
695758F928857FDC00E36789 /* ReviewWriteEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 695758F828857FDC00E36789 /* ReviewWriteEntity.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 @@ -280,6 +281,7 @@
695758EB28830E3000E36789 /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = "<group>"; };
695758ED28830E3F00E36789 /* Splash.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Splash.storyboard; sourceTree = "<group>"; };
695758F3288545CC00E36789 /* CopingTabEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopingTabEntity.swift; sourceTree = "<group>"; };
695758F828857FDC00E36789 /* ReviewWriteEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewWriteEntity.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 @@ -713,6 +715,22 @@
path = CopingTabScene;
sourceTree = "<group>";
};
695758F528857F8400E36789 /* Review */ = {
isa = PBXGroup;
children = (
695758F628857F9500E36789 /* ReviewWriteScene */,
);
path = Review;
sourceTree = "<group>";
};
695758F628857F9500E36789 /* ReviewWriteScene */ = {
isa = PBXGroup;
children = (
695758F828857FDC00E36789 /* ReviewWriteEntity.swift */,
);
path = ReviewWriteScene;
sourceTree = "<group>";
};
697074FB28737D78001A607F /* MenuTabScene */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -763,7 +781,6 @@
isa = PBXGroup;
children = (
C321ED365502C47A4E65A10E /* Pods_HealthFoodMe.framework */,
FD924375288007ED0034876B /* NicknameChange.storyboard */,
A90CFDD22885C3050018AB94 /* SearchRequestEntity.swift */,
A90CFDC82885B1880018AB94 /* SearchEntity.swift */,
A90CFDCA2885B2730018AB94 /* SearchResultEntity.swift */,
Expand Down Expand Up @@ -1611,6 +1628,7 @@
EBF66B062872AE4200DE0ED1 /* Entity */ = {
isa = PBXGroup;
children = (
695758F528857F8400E36789 /* Review */,
A90ED6212886644400FCE149 /* Search */,
A90CFDB228852C550018AB94 /* User */,
FDF2E21A287F5D7F0007D4F9 /* Author */,
Expand Down Expand Up @@ -2156,6 +2174,7 @@
EBF66ABE287227F500DE0ED1 /* UITextView+.swift in Sources */,
EBFAEB172885DE83009C569C /* Reissuance.swift in Sources */,
EBF66AD5287227F500DE0ED1 /* ViewModelType.swift in Sources */,
695758F928857FDC00E36789 /* ReviewWriteEntity.swift in Sources */,
69028BB02874A60E00373984 /* HeaderView.swift in Sources */,
EBFAEB302885F2F7009C569C /* MyReviewUseCase.swift in Sources */,
EBFAEB0A2885636E009C569C /* FirebaseAnalyticsProvider.swift in Sources */,
Expand Down Expand Up @@ -2422,7 +2441,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
@@ -0,0 +1,40 @@
//
// ReviewWriteEntity.swift
// HealthFoodMe
//
// Created by 최영린 on 2022/07/18.
//

import Foundation

// MARK: - ReviewWriteEntity

struct ReviewWriteEntity: Codable {
let restaurant, writer: String
let score: Int
let content: String
let image: [ReviewWriteImage]
let taste: String
let good: [String]
let id: String
let v: Int

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

// MARK: - Image
struct ReviewWriteImage: 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 @@ -83,7 +83,6 @@ extension BaseRouter {

case .requestPlain:
break

}

return request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ enum HTTPHeaderField: String {
enum HeaderContent: String {
case json = "application/json"
case multiPart = "multipart/form-data"
case tokenSerial = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZDRlZDI0MGZmMmY5MDBlYTg4YmVmNiIsImlhdCI6MTY1ODE2OTIwNywiZXhwIjoxNjU4MTcyODA3fQ.db5U6ro0LAVpquSHR2ICVpe4syK98VXAhwoc6vLsDOk"
case tokenSerial = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyZDRlODRmMGZmMmY5MDBlYTg4YmVjMyIsImlhdCI6MTY1ODI0NzMwMCwiZXhwIjoxNjU4MjUwOTAwfQ.amovJp_3LDOBBcPrlO6ZQJT0QTW-17VX5otwrbEuYxk"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,39 @@
//

import Alamofire
import UIKit

enum ReviewRouter {
case requestReviewWrite(userId: String, restaurantId: String, score: Double, taste: String, good: [String], content: String, image: [UIImage])
case getReviewList(restaurantId: String)
case requestUserReview(userId: String)
}

extension ReviewRouter: BaseRouter {
var method: HTTPMethod {
switch self {
default :
case .requestReviewWrite:
return .post
default:
return .get
}
}

var header: HeaderType {
return .multiPartWithToken
}

var path: String {
switch self {
case .getReviewList(let restaurantId):
return "review/restaurant/\(restaurantId)/"
case .requestUserReview(let userId):
return "/review/user/\(userId)"
case .requestReviewWrite(let userId, let restaurantId,_,_,_,_,_):
return "/review/user/\(userId)/restaurant/\(restaurantId)"
default:
return ""

}
}

Expand All @@ -48,10 +59,35 @@ extension ReviewRouter: BaseRouter {
}
}

var multipart: MultipartFormData {
switch self {
case .requestReviewWrite(_,_,let score, let taste, let good, let content, let image):
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")
}
}

return multiPart
default: return MultipartFormData()
}

var header: HeaderType {
switch self {
default:
return .withToken
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ extension ReviewService {
completion: completion)
}

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

AFManager.upload(multipartFormData: ReviewRouter.requestReviewWrite(userId: userId,
restaurantId: restaurantId,
score: score,
taste: taste,
good: good,
content: content,
image: image).multipart,
with: ReviewRouter.requestReviewWrite(userId: userId,
restaurantId: restaurantId, score: score, taste: taste, good: good, content: content, image: image)).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: ReviewWriteEntity.self, decodingMode: .model)
completion(networkResult)


case .failure(let err) :
print("ERR")
}
}
}
func requestUserReview(userId: String, completion: @escaping(NetworkResult<Any>) -> Void) {
requestObject(ReviewRouter.requestUserReview(userId: userId), type: [MyReviewEntity].self, decodingMode: .model, completion: completion)
}
Expand Down
36 changes: 36 additions & 0 deletions HealthFoodMe/HealthFoodMe/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>978280628900-i578u456pougpdhlh0mmf6hdf1d6dspa.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.978280628900-i578u456pougpdhlh0mmf6hdf1d6dspa</string>
<key>ANDROID_CLIENT_ID</key>
<string>978280628900-qhf2c4ltcl71e4reod89n3mlan5p1q58.apps.googleusercontent.com</string>
<key>API_KEY</key>
<string>AIzaSyAVRFfLu-g1b8g-SQyWlgSQkGwAy9ThdYM</string>
<key>GCM_SENDER_ID</key>
<string>978280628900</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.healthFoodMe.release</string>
<key>PROJECT_ID</key>
<string>health-food-me</string>
<key>STORAGE_BUCKET</key>
<string>health-food-me.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:978280628900:ios:ec2ddfc73e29e2ed6bdc31</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ final class ReviewWriteVC: UIViewController, UIScrollViewDelegate {
var userSelectedImages: [UIImage] = [UIImage]()
var tasteSet = ""
var feelingArray: [Bool] = [false, false, false]
var userId = "62d4e84f0ff2f900ea88bec3" //임시로 넣어준 userID
var restaurantID = "62d26c9bd11146a81ef18ea6" //임시로 넣어준 식당ID
private var currentRate: Double = 0

// MARK: - UI Components
Expand All @@ -46,7 +48,7 @@ final class ReviewWriteVC: UIViewController, UIScrollViewDelegate {

private lazy var restaurantTitleLabel: UILabel = {
let lb = UILabel()
lb.text = "샐러디 태릉입구점"
lb.text = "샐러디 태릉입구점(임시)"
lb.textColor = .helfmeBlack
lb.font = .NotoBold(size: 16)
return lb
Expand Down Expand Up @@ -383,13 +385,11 @@ extension ReviewWriteVC {
backButton.setImage(ImageLiterals.MainDetail.beforeIcon, for: .normal)
backButton.tintColor = .helfmeBlack
backButton.addAction(UIAction(handler: { _ in

self.makeAlert(alertType: .logoutAlert,
title: "리뷰작성을 취소하시겠습니까?",
subtitle: "작성취소 시,\n 작성된 글은 저장되지 않습니다.") {
self.navigationController?.dismiss(animated: true)

}
}
}), for: .touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
}
Expand Down Expand Up @@ -675,7 +675,7 @@ extension ReviewWriteVC {
if !checkReview() {
showReviewToast()
} else {
makeAlert(title: "알림", message: "작성완료!")
requestReviewWrite()
}
}

Expand Down Expand Up @@ -769,7 +769,44 @@ extension ReviewWriteVC {
// MARK: - Network

extension ReviewWriteVC {

func requestReviewWrite() {
let starScore = self.currentRate
let taste = tasteSet
var good : [String] = []
for i in 0...2 {
if feelingArray[i] == true{
switch i{
case 0:
good.append("# 약속 시 부담없는")
case 1:
good.append("# 양 조절 쉬운")
case 2:
good.append("# 든든한")
default:
print("음")
}
}
}

if reviewTextView.text == I18N.Detail.Review.reviewPlaceholder{
reviewTextView.text = " "
}
guard let content = reviewTextView.text else { return }

let image = photoModel.userSelectedImages
ReviewService.shared.requestReviewWrite(userId: userId, restaurantId: restaurantID, score: starScore, taste: taste, good: good, content: content, image: image) { networkResult in
dump(networkResult)
switch networkResult {
case .success(let data):
if let data = data as? ReviewWriteEntity {
print(data, "성공")
self.navigationController?.dismiss(animated: true)
}
default:
break;
}
}
}
}

extension ReviewWriteVC: UICollectionViewDelegate, UICollectionViewDataSource {
Expand Down