@@ -20,6 +20,7 @@ class Model{
20 static let urlForUpdate = URL(string:"\(baseUrl)/drafts/update")!
20 static let urlForUpdate = URL(string:"\(baseUrl)/drafts/update")!
21 static let urlForPostsForUser = URL(string:"\(baseUrl)/posts/forUser")!
21 static let urlForPostsForUser = URL(string:"\(baseUrl)/posts/forUser")!
22 static let urlForUsers = URL(string:"\(baseUrl)/users")!
22 static let urlForUsers = URL(string:"\(baseUrl)/users")!
23+ static let createAndPublishURL = URL(string:"\(baseUrl)/drafts/createAndPublish")!
24 struct Posts: Codable {
25 struct Posts: Codable {
25 var body: [Attachments]
26 var body: [Attachments]
@@ -148,46 +149,16 @@ class Model{
151− static var seeMe: Int = 0 {
157− static func publish(){
158− let jsonUpd = "\(seeMe)"
159− var request = URLRequest(url: urlForPublish)
161− request.httpMethod = "POST"
163− // insert json data to the request
164− request.httpBody = jsonUpd.data(using: .utf8)
165− request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
166− AF.request(request).response {
169− if response.response?.statusCode == 204 {
170− print("successfuly published \(jsonUpd)")
175− static func update(post: Posts){
153+ static func createAndPublish(string: String){
176− let transformed = post.body.reduce("") { (res, att) -> String in
180 let jsonUpd = """
154 let jsonUpd = """
184− "markdown": "\(transformed)"
157+ "markdown": "\(string)"
190− var request = URLRequest(url: urlForUpdate)
161+ var request = URLRequest(url: createAndPublishURL)
192 request.httpMethod = "POST"
163 request.httpMethod = "POST"
@@ -198,10 +169,9 @@ class Model{
198 (response) in
169 (response) in
200 if response.response?.statusCode == 204 {
171 if response.response?.statusCode == 204 {
201− print("successfuly updated \(post.id) with \(jsonUpd)")
172+ print("post created")
204− print(response.response?.statusCode)
174+ print("failure in creating and publishing post")