-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscribeQueryModel.swift
More file actions
368 lines (294 loc) · 13.4 KB
/
SubscribeQueryModel.swift
File metadata and controls
368 lines (294 loc) · 13.4 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//
// SubsListQueryModel.swift
// GAMBAS
//
// Created by Songhee Choi on 2020/09/18.
// Copyright © 2020 TJ. All rights reserved.
//
import Foundation
//프로토콜 ---
// 구독 리스트 테이블
protocol SubsListQueryModelProtocol: class{
func subsListItemDownloaded(items:NSArray)
}
// 콘텐츠 리스트 테이블
protocol ContentsListQueryModelProtocol: class{
func contentsListItemDownloaded(items:NSArray)
}
// 콘텐츠 뷰
protocol ContentsViewQueryModelProtocol: class{
func contentsViewItemDownloaded(items:NSArray)
}
// 댓글 리스트 테이블
protocol CommentListQueryModelProtocol: class{
func commentListItemDownloaded(items:NSArray)
}
//---------
// 구독리스트 테이블뷰
class SubsListQueryModel: NSObject{
var delegate: SubsListQueryModelProtocol!
var urlPath = "http://localhost:8080/gambas/subsListQuery.jsp"
func subsListdownloadItems(uSeqno: String?){
print("받은uSeqno", uSeqno!)
// urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
let urlAdd = "?uSeqno=\(String(uSeqno!))"
urlPath += urlAdd
let url: URL = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to download data")
}else{
print("SubsList Data is downloaded")
//parse JSON
self.parseJSON(data!)
}
}
task.resume()
}
func parseJSON(_ data: Data){
var jsonResult = NSArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSArray
}catch let error as NSError{
print("subsList",error)
}
var jsonElement = NSDictionary()
let locations = NSMutableArray()
for i in 0..<jsonResult.count{
jsonElement = jsonResult[i] as! NSDictionary
let query = SubscribeDBModel()
if let subsSeqno = jsonElement["subsSeqno"] as? String,
let subsRegistDate = jsonElement["subsRegistDate"] as? String,
let subsValidation = jsonElement["subsValidation"] as? String,
let uSeqno = jsonElement["uSeqno"] as? String,
let prdSeqno = jsonElement["prdSeqno"] as? String,
let term = jsonElement["term"] as? String,
let releaseDay = jsonElement["releaseDay"] as? String,
let prdTitle = jsonElement["prdTitle"] as? String,
let prdPrice = jsonElement["prdPrice"] as? String,
let prdImage = jsonElement["prdImage"] as? String,
let prdRegistDate = jsonElement["prdRegistDate"] as? String,
let cgSeqno = jsonElement["cgSeqno"] as? String,
let chSeqno = jsonElement["chSeqno"] as? String,
let chContext = jsonElement["chContext"] as? String,
let chNickname = jsonElement["chNickname"] as? String,
let chImage = jsonElement["chImage"] as? String,
let chValidation = jsonElement["chValidation"] as? String,
let createrUSeqno = jsonElement["createrUSeqno"] as? String,
let cgName = jsonElement["cgName"] as? String
{
query.subsSeqno = subsSeqno
query.subsRegistDate = subsRegistDate
query.subsValidation = subsValidation
query.uSeqno = uSeqno
query.prdSeqno = prdSeqno
query.term = term
query.releaseDay = releaseDay
query.prdTitle = prdTitle
query.prdPrice = prdPrice
query.prdImage = prdImage
query.prdRegistDate = prdRegistDate
query.cgSeqno = cgSeqno
query.chSeqno = chSeqno
query.chContext = chContext
query.chNickname = chNickname
query.chImage = chImage
query.chValidation = chValidation
query.createrUSeqno = createrUSeqno
query.cgName = cgName
}
// 배열에 넣어줌
locations.add(query)
}
// 프로토콜로 전달
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.subsListItemDownloaded(items: locations)
})
}
}//----
// 콘텐츠리스트 테이블뷰
class ContentsListQueryModel: NSObject{
var delegate: ContentsListQueryModelProtocol!
var urlPath = "http://localhost:8080/gambas/contentsListQuery.jsp"
func contentsListdownloadItems(prdSeqno: String?){
//print("받은prdSeqno", prdSeqno!)
// urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
let urlAdd = "?prdSeqno=\(String(prdSeqno!))"
urlPath += urlAdd
let url: URL = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to download data")
}else{
print("Contents List Data is downloaded")
//parse JSON
self.parseJSON(data!)
}
}
task.resume()
}
func parseJSON(_ data: Data){
var jsonResult = NSArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSArray
}catch let error as NSError{
print("contentslist",error)
}
var jsonElement = NSDictionary()
let locations = NSMutableArray()
for i in 0..<jsonResult.count{
jsonElement = jsonResult[i] as! NSDictionary // 제일 처음 중괄호 묶여있는 데이터 jsonResult[i]> 0번으로 들어와있고 > Dictionary로 바꿔주고
let query = SubscribeDBModel()
if let ctSeqno = jsonElement["ctSeqno"] as? String,
let ctTitle = jsonElement["ctTitle"] as? String,
let ctContext = jsonElement["ctContext"] as? String,
let ctfile = jsonElement["ctfile"] as? String,
let ctRegistDate = jsonElement["ctRegistDate"] as? String,
let ctValidation = jsonElement["ctValidation"] as? String,
let prdSeqno = jsonElement["prdSeqno"] as? String,
let ctReleaseDate = jsonElement["ctReleaseDate"] as? String
{
query.ctSeqno = ctSeqno
query.ctTitle = ctTitle
query.ctContext = ctContext
query.ctfile = ctfile
query.ctRegistDate = ctRegistDate
query.ctValidation = ctValidation
query.prdSeqno = prdSeqno
query.ctReleaseDate = ctReleaseDate
}
// 배열에 넣어줌
locations.add(query)
}
// 프로토콜로 전달
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.contentsListItemDownloaded(items: locations)
})
}
}//----
// 콘텐츠뷰 get = ctSeqno
class ContentsViewQueryModel: NSObject{
var delegate: ContentsViewQueryModelProtocol!
var urlPath = "http://localhost:8080/gambas/contentsViewQuery.jsp"
func contentsViewdownloadItems(ctSeqno: String?, uSeqno: String?){
//print("받은ctSeqno", ctSeqno!, "받은 uSeqno", uSeqno!)
// urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
let urlAdd = "?ctSeqno=\(String(ctSeqno!))&uSeqno=\(String(uSeqno!))"
urlPath += urlAdd
let url: URL = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to download data")
}else{
print("ContentsView Data is downloaded")
//parse JSON
self.parseJSON(data!)
}
}
task.resume()
}
func parseJSON(_ data: Data){
var jsonResult = NSArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSArray
}catch let error as NSError{
print("contentsView parse error",error)
}
var jsonElement = NSDictionary()
let locations = NSMutableArray()
for i in 0..<jsonResult.count{
jsonElement = jsonResult[i] as! NSDictionary
let query = SubscribeDBModel()
if let ctSeqno = jsonElement["ctSeqno"] as? String,
let ctTitle = jsonElement["ctTitle"] as? String,
let ctContext = jsonElement["ctContext"] as? String,
let ctfile = jsonElement["ctfile"] as? String,
let ctRegistDate = jsonElement["ctRegistDate"] as? String,
let ctValidation = jsonElement["ctValidation"] as? String,
let prdSeqno = jsonElement["prdSeqno"] as? String,
let ctReleaseDate = jsonElement["ctReleaseDate"] as? String,
let countlikecontents = jsonElement["countlikecontents"] as? String,
let checkmylikecontents = jsonElement["checkmylikecontents"] as? String
{
query.ctSeqno = ctSeqno
query.ctTitle = ctTitle
query.ctContext = ctContext
query.ctfile = ctfile
query.ctRegistDate = ctRegistDate
query.ctValidation = ctValidation
query.prdSeqno = prdSeqno
query.ctReleaseDate = ctReleaseDate
query.countlikecontents = countlikecontents
query.checkmylikecontents = checkmylikecontents
}
// 배열에 넣어줌
locations.add(query)
}
// 프로토콜로 전달
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.contentsViewItemDownloaded(items: locations)
})
}
}//----
// 콘텐츠뷰 - 댓글 리스트 get = ctSeqno
class CommentListQueryModel: NSObject{
var delegate: CommentListQueryModelProtocol!
var urlPath = "http://localhost:8080/gambas/commentListQuery.jsp" //
func commentListdownloadItems(ctSeqno: String?){
//print("받은ctSeqno", ctSeqno!)
// urlPath 뒤에 ? 물음표 부터 뒤에 넣을 것 세팅
let urlAdd = "?ctSeqno=\(String(ctSeqno!))"
urlPath += urlAdd
let url: URL = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
let task = defaultSession.dataTask(with: url){(data, response, error) in
if error != nil { // 에러코드가 없을 때 실행
print("Failed to download data")
}else{
print("CommentList Data is downloaded")
//parse JSON
self.parseJSON(data!)
}
}
task.resume()
}
func parseJSON(_ data: Data){
var jsonResult = NSArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSArray
}catch let error as NSError{
print("comment list parse error",error)
}
var jsonElement = NSDictionary()
let locations = NSMutableArray()
for i in 0..<jsonResult.count{
jsonElement = jsonResult[i] as! NSDictionary
let query = SubscribeDBModel()
if let cmSeqno = jsonElement["cmSeqno"] as? String,
let cmcontext = jsonElement["cmcontext"] as? String,
let cmRegistDate = jsonElement["cmRegistDate"] as? String,
let cmValidation = jsonElement["cmValidation"] as? String,
let ctSeqno = jsonElement["ctSeqno"] as? String,
let uSeqno = jsonElement["uSeqno"] as? String,
let uName = jsonElement["uName"] as? String
{
query.cmSeqno = cmSeqno
query.cmcontext = cmcontext
query.cmRegistDate = cmRegistDate
query.cmValidation = cmValidation
query.ctSeqno = ctSeqno
query.uSeqno = uSeqno
query.uName = uName
}
// 배열에 넣어줌
locations.add(query)
}
// 프로토콜로 전달
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.commentListItemDownloaded(items: locations)
})
}
}//----