-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLikeInsertUpdateModel.swift
More file actions
61 lines (45 loc) · 2.52 KB
/
LikeInsertUpdateModel.swift
File metadata and controls
61 lines (45 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// LikeInsertUpdateModel.swift
// GAMBAS
//
// Created by Songhee Choi on 2020/09/22.
// Copyright © 2020 TJ. All rights reserved.
//
import Foundation
class LikeInsertUpdateModel: NSObject{
var urlPathInsert = "http://localhost:8080/gambas/contentsLikeInsert.jsp"
func InsertItems(uSeqno: String, ctSeqno: String, prdSeqno: String){ // 매개변수 값으로 데이터 들어오고 리턴값 Bool로 받음
let urlAdd = "?uSeqno=\(uSeqno)&ctSeqno=\(ctSeqno)&prdSeqno=\(prdSeqno)" // urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
urlPathInsert += urlAdd
// 한글 url encoding: url 타입은 한글들어가면 에러나기 때문에 addingPercentEncoding 퍼센트 들어가는걸로 바꿔줘야 함
urlPathInsert = urlPathInsert.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let url: URL = URL(string: urlPathInsert)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to insert data")
}else{
print("Data is inserted")
}
}
task.resume()
}
// 좋아요 취소 : likeValidation = 0 으로 update
var urlPathUpdate = "http://localhost:8080/gambas/contentsLikeUpdate.jsp"
func UpdateItems(uSeqno: String, ctSeqno: String){ // 매개변수 값으로 데이터 들어오고 리턴값 Bool로 받음
let urlAdd = "?uSeqno=\(uSeqno)&ctSeqno=\(ctSeqno)" // urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
urlPathUpdate += urlAdd
// 한글 url encoding: url 타입은 한글들어가면 에러나기 때문에 addingPercentEncoding 퍼센트 들어가는걸로 바꿔줘야 함
urlPathUpdate = urlPathUpdate.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let url: URL = URL(string: urlPathUpdate)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to update data")
}else{
print("Data is updated")
}
}
task.resume()
}
}//----