mirror of
https://github.com/dashared/GDproject.git
synced 2024-11-29 02:54:30 +03:00
changed time on post. upd to new version of denis. channels and hashtags are left
This commit is contained in:
parent
78a2ade5f9
commit
fb5ea63b8d
@ -193,7 +193,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
|
||||
var indexOfPost = 0
|
||||
// MARK:- new post
|
||||
@objc func newPost(){
|
||||
Model.createAndPublish(string: textView.text!)
|
||||
Model.createAndPublish(body: [ Model.Attachments(markdown: textView!.text) ], tags: ["ПИ", "люблюСвоюРаботу", "работаРулит", "Шершаков"])
|
||||
// adding row to uiTableView after adding new post
|
||||
// myProtocol?.addPost(post: p)
|
||||
moveBackToParentVC()
|
||||
|
@ -33,7 +33,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
|
||||
var newPosts: [Model.Posts] = []
|
||||
|
||||
channel?.posts.forEach({ (post) in
|
||||
newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated))
|
||||
newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated, tags: post.tags))
|
||||
})
|
||||
|
||||
news.dataSourse = newPosts
|
||||
|
@ -88,8 +88,12 @@ class PostViewCell: UITableViewCell
|
||||
setUpInStackView(isFullVersoin)
|
||||
}
|
||||
|
||||
let hashtags = ["Программная инженерия", "ПИ", "НИУ ВШЭ", "Наука"]
|
||||
var hashtags = [String]()
|
||||
|
||||
func setUpInStackView(_ full : Bool){
|
||||
|
||||
hashtags = post!.tags
|
||||
|
||||
let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
|
||||
nameStackView.axis = .vertical
|
||||
contentView.addSubview(nameStackView)
|
||||
|
@ -39,15 +39,14 @@ class BasicInfoController: UIViewController, UITableViewDelegate, UITableViewDat
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
if indexPath.row == 0 {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: basicInfoCellId, for: indexPath) as! BasicInfoCell
|
||||
cell.fill(title: dataSourse[indexPath.section].title)
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
cell.textLabel?.text = dataSourse[indexPath.section].title
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
cell.selectionStyle = .none
|
||||
return cell
|
||||
} else {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: infoCellId, for: indexPath) as! InfoCell
|
||||
cell.fill(title: dataSourse[indexPath.section].sectionData[indexPath.row - 1])
|
||||
cell.selectionStyle = .none
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
||||
cell.textLabel?.text = dataSourse[indexPath.section].sectionData[indexPath.row - 1]
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class ProfileViewController: UIViewController
|
||||
var newPosts: [Model.Posts] = []
|
||||
|
||||
dataSourse?.forEach({ (post) in
|
||||
newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: user!, date: post.updated))
|
||||
newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: user!, date: post.updated, tags: post.tags))
|
||||
})
|
||||
|
||||
self.posts.dataSourse = newPosts
|
||||
|
@ -13,6 +13,7 @@ class Model{
|
||||
static let invalidTocken = 498
|
||||
private static var isValidTocken: ((Int)->())? = {
|
||||
responce in
|
||||
print("\(responce)")
|
||||
if responce == invalidTocken {
|
||||
DataStorage.standard.setIsLoggedIn(value: false, with: 0)
|
||||
}
|
||||
@ -22,12 +23,10 @@ class Model{
|
||||
|
||||
static let url = URL(string:"\(baseUrl)/authentication/login")!
|
||||
static let url1 = URL(string:"\(baseUrl)/posts/last")!
|
||||
static let urlForDrafts = URL(string:"\(baseUrl)/drafts/create")!
|
||||
static let urlForPublish = URL(string:"\(baseUrl)/drafts/publish")!
|
||||
static let urlForUpdate = URL(string:"\(baseUrl)/drafts/update")!
|
||||
static let urlForPostsForUser = URL(string:"\(baseUrl)/posts/forUser")!
|
||||
static let urlForUsers = URL(string:"\(baseUrl)/users")!
|
||||
static let createAndPublishURL = URL(string:"\(baseUrl)/posts/publish")!
|
||||
static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
|
||||
|
||||
|
||||
struct QueryPosts: Codable{
|
||||
@ -41,20 +40,23 @@ class Model{
|
||||
var id: Int
|
||||
var user: Model.Users?
|
||||
var updated: String
|
||||
var tags: [String]
|
||||
|
||||
init(body: [Attachments], authorId: Int, id: Int, date: String) {
|
||||
init(body: [Attachments], authorId: Int, id: Int, date: String,tags: [String]) {
|
||||
self.body = body
|
||||
self.authorId = authorId
|
||||
self.id = id
|
||||
self.updated = date
|
||||
self.tags = tags
|
||||
}
|
||||
|
||||
init(body: [Attachments], authorId: Int, id: Int, user: Model.Users, date: String) {
|
||||
init(body: [Attachments], authorId: Int, id: Int, user: Model.Users, date: String, tags: [String]) {
|
||||
self.body = body
|
||||
self.authorId = authorId
|
||||
self.id = id
|
||||
self.user = user
|
||||
self.updated = date
|
||||
self.tags = tags
|
||||
}
|
||||
|
||||
func convertDateFormatter() -> String
|
||||
@ -62,17 +64,33 @@ class Model{
|
||||
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
|
||||
dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
|
||||
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
||||
let date = dateFormatter.date(from: updated)
|
||||
|
||||
dateFormatter.dateFormat = "MMM d, yyyy HH:mm" ///this is what you want to convert format
|
||||
dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
|
||||
dateFormatter.timeZone = NSTimeZone.local
|
||||
let timeStamp = dateFormatter.string(from: date!)
|
||||
|
||||
return timeStamp
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatedPost: Codable {
|
||||
var body = [Attachments]()
|
||||
var tags = [String]()
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case body
|
||||
case tags
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(body, forKey: .body)
|
||||
try container.encode(tags, forKey: .tags)
|
||||
}
|
||||
}
|
||||
|
||||
struct Users: Codable{
|
||||
|
||||
var middleName: String
|
||||
@ -88,6 +106,15 @@ class Model{
|
||||
init(markdown: String) {
|
||||
self.markdown = markdown
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case markdown
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(markdown, forKey: .markdown)
|
||||
}
|
||||
}
|
||||
|
||||
static func authenticate(with id: Int, completion: @escaping ((Bool)->())) {
|
||||
@ -155,50 +182,17 @@ class Model{
|
||||
}
|
||||
}
|
||||
|
||||
static func createDraft(completion: @escaping ((Int)->())){
|
||||
let jsonString = "[{ \"markdown\": \"# This is a markdown title\nThis is body.\" }]"
|
||||
var request = URLRequest(url: urlForDrafts)
|
||||
|
||||
request.httpMethod = "POST"
|
||||
|
||||
// insert json data to the request
|
||||
request.httpBody = jsonString.data(using: .utf8)
|
||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
AF.request(request).responseJSON {
|
||||
(response) in
|
||||
|
||||
if response.response?.statusCode == 200 {
|
||||
print("success in creating draft")
|
||||
} else {
|
||||
print("\(response.response?.statusCode ?? 0)")
|
||||
}
|
||||
|
||||
//let decoder = JSONDecoder()
|
||||
guard let json = response.data else { return }
|
||||
|
||||
guard let id = String(data: json, encoding: String.Encoding.utf8) else {return}
|
||||
|
||||
print("with id \(id)")
|
||||
completion(Int(id) ?? 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static func createAndPublish(string: String){
|
||||
let jsonUpd = """
|
||||
[
|
||||
{
|
||||
"markdown": "\(string)"
|
||||
}
|
||||
]
|
||||
"""
|
||||
static func createAndPublish(body: [Attachments], tags: [String]){
|
||||
let jsonUpd = CreatedPost(body: body, tags: tags)
|
||||
|
||||
var request = URLRequest(url: createAndPublishURL)
|
||||
|
||||
request.httpMethod = "POST"
|
||||
|
||||
// insert json data to the request
|
||||
request.httpBody = jsonUpd.data(using: .utf8)
|
||||
request.httpBody = try? JSONEncoder().encode(jsonUpd)
|
||||
|
||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||
AF.request(request).response {
|
||||
(response) in
|
||||
@ -210,7 +204,7 @@ class Model{
|
||||
|
||||
static func getPostsForUser(with id: Int, completion: @escaping (([Posts])->())){
|
||||
let json = [
|
||||
"userId" : id,
|
||||
"request" : id,
|
||||
"limit": 10
|
||||
]
|
||||
|
||||
@ -271,4 +265,36 @@ class Model{
|
||||
completion(Model.idUser)
|
||||
}
|
||||
}
|
||||
|
||||
// get channel (with id): in responce -- PostQuery
|
||||
static func getChannels(with channelId: Int, completion: @escaping (([Posts])->())){
|
||||
let json = [
|
||||
"request" : channelId,
|
||||
"limit": 10
|
||||
]
|
||||
|
||||
let jsonData = try? JSONSerialization.data(withJSONObject: json)
|
||||
|
||||
var request = URLRequest(url: urlForPostsForUser)
|
||||
request.httpMethod = "POST"
|
||||
|
||||
// insert json data to the request
|
||||
request.httpBody = jsonData
|
||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
AF.request(request).responseJSON {
|
||||
(response) in
|
||||
|
||||
if response.response?.statusCode == 200 {
|
||||
print("success")
|
||||
}
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
guard let json = response.data else { return }
|
||||
|
||||
guard let newPost = try? decoder.decode(QueryPosts.self, from: json) else { return }
|
||||
|
||||
completion(newPost.posts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user