@@ -13,9 +13,7 @@ class Model{
1313
1414 static let invalidTocken = 498
1515
16− private static var isValidTocken: ((Int)->())? = {
17− responce in
18− print("\(responce)")
16+ private static var isValidTocken: ((Int)->())? = { responce in
1917 if responce == invalidTocken {
2018 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
2119 }
@@ -24,15 +22,16 @@ class Model{
2422 private static let baseUrl = "https://valera-denis.herokuapp.com"
2523 static let decoder = JSONDecoder()
2624
27− static let url = URL(string:"\(baseUrl)/authentication/login")!
28− static let url1 = URL(string:"\(baseUrl)/posts/last")!
29− static let urlForPostsForUser = URL(string:"\(baseUrl)/posts/forUser")!
30− static let urlForUsers = URL(string:"\(baseUrl)/users")!
31− static let createAndPublishURL = URL(string:"\(baseUrl)/posts/publish")!
25+ static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
26+ static let postsLastURL = URL(string:"\(baseUrl)/posts/last")!
27+ static let postsForUserURL = URL(string:"\(baseUrl)/posts/forUser")!
28+ static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
29+ static let usersURL = URL(string:"\(baseUrl)/users")!
3230 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
3331 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
3432 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
3533 static let channelsCreateURL = URL(string: "\(baseUrl)/channels/create")!
34+ static let channelsDeleteURL = URL(string: "\(baseUrl)/channels/delete")!
3635
3736
3837 struct QueryPosts: Codable{
@@ -154,10 +153,9 @@ class Model{
154153 var container = encoder.container(keyedBy: CodingKeys.self)
155154 try container.encode(people, forKey: .people)
156155 try container.encode(name, forKey: .name)
157− // try container.encode(id, forKey: .id)
156+ try container.encode(id, forKey: .id)
158157 try container.encode(tags, forKey: .tags)
159158 }
160−
161159 }
162160
163161 static func authenticate(with id: Int, completion: @escaping ((Bool)->())) {
@@ -165,7 +163,7 @@ class Model{
165163 let json: [String:Any] = ["authenticationId" : id]
166164 let jsonData = try? JSONSerialization.data(withJSONObject: json)
167165
168− var request = URLRequest(url: url)
166+ var request = URLRequest(url: authenticationURL)
169167 request.httpMethod = "POST"
170168
171169 // insert json data to the request
@@ -201,7 +199,7 @@ class Model{
201199
202200 static func getLast(completion: @escaping (((users:[Int: Users], posts:[Posts]))->())){
203201 let jsonString = "30"
204− var request = URLRequest(url: url1)
202+ var request = URLRequest(url: postsLastURL)
205203
206204 request.httpMethod = "POST"
207205
@@ -227,7 +225,7 @@ class Model{
227225
228226 static func createAndPublish(body: [Attachments], tags: [String]){
229227 let jsonUpd = CreatedPost(body: body, tags: tags)
230− var request = URLRequest(url: createAndPublishURL)
228+ var request = URLRequest(url: postsPublishURL)
231229
232230 request.httpMethod = "POST"
233231
@@ -251,7 +249,7 @@ class Model{
251249
252250 let jsonData = try? JSONSerialization.data(withJSONObject: json)
253251
254− var request = URLRequest(url: urlForPostsForUser)
252+ var request = URLRequest(url: postsForUserURL)
255253 request.httpMethod = "POST"
256254
257255 // insert json data to the request
@@ -276,7 +274,7 @@ class Model{
276274 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
277275 let json = "\(Set(ids))"
278276 print(json)
279− var request = URLRequest(url: urlForUsers)
277+ var request = URLRequest(url: usersURL)
280278
281279 request.httpMethod = "POST"
282280
@@ -364,4 +362,31 @@ class Model{
364362 completion(channelsList)
365363 }
366364 }
365+
366+ static func channelsDelete(by id: Int, completion: @escaping(()->())){
367+ var request = URLRequest(url: channelsDeleteURL)
368+ request.httpMethod = "POST"
369+ request.httpBody = "\(id)".data(using: .utf8)
370+ print("\(id)")
371+ request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
372+
373+ AF.request(request).response { (response) in
374+ isValidTocken?(response.response?.statusCode ?? 498)
375+ }
376+ completion()
377+ }
378+
379+ static func updateChannel(with channel: Channels) {
380+
381+ var request = URLRequest(url: channelsUpdateURL)
382+ request.httpMethod = "POST"
383+ request.httpBody = try? JSONEncoder().encode(channel)
384+
385+ request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
386+ AF.request(request).response {
387+ (response) in
388+
389+ isValidTocken?(response.response?.statusCode ?? 498)
390+ }
391+ }
367392}