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

[Team-13] Delete 기능 구현 & 사용자 쿠키가 반영된 API 연결하고 화면 업데이트 #202

Open
wants to merge 7 commits into
base: team-13
Choose a base branch
from
17 changes: 14 additions & 3 deletions Client/iOS/TodoList/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

static let middleWare = CardDataMiddleWare {
DebugDataTask(api: Team13API())
static let dataTask = DataTask(api: Team13API())
static let middleWare = CardDataMiddleWare(persistenceProvider: BoardPersistenceProvider()) {
dataTask
}

func applicationDidFinishLaunching(_ application: UIApplication) {
// TODO:- 사용자 쿠키를 받아오지 못했을때 처리
Self.dataTask?.fetchUser(completionHandler: { result in
switch result {
case .success:
break
case .failure:
break
}
})
}
}

14 changes: 9 additions & 5 deletions Client/iOS/TodoList/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="U8l-VO-PVk">
<rect key="frame" x="0.0" y="0.0" width="256" height="638"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="256" id="Nxu-Is-f3p"/>
</constraints>
Expand All @@ -48,6 +49,7 @@
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fQh-7P-Cmq">
<rect key="frame" x="0.0" y="0.0" width="1194" height="74"/>
Expand Down Expand Up @@ -106,7 +108,8 @@
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="0SC-7T-nbF" customClass="TodoTableView" customModule="TodoList" customModuleProvider="target">
<rect key="frame" x="0.0" y="60" width="256" height="578"/>
<color key="backgroundColor" name="gray6"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Wbo-O3-mRX" userLabel="header view">
<rect key="frame" x="0.0" y="0.0" width="256" height="60"/>
Expand Down Expand Up @@ -152,6 +155,7 @@
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="dTh-RU-Ln0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="0SC-7T-nbF" firstAttribute="leading" secondItem="dTh-RU-Ln0" secondAttribute="leading" id="GRk-gx-EiQ"/>
<constraint firstItem="0SC-7T-nbF" firstAttribute="top" secondItem="Wbo-O3-mRX" secondAttribute="bottom" id="Rvh-cb-bxr"/>
Expand Down Expand Up @@ -179,9 +183,9 @@
<rect key="frame" x="0.0" y="0.0" width="256" height="638"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="cq0-cd-q25" customClass="TodoTableView" customModule="TodoList" customModuleProvider="target">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="cq0-cd-q25" customClass="TodoTableView" customModule="TodoList" customModuleProvider="target">
<rect key="frame" x="0.0" y="60" width="256" height="578"/>
<color key="backgroundColor" name="gray6"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Nbd-tq-n0l" userLabel="header view">
<rect key="frame" x="0.0" y="0.0" width="256" height="60"/>
Expand Down Expand Up @@ -254,7 +258,7 @@
<rect key="frame" x="0.0" y="0.0" width="256" height="638"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="QqX-tp-SRV" customClass="TodoTableView" customModule="TodoList" customModuleProvider="target">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="QqX-tp-SRV" customClass="TodoTableView" customModule="TodoList" customModuleProvider="target">
<rect key="frame" x="0.0" y="60" width="256" height="578"/>
<color key="backgroundColor" name="gray6"/>
</tableView>
Expand Down Expand Up @@ -329,7 +333,7 @@
<color red="0.74117647058823533" green="0.74117647058823533" blue="0.74117647058823533" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="gray6">
<color red="0.89800000000000002" green="0.89800000000000002" blue="0.89800000000000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.89800000190734863" green="0.89800000190734863" blue="0.89800000190734863" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
</document>
2 changes: 1 addition & 1 deletion Client/iOS/TodoList/Cells/TodoTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TodoTableViewCell: UITableViewCell {
roundedView.layer.masksToBounds = true
}

func applyTextAllLabels(data card: CardData) {
func applyTextAllLabels(data card: Card) {
setTitleLabelAttribute(card.title)
setContentLabelAttribute(card.contents)
}
Expand Down
20 changes: 5 additions & 15 deletions Client/iOS/TodoList/Cells/TodoTableViewCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6PF-11-PDT">
<rect key="frame" x="0.0" y="0.0" width="610" height="157"/>
<rect key="frame" x="0.0" y="0.0" width="610" height="173"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fD8-6j-jre">
<rect key="frame" x="16" y="16" width="578" height="19.5"/>
Expand All @@ -29,14 +29,14 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5NI-kI-vJu">
<rect key="frame" x="16" y="43.5" width="578" height="72.5"/>
<rect key="frame" x="16" y="43.5" width="578" height="88.5"/>
<string key="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="author by iOS" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tmL-b9-NNV">
<rect key="frame" x="16" y="124" width="578" height="17"/>
<rect key="frame" x="16" y="140" width="578" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="EKr-Gc-mh9"/>
</constraints>
Expand All @@ -59,24 +59,14 @@
<constraint firstItem="tmL-b9-NNV" firstAttribute="top" secondItem="5NI-kI-vJu" secondAttribute="bottom" constant="8" id="kBE-lZ-kC6"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ShY-pS-eQF">
<rect key="frame" x="0.0" y="157" width="610" height="16"/>
<color key="backgroundColor" name="gray6"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="vKt-UK-mFg"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" name="gray6"/>
<constraints>
<constraint firstItem="6PF-11-PDT" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="4o6-nw-Sbr"/>
<constraint firstItem="6PF-11-PDT" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="7Xj-Fg-35B"/>
<constraint firstAttribute="trailing" secondItem="6PF-11-PDT" secondAttribute="trailing" id="Gfe-gH-cRm"/>
<constraint firstItem="ShY-pS-eQF" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="ekz-Fy-hPr"/>
<constraint firstAttribute="trailing" secondItem="ShY-pS-eQF" secondAttribute="trailing" id="i3T-eM-hjm"/>
<constraint firstItem="ShY-pS-eQF" firstAttribute="top" secondItem="6PF-11-PDT" secondAttribute="bottom" id="oSc-ot-RDR"/>
<constraint firstAttribute="bottom" secondItem="ShY-pS-eQF" secondAttribute="bottom" id="t1S-2a-oHG"/>
<constraint firstAttribute="trailing" secondItem="6PF-11-PDT" secondAttribute="trailing" id="tIE-Ne-XTM"/>
<constraint firstAttribute="bottom" secondItem="6PF-11-PDT" secondAttribute="bottom" id="uOb-D3-UMQ"/>
<constraint firstItem="6PF-11-PDT" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="wbh-sY-64h"/>
</constraints>
</tableViewCellContentView>
Expand All @@ -94,7 +84,7 @@
<color red="0.74117647058823533" green="0.74117647058823533" blue="0.74117647058823533" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="gray6">
<color red="0.89800000000000002" green="0.89800000000000002" blue="0.89800000000000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.89800000190734863" green="0.89800000190734863" blue="0.89800000190734863" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
38 changes: 28 additions & 10 deletions Client/iOS/TodoList/DB/PersistenceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import CoreData

// MARK:- Cards
struct Card {
let cardId: Int
let cardTitle: String
let cardContent: String
let id: Int
let title: String
let contents: String
let boardName: String
}

Expand All @@ -16,22 +16,28 @@ enum BoardType: CustomStringConvertible {
case done

var description: String {
return "\(self)"
switch self {
case .todo:
return "TODO"
case .progress:
return "DOING"
case .done:
return "DONE"
default:
return ""
}
}
}

// MARK:- DataManager
protocol PersistenceProvider {
func insertCard(boardType: BoardType, id: Int, title: String, content: String)
func insertBoard(type: BoardType, cards: [Card])
func fetchAllCard(where boardType: BoardType) -> [Card]
}


class BoardPersistenceProvider: PersistenceProvider {
static var shared = BoardPersistenceProvider()

private init() {}

private lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Model")
container.loadPersistentStores { description, error in
Expand All @@ -50,12 +56,23 @@ class BoardPersistenceProvider: PersistenceProvider {
return NSEntityDescription.entity(forEntityName: "TaskBoard", in: context)
}

func insertBoard(type: BoardType, cards: [Card]) {
let fetchAllCard = fetchAllCard(where: type)
for card in cards {
if fetchAllCard.contains(where: { $0.id == card.id }) {
// TODO:- id 가 같지만 수정되어 필드값이 하나라도 다를 수 있다 -> 모든 필드가 같은지 비교 필요
continue
}
insertCard(boardType: type, id: card.id, title: card.title, content: card.contents)
}
}

func insertCard(boardType: BoardType, id: Int, title: String, content: String) {
guard let entity = entity else {
return
}
let object = NSManagedObject(entity: entity, insertInto: context)
object.setValue(boardType, forKey: "type")
object.setValue(boardType.description, forKey: "type")
object.setValue(id, forKey: "cardId")
object.setValue(content, forKey: "content")
object.setValue(title, forKey: "title")
Expand All @@ -66,7 +83,8 @@ class BoardPersistenceProvider: PersistenceProvider {
do {
let fetchResults = try context.fetch(TaskBoard.fetchRequest()) as! [TaskBoard]
let results = fetchResults
.map{ Card.init(cardId: Int($0.cardId), cardTitle: $0.title!, cardContent: $0.content!, boardName: $0.type!) }
.map{ Card(id: Int($0.cardId), title: $0.title!, contents: $0.content!, boardName: $0.type!) }

if boardType == .all {
return results
}
Expand Down
31 changes: 30 additions & 1 deletion Client/iOS/TodoList/Network/CardsFetchingDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ struct Team13API: ServerAPI {
let endpoint: String = "http://13.125.216.180:8080"
}

protocol APIService {
func fetchUser(completionHandler: @escaping (Result<String,DataTaskError>) -> Void)
func fetchAll<T: Codable>(dataType: T.Type, completionHandler: @escaping (Result<T,DataTaskError>) -> Void)
func requestDelete(parameter: Int, completionHandler: @escaping (Result<Int, DataTaskError>) -> Void)
}


class DataTask: SessionDataTask {
class DataTask: SessionDataTask, APIService {
private let encoder = JSONEncoder()
private let decoder = JSONDecoder()
private let api: ServerAPI
Expand Down Expand Up @@ -78,6 +84,29 @@ class DataTask: SessionDataTask {
}.resume()
}

func requestDelete(parameter: Int, completionHandler: @escaping (Result<Int, DataTaskError>) -> Void) {
guard var url = api.toURL(path: .all) else {
completionHandler(.failure(.invalidURL))
return
}

url.appendPathComponent("\(parameter)")
var request = URLRequest(url: url)
request.httpMethod = "DELETE"

self.session.dataTask(with: request) { data, response, error in
guard
let data = data,
let cardResponse = try? self.decoder.decode(CardAPIResponse.self, from: data)
else {
completionHandler(.failure(.notConnect))
return
}

completionHandler(.success(cardResponse.cardId))
}.resume()
}

private func makeRequestContainCookie(with url: URL) -> URLRequest? {
var request = URLRequest(url: url)
guard let baseUrl = api.toURL(path: .base),
Expand Down
23 changes: 23 additions & 0 deletions Client/iOS/TodoList/Network/CardsFetchingDebugDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ class DebugDataTask: SessionDataTask {
}.resume()
}

func requestDelete(parameter: Int, completionHandler: @escaping (Result<Int, DataTaskError>) -> Void) {
guard var url = api.toURL(path: .all) else {
completionHandler(.failure(.invalidURL))
return
}

url.appendPathComponent("\(parameter)")
var request = URLRequest(url: url)
request.httpMethod = "DELETE"

self.session.dataTask(with: request) { data, response, error in
guard
let data = data,
let cardResponse = try? self.decoder.decode(CardAPIResponse.self, from: data)
else {
completionHandler(.failure(.notConnect))
return
}

completionHandler(.success(cardResponse.cardId))
}
}

private func makeURLComponents(from string: String? = nil, using parameter: [String: String]? = nil) -> URLComponents? {

if let string = string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct CardAPIResponse: Codable {
var cardId: Int
}
2 changes: 1 addition & 1 deletion Client/iOS/TodoList/Network/ResourcesNetwork/CardMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ struct CardMap: Codable {
var cardMap: TodoList

struct TodoList: Codable {
var todo: [CardData]
var TODO: [CardData]
}
}
Loading