git.iko.soy/dashared/GDproject
on master help sign in
added new API method for publishing posts. added icons on tab bar. some slight modifications
8d28882Darya Rednikina
GDproject/Base.lproj/Main.storyboard+6−2
@@ -414,7 +414,7 @@
414 <scene sceneID="RSd-UJ-34B">
414 <scene sceneID="RSd-UJ-34B">
415 <objects>
415 <objects>
416 <navigationController storyboardIdentifier="navChannels" automaticallyAdjustsScrollViewInsets="NO" id="NuV-ZG-ld2" sceneMemberID="viewController">
416 <navigationController storyboardIdentifier="navChannels" automaticallyAdjustsScrollViewInsets="NO" id="NuV-ZG-ld2" sceneMemberID="viewController">
417− <tabBarItem key="tabBarItem" title="Posts" id="dH2-sL-YsR"/>
417+ <tabBarItem key="tabBarItem" title="Posts" image="5" selectedImage="5" id="dH2-sL-YsR"/>
418 <toolbarItems/>
418 <toolbarItems/>
419 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="6qB-3A-tuL">
419 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="6qB-3A-tuL">
420 <rect key="frame" x="0.0" y="20" width="375" height="96"/>
420 <rect key="frame" x="0.0" y="20" width="375" height="96"/>
@@ -453,7 +453,7 @@
453 <scene sceneID="dJj-Hp-Wa9">
453 <scene sceneID="dJj-Hp-Wa9">
454 <objects>
454 <objects>
455 <navigationController storyboardIdentifier="navPosts" automaticallyAdjustsScrollViewInsets="NO" id="tae-5q-wvT" sceneMemberID="viewController">
455 <navigationController storyboardIdentifier="navPosts" automaticallyAdjustsScrollViewInsets="NO" id="tae-5q-wvT" sceneMemberID="viewController">
456− <tabBarItem key="tabBarItem" title="Profile" id="lYy-LQ-AcR"/>
456+ <tabBarItem key="tabBarItem" title="Profile" image="1" selectedImage="1" id="lYy-LQ-AcR"/>
457 <toolbarItems/>
457 <toolbarItems/>
458 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="q3a-ph-c8V">
458 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="q3a-ph-c8V">
459 <rect key="frame" x="0.0" y="20" width="375" height="96"/>
459 <rect key="frame" x="0.0" y="20" width="375" height="96"/>
@@ -501,4 +501,8 @@
501 <point key="canvasLocation" x="-466" y="641"/>
501 <point key="canvasLocation" x="-466" y="641"/>
502 </scene>
502 </scene>
503 </scenes>
503 </scenes>
504+ <resources>
505+ <image name="1" width="30" height="30"/>
506+ <image name="5" width="30" height="30"/>
507+ </resources>
504</document>
508</document>
GDproject/Controller/ News and channels/NewPostViewController.swift+2−13
@@ -46,24 +46,13 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
46 override func viewDidLoad()
46 override func viewDidLoad()
47 {
47 {
48 super.viewDidLoad()
48 super.viewDidLoad()
49− Model.createDraft { [weak self] (int) in
50− self?.indexOfPost = int
51− }
52 //createTimerForUpdates()
49 //createTimerForUpdates()
53
50
54 setUpMD()
51 setUpMD()
55 setUpTextView()
52 setUpTextView()
56 setUpAccessoryView()
53 setUpAccessoryView()
57 }
54 }
58−
55+
59− func createTimerForUpdates(){
60− // timer for update
61− let t = RepeatingTimer(timeInterval: 15)
62− t.eventHandler = { [unowned self] in
63− Model.update(post: Model.Posts(body: [Model.Attachments(markdown: self.textView.text)], authorId: 42, id: self.indexOfPost))
64− }
65− t.resume()
66− }
67
56
68 override func viewWillAppear(_ animated: Bool) {
57 override func viewWillAppear(_ animated: Bool) {
69 super.viewWillAppear(animated)
58 super.viewWillAppear(animated)
@@ -204,7 +193,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
204 var indexOfPost = 0
193 var indexOfPost = 0
205 // MARK:- new post
194 // MARK:- new post
206 @objc func newPost(){
195 @objc func newPost(){
207− Model.update(post: Model.Posts(body: [Model.Attachments(markdown: textView.text)], authorId: 42, id: indexOfPost))
196+ Model.createAndPublish(string: textView.text!)
208 // adding row to uiTableView after adding new post
197 // adding row to uiTableView after adding new post
209 // myProtocol?.addPost(post: p)
198 // myProtocol?.addPost(post: p)
210 moveBackToParentVC()
199 moveBackToParentVC()
GDproject/Simple model/Model.swift+10−40
@@ -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")!
23
24
24 struct Posts: Codable {
25 struct Posts: Codable {
25 var body: [Attachments]
26 var body: [Attachments]
@@ -148,46 +149,16 @@ class Model{
148 }
149 }
149 }
150 }
150
151
151− static var seeMe: Int = 0 {
152− didSet{
153− publish()
154− }
155− }
156−
157− static func publish(){
158− let jsonUpd = "\(seeMe)"
159− var request = URLRequest(url: urlForPublish)
160−
161− request.httpMethod = "POST"
162−
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 {
167− (response) in
168−
169− if response.response?.statusCode == 204 {
170− print("successfuly published \(jsonUpd)")
171− }
172− }
173− }
174
152
175− static func update(post: Posts){
153+ static func createAndPublish(string: String){
176− let transformed = post.body.reduce("") { (res, att) -> String in
177− res + att.markdown
178− }
179−
180 let jsonUpd = """
154 let jsonUpd = """
181− {
155+ [
182− "body": [
183− {
156+ {
184− "markdown": "\(transformed)"
157+ "markdown": "\(string)"
185− }
158+ }
186− ],
159+ ]
187− "id": \(post.id)
188− }
189 """
160 """
190− var request = URLRequest(url: urlForUpdate)
161+ var request = URLRequest(url: createAndPublishURL)
191
162
192 request.httpMethod = "POST"
163 request.httpMethod = "POST"
193
164
@@ -198,10 +169,9 @@ class Model{
198 (response) in
169 (response) in
199
170
200 if response.response?.statusCode == 204 {
171 if response.response?.statusCode == 204 {
201− print("successfuly updated \(post.id) with \(jsonUpd)")
172+ print("post created")
202− seeMe = post.id
203 } else {
173 } else {
204− print(response.response?.statusCode)
174+ print("failure in creating and publishing post")
205 }
175 }
206 }
176 }
207 }
177 }
GDproject/Supporting files/Assets.xcassets/1.imageset/1.pdfnew file

Binary file not shown.

GDproject/Supporting files/Assets.xcassets/1.imageset/Contents.jsonnew file+25
@@ -0,0 +1,25 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "1.pdf",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ },
21+ "properties" : {
22+ "template-rendering-intent" : "template",
23+ "preserves-vector-representation" : true
24+ }
25+}
GDproject/Supporting files/Assets.xcassets/2.imageset/2.pdfnew file

Binary file not shown.

GDproject/Supporting files/Assets.xcassets/2.imageset/Contents.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "2.pdf",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ }
21+}
GDproject/Supporting files/Assets.xcassets/3.imageset/3.pdfnew file

Binary file not shown.

GDproject/Supporting files/Assets.xcassets/3.imageset/Contents.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "3.pdf",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ }
21+}
GDproject/Supporting files/Assets.xcassets/4.imageset/4.pdfnew file

Binary file not shown.

GDproject/Supporting files/Assets.xcassets/4.imageset/Contents.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "4.pdf",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ }
21+}
GDproject/Supporting files/Assets.xcassets/5.imageset/5.pdfnew file

Binary file not shown.

GDproject/Supporting files/Assets.xcassets/5.imageset/Contents.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "5.pdf",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ }
21+}
GDproject/Supporting files/Assets.xcassets/share.imageset/Contents.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "share.png",
6+ "scale" : "1x"
7+ },
8+ {
9+ "idiom" : "universal",
10+ "scale" : "2x"
11+ },
12+ {
13+ "idiom" : "universal",
14+ "scale" : "3x"
15+ }
16+ ],
17+ "info" : {
18+ "version" : 1,
19+ "author" : "xcode"
20+ }
21+}
GDproject/Supporting files/Assets.xcassets/share.imageset/share.pngnew file

Binary file not shown.