Skip to content

Commit

Permalink
Merge pull request #142 from Sopt-Mongle/feature/#137
Browse files Browse the repository at this point in the history
Feature/#137
  • Loading branch information
Juhyeoklee authored Nov 14, 2020
2 parents 6337a81 + 8c990bd commit 4e93292
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 101 deletions.
8 changes: 8 additions & 0 deletions Mongle/Mongle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
7F6ABED924ADEC9E0040746E /* APIConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F6ABED824ADEC9E0040746E /* APIConstants.swift */; };
7F6ABEDB24ADED910040746E /* GenericResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F6ABEDA24ADED910040746E /* GenericResponse.swift */; };
7F6ABEDD24ADF3B20040746E /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F6ABEDC24ADF3B20040746E /* NetworkResult.swift */; };
7F74597D25600A7B0095FC5D /* ReportService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F74597C25600A7B0095FC5D /* ReportService.swift */; };
7F767D7724B211D100ADF46D /* WritingThemeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F767D7624B211D100ADF46D /* WritingThemeVC.swift */; };
7F7C096D24B9C776007C7C52 /* SentenceInfo.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7F7C096C24B9C776007C7C52 /* SentenceInfo.storyboard */; };
7F7C096F24BA2910007C7C52 /* SentenceInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F7C096E24BA2910007C7C52 /* SentenceInfoVC.swift */; };
Expand Down Expand Up @@ -62,6 +63,7 @@
7FCEE21B24B3091C00225CA3 /* MainTabFirstTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FCEE21A24B3091C00225CA3 /* MainTabFirstTVC.swift */; };
7FCEE21D24B355FC00225CA3 /* MainPictureCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FCEE21C24B355FC00225CA3 /* MainPictureCVC.swift */; };
7FCEE21F24B363CF00225CA3 /* MainTabSecondTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FCEE21E24B363CF00225CA3 /* MainTabSecondTVC.swift */; };
7FF9622825603E77002BDEF7 /* SentenceEditService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FF9622725603E77002BDEF7 /* SentenceEditService.swift */; };
7FFEA26624BE1B54003D381A /* VersionInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FFEA26524BE1B54003D381A /* VersionInfoVC.swift */; };
7FFEA26824BE1E05003D381A /* Mongles.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7FFEA26724BE1E05003D381A /* Mongles.storyboard */; };
7FFEA26A24BE3317003D381A /* MonglesVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FFEA26924BE3317003D381A /* MonglesVC.swift */; };
Expand Down Expand Up @@ -254,6 +256,7 @@
7F6ABED824ADEC9E0040746E /* APIConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIConstants.swift; sourceTree = "<group>"; };
7F6ABEDA24ADED910040746E /* GenericResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericResponse.swift; sourceTree = "<group>"; };
7F6ABEDC24ADF3B20040746E /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
7F74597C25600A7B0095FC5D /* ReportService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportService.swift; sourceTree = "<group>"; };
7F767D7624B211D100ADF46D /* WritingThemeVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WritingThemeVC.swift; sourceTree = "<group>"; };
7F7C096C24B9C776007C7C52 /* SentenceInfo.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SentenceInfo.storyboard; sourceTree = "<group>"; };
7F7C096E24BA2910007C7C52 /* SentenceInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentenceInfoVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -285,6 +288,7 @@
7FCEE21A24B3091C00225CA3 /* MainTabFirstTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabFirstTVC.swift; sourceTree = "<group>"; };
7FCEE21C24B355FC00225CA3 /* MainPictureCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainPictureCVC.swift; sourceTree = "<group>"; };
7FCEE21E24B363CF00225CA3 /* MainTabSecondTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabSecondTVC.swift; sourceTree = "<group>"; };
7FF9622725603E77002BDEF7 /* SentenceEditService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentenceEditService.swift; sourceTree = "<group>"; };
7FFEA26524BE1B54003D381A /* VersionInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionInfoVC.swift; sourceTree = "<group>"; };
7FFEA26724BE1E05003D381A /* Mongles.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Mongles.storyboard; sourceTree = "<group>"; };
7FFEA26924BE3317003D381A /* MonglesVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonglesVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -599,6 +603,8 @@
EC759C5124C03C77001D2F81 /* SearchThemeService.swift */,
7FA8C4AC24C0C64F00317F43 /* ThemeService.swift */,
7FA8C4B224C0FB5C00317F43 /* SentenceService.swift */,
7FF9622725603E77002BDEF7 /* SentenceEditService.swift */,
7F74597C25600A7B0095FC5D /* ReportService.swift */,
7FA8C4BC24C1BFB000317F43 /* NoThemeSentenceService.swift */,
B8E2E15824C0A71E00595752 /* SearchSentenceService.swift */,
B8E2E15E24C0C08100595752 /* SearchCuratorService.swift */,
Expand Down Expand Up @@ -1098,6 +1104,7 @@
EC759C4E24C0272A001D2F81 /* ThemeSelectForWriteService.swift in Sources */,
B8E2E17924C29CD300595752 /* MyThemeData.swift in Sources */,
B86D4C4224B2C14200C21906 /* RecommendSearchCVC.swift in Sources */,
7F74597D25600A7B0095FC5D /* ReportService.swift in Sources */,
7F1E719724B4553F00D79516 /* MainTabThirdTVC.swift in Sources */,
B8E2E15B24C0AA8500595752 /* SearchSentenceData.swift in Sources */,
7F1E71A024B476C900D79516 /* MainMongleHeaderView.swift in Sources */,
Expand Down Expand Up @@ -1128,6 +1135,7 @@
B8B48A5D24B6029100551F5B /* SearchResultSentenceVC.swift in Sources */,
EC7C78F024B2F2DE00B7FCFB /* UnderTabBarController.swift in Sources */,
B8E2E15D24C0AA9A00595752 /* SearchCuratorData.swift in Sources */,
7FF9622825603E77002BDEF7 /* SentenceEditService.swift in Sources */,
B8E2E17F24C2B67300595752 /* MyCuratorService.swift in Sources */,
B8B48B3724BC878C00551F5B /* CuratorTabMainTVC.swift in Sources */,
B8E2E14B24BEE0A000595752 /* MyTabThemeVC.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion Mongle/Mongle/Resource/APIService/APIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ struct APIConstants {
static let detailThemeURL = baseURL + "/detail/theme"
// 문장 상세조회 (/detail/sentence/:sentenceIdx)
static let detailSentenceURL = baseURL + "/detail/sentence"
// 신고하기
static let detailReportURL = baseURL + "/detail/report"
//테마 없는 문장 목록 조회 (/post/emptySentence)
static let postEmptySentenceURL = baseURL + "/post/emptySentence"
// 테마 없는 문장 테마 지정하기 (/post/setTheme)
static let postSetThemeURL = baseURL + "/post/setTheme"

// 문장 수정
static let myURL = baseURL + "/my"
static let bookSearchForWritingURL = baseURL + "/post/bookSearch"
static let recentSearchURL = baseURL + "/search/recent"
static let recommendSearchURL = baseURL + "/search/recommend"
Expand Down
71 changes: 71 additions & 0 deletions Mongle/Mongle/Resource/APIService/ReportService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// ReportService.swift
// Mongle
//
// Created by 이주혁 on 2020/11/14.
// Copyright © 2020 이주혁. All rights reserved.
//

import Foundation
import Alamofire

struct ReportService {
static let shared = ReportService()

func report(type: String, idx: Int, content: String, completion: @escaping (NetworkResult<Any>) -> ()) {

let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest"

let header: HTTPHeaders = [
"Content-Type":"application/json",
"token":token
]

let parameter: Parameters = [
"sort": type,
"idx": idx,
"content" : content
]

let url = APIConstants.detailReportURL

Alamofire.request(url,
method: .post,
parameters: parameter,
encoding: JSONEncoding.default,
headers: header).responseData { response in
switch response.result {
case .success:
guard let statusCode = response.response?.statusCode else {
return
}
guard let data = response.value else {
return
}
completion(self.judge(status: statusCode, data: data))
case .failure(let err):
print(err)
completion(.networkFail)
}
}


}

private func judge(status: Int, data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<String>.self, from: data) else {
return .pathErr
}
switch status {
case 200:
return .success(decodedData.data)
case 400..<500:
return .requestErr(decodedData.message)
case 600:
return .serverErr
default:
return .networkFail
}
}
}
124 changes: 124 additions & 0 deletions Mongle/Mongle/Resource/APIService/SentenceEditService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// SentenceEditService.swift
// Mongle
//
// Created by 이주혁 on 2020/11/15.
// Copyright © 2020 이주혁. All rights reserved.
//

import Foundation
import Alamofire

struct SentenceEditService {
static let shared = SentenceEditService()

func editSentence(idx: Int, sentence: String, completion: @escaping (NetworkResult<Any>) -> ()) {
let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest"

let header: HTTPHeaders = [
"Content-Type":"application/json",
"token":token
]

let body: Parameters = [
"sentence" : sentence
]

let url = APIConstants.myURL + "/\(idx)"

Alamofire.request(url,
method: .put,
parameters: body,
encoding: JSONEncoding.default,
headers: header).responseData { response in
switch response.result {
case .success:
guard let statusCode = response.response?.statusCode else {
return
}
guard let data = response.value else {
return
}
completion(self.judgeSenteceEdit(status: statusCode, data: data))
case .failure(let err):
print(err)
completion(.networkFail)
}
}
}

private func judgeSenteceEdit(status: Int, data: Data) -> NetworkResult<Any> {

struct EditSentence: Codable {
var sentence: String
}

let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<EditSentence>.self, from: data) else {
return .pathErr
}
switch status {
case 200:
return .success(decodedData.data?.sentence)
case 400..<500:
return .requestErr(decodedData.message)
case 600:
return .serverErr
default:
return .networkFail
}
}

func deleteSentece(idx: Int, completion: @escaping (NetworkResult<Any>) ->()) {
let token: String = UserDefaults.standard.string(forKey: UserDefaultKeys.token.rawValue) ?? "guest"

let header: HTTPHeaders = [
"Content-Type":"application/json",
"token":token
]

let url = APIConstants.myURL + "/\(idx)"

Alamofire.request(url,
method: .delete,
parameters: nil,
encoding: JSONEncoding.default,
headers: header).responseData { response in
switch response.result {
case .success:
guard let statusCode = response.response?.statusCode else {
return
}
guard let data = response.value else {
return
}
completion(self.judgeSenteceDelete(status: statusCode, data: data))
case .failure(let err):
print(err)
completion(.networkFail)
}
}
}

private func judgeSenteceDelete(status: Int, data: Data) -> NetworkResult<Any> {

struct DeleteSentence: Codable {
var deleteSentenceIdx: String
}

let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<DeleteSentence>.self, from: data) else {
return .pathErr
}
switch status {
case 200:
return .success(decodedData.data?.deleteSentenceIdx)
case 400..<500:
return .requestErr(decodedData.message)
case 600:
return .serverErr
default:
return .networkFail
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"scale" : "1x",
"idiom" : "universal",
"filename" : "themeInfoBtnMore.png"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"scale" : "3x",
"idiom" : "universal",
"filename" : "[email protected]"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4e93292

Please sign in to comment.