Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions Secretly.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

84 changes: 79 additions & 5 deletions Secretly/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,78 @@
</objects>
<point key="canvasLocation" x="1167" y="879"/>
</scene>
<!--Coments-->
<scene sceneID="bCN-YU-Hqg">
<objects>
<viewController id="rYd-VY-Amq" customClass="CommentViewController" customModule="Secretly" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="1Jl-TL-Dct">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="6tF-IE-59E">
<rect key="frame" x="0.0" y="56" width="414" height="659"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="commentCell" id="9AL-Q2-X1e" customClass="CommentViewCellTableViewCell" customModule="Secretly" customModuleProvider="target">
<rect key="frame" x="0.0" y="24.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="9AL-Q2-X1e" id="jaU-hX-fhe">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
</tableView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yPh-70-Wox">
<rect key="frame" x="0.0" y="715" width="414" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="SHt-nC-z6h"/>
</constraints>
<items>
<barButtonItem style="plain" id="0eC-01-C4N">
<textField key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" id="I7T-p3-Pmt">
<rect key="frame" x="20" y="5" width="340" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</barButtonItem>
<barButtonItem style="plain" systemItem="flexibleSpace" id="qNd-Ma-rau"/>
<barButtonItem title="Item" image="paperplane.fill" catalog="system" id="RYt-JI-uy0">
<connections>
<action selector="didTapSendComment:" destination="rYd-VY-Amq" id="XX6-sR-WiJ"/>
</connections>
</barButtonItem>
</items>
</toolbar>
</subviews>
<viewLayoutGuide key="safeArea" id="23m-FA-dN8"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="6tF-IE-59E" firstAttribute="trailing" secondItem="23m-FA-dN8" secondAttribute="trailing" id="2po-jX-CNI"/>
<constraint firstItem="yPh-70-Wox" firstAttribute="top" secondItem="6tF-IE-59E" secondAttribute="bottom" id="4Fg-ci-zza"/>
<constraint firstItem="6tF-IE-59E" firstAttribute="leading" secondItem="23m-FA-dN8" secondAttribute="leading" id="9Yn-0a-PAP"/>
<constraint firstItem="yPh-70-Wox" firstAttribute="top" secondItem="6tF-IE-59E" secondAttribute="bottom" id="JkJ-Nf-5w5"/>
<constraint firstItem="6tF-IE-59E" firstAttribute="trailing" secondItem="23m-FA-dN8" secondAttribute="trailing" id="KFJ-EQ-QJt"/>
<constraint firstItem="yPh-70-Wox" firstAttribute="bottom" secondItem="23m-FA-dN8" secondAttribute="bottom" id="MWE-83-vdc"/>
<constraint firstItem="6tF-IE-59E" firstAttribute="top" secondItem="23m-FA-dN8" secondAttribute="top" id="O2r-he-2Du"/>
<constraint firstItem="6tF-IE-59E" firstAttribute="leading" secondItem="23m-FA-dN8" secondAttribute="leading" id="Qna-Yi-IB2"/>
<constraint firstItem="yPh-70-Wox" firstAttribute="leading" secondItem="23m-FA-dN8" secondAttribute="leading" id="UbZ-nC-S6a"/>
<constraint firstItem="6tF-IE-59E" firstAttribute="top" secondItem="23m-FA-dN8" secondAttribute="top" id="awN-uA-zKK"/>
<constraint firstItem="yPh-70-Wox" firstAttribute="trailing" secondItem="23m-FA-dN8" secondAttribute="trailing" id="x33-xq-Hgy"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Coments" id="aZp-eN-gGN"/>
<connections>
<outlet property="CommentToolBar" destination="yPh-70-Wox" id="b5P-k1-6XU"/>
<outlet property="commentTextField" destination="I7T-p3-Pmt" id="2zx-LR-aNC"/>
<outlet property="tableView" destination="6tF-IE-59E" id="Tvj-KL-FVX"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OER-c9-FZp" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3847.826086956522" y="135.9375"/>
</scene>
<!--Feed-->
<scene sceneID="gKD-R1-dE4">
<objects>
Expand All @@ -87,7 +159,7 @@
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="feedPostCell" id="ONf-lQ-zoe">
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="feedPostCell" id="ONf-lQ-zoe" customClass="PostCollectionViewCell" customModule="Secretly" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="dLf-VO-Qyo">
Expand All @@ -101,10 +173,10 @@
<viewLayoutGuide key="safeArea" id="7sz-vS-vke"/>
<color key="backgroundColor" systemColor="tertiarySystemBackgroundColor"/>
<constraints>
<constraint firstItem="TPK-s3-R7J" firstAttribute="top" secondItem="7sz-vS-vke" secondAttribute="top" id="Gf0-mf-0D7"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="leading" secondItem="7sz-vS-vke" secondAttribute="leading" id="MHQ-c2-o06"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="trailing" secondItem="7sz-vS-vke" secondAttribute="trailing" id="edX-Kb-hLW"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="bottom" secondItem="7sz-vS-vke" secondAttribute="bottom" id="jKr-7I-p9N"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="leading" secondItem="7sz-vS-vke" secondAttribute="leading" id="Gpz-cl-qPp"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="bottom" secondItem="7sz-vS-vke" secondAttribute="bottom" id="LMv-Ma-wKt"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="top" secondItem="7sz-vS-vke" secondAttribute="top" id="Mzo-hu-tTa"/>
<constraint firstItem="TPK-s3-R7J" firstAttribute="trailing" secondItem="7sz-vS-vke" secondAttribute="trailing" id="ysy-Me-1Kw"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Feed" id="tAD-Oa-Yyq">
Expand All @@ -121,6 +193,7 @@
</navigationItem>
<connections>
<outlet property="collectionView" destination="TPK-s3-R7J" id="EFZ-ci-ff1"/>
<segue destination="rYd-VY-Amq" kind="show" identifier="commentSegue" id="mno-0M-0CG"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="svI-0p-kLa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -170,6 +243,7 @@
</scenes>
<resources>
<image name="logo-white" width="256" height="256"/>
<image name="paperplane.fill" catalog="system" width="128" height="118"/>
<image name="person.fill" catalog="system" width="128" height="120"/>
<image name="plus" catalog="system" width="128" height="113"/>
<image name="text.bubble.fill" catalog="system" width="128" height="110"/>
Expand Down
9 changes: 9 additions & 0 deletions Secretly/Extensions/ActivityIndicator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// ActivityIndicator.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-03.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import Foundation
12 changes: 6 additions & 6 deletions Secretly/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>To add some context to your posts </string>
<key>NSCameraUsageDescription</key>
<string>To add some context to your posts</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>To georeference posts within a region </string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand All @@ -26,6 +20,12 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>To add some context to your posts</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>To georeference posts within a region </string>
<key>NSPhotoLibraryUsageDescription</key>
<string>To add some context to your posts </string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
30 changes: 30 additions & 0 deletions Secretly/Models/Comment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Comment.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-02.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import UIKit

struct Comment: Restable{
var id: Int?
var autor:User?
var createdAt:Date?
var uptadedAt:Date?
var content:String
// autor: User? = nil, createdAt: Date? = nil, uptadedAt: Date? = nil
init(content: String){
self.id = nil
self.autor = nil
self.createdAt = nil
self.uptadedAt = nil
self.content = content
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(content, forKey: .content)
}
}
26 changes: 26 additions & 0 deletions Secretly/Models/Like.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Like.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-11.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import Foundation

struct Like: Restable {
let id: Int?
let createdAt: Date?
let updatedAt: Date?

init(){
self.id = nil
self.createdAt = nil
self.updatedAt = nil
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
}
}
7 changes: 6 additions & 1 deletion Secretly/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ struct Post: Restable {
let latitude: Double?
let longitude: Double?
let createdAt: Date?
let updatedAt: Date?
var updatedAt: Date?
var liked: Bool
var numLikes: Int?

init(content: String, backgroundColor: String, latitude: Double? = nil, longitude: Double? = nil, image: UIImage? = nil) {
self.content = content
Expand All @@ -34,6 +36,9 @@ struct Post: Restable {
self.commentsCount = nil
self.createdAt = nil
self.updatedAt = nil
self.liked = false
self.numLikes = 0

}

func encode(to encoder: Encoder) throws {
Expand Down
74 changes: 74 additions & 0 deletions Secretly/Services/CommentService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// CommentService.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-02.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import Foundation

struct CommentService {
private var endpoint: RestClient<Comment>
private var post: Post?

init(post: Post) {
endpoint = RestClient<Comment>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(post.id ?? 1)/comments")
self.post = post
}

func create(_ model: Comment, complete: @escaping (Result<Comment?, Error>) -> Void ) {
try? endpoint.create(model: model) { result in
DispatchQueue.main.async { complete(result) }
}
}

func delete(_ model: Comment, complete: @escaping (Result<Comment?, Error>) -> Void ) {
let deleteEndpoint = RestClient<Comment>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(post?.id ?? 1)/comments/\(model.id ?? -1)")
print(deleteEndpoint.path)
deleteEndpoint.delete(model: model, complete: { result in
DispatchQueue.main.async {
complete(result)
}
})
}

func update(_ model: Comment, complete: @escaping (Result<Comment?, Error>) -> Void ) {
let updateEndpoint = RestClient<Comment>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(post?.id ?? 1)/comments/\(model.id ?? -1)")
print(updateEndpoint.path)

try? updateEndpoint.update(model: model){ result in
DispatchQueue.main.async {
complete(result)
}
}
}


func load(completion: @escaping ([Comment]) -> Void) {
endpoint.list { result in
guard let posts = try? result.get() else { return }
DispatchQueue.main.async { completion(posts) }
}
}

static func count(post:Post,completion: @escaping ([Comment]) -> Void){
let endPoint = RestClient<Comment>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(post.id ?? 1)/comments")
endPoint.list { result in
guard let posts = try? result.get() else { return }
DispatchQueue.main.async {
completion(posts)
}
}
}

static func countByID(id:Int,completion: @escaping ([Comment]) -> Void){
let endPoint = RestClient<Comment>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(id)/comments")
endPoint.list { result in
guard let posts = try? result.get() else { return }
DispatchQueue.main.async {
completion(posts)
}
}
}
}
30 changes: 30 additions & 0 deletions Secretly/Services/LikeService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// LikeService.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-11.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import UIKit

struct LikeService {
private var endpoint: RestClient<Like>

init(post: Post) {
self.endpoint = RestClient<Like>(client: AmacaConfig.shared.httpClient, path: "/api/v1/posts/\(post.id ?? 1)/likes")
}

func create(_ model: Like, complete: @escaping (Result<Like?, Error>) -> Void ) {
try? endpoint.create(model: model) { result in
DispatchQueue.main.async { complete(result) }
}
}

func delete(_ model: Like, complete: @escaping (Result<Like?, Error>) -> Void) {
endpoint.delete(model: model) { result in
DispatchQueue.main.async { complete(result) }
}
}

}
58 changes: 58 additions & 0 deletions Secretly/ViewControllers/CommentView+UISwipeGestures.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// CommentView+UISwipeGestures.swift
// Secretly
//
// Created by Samuel Arturo Garrido Sánchez on 2021-07-09.
// Copyright © 2021 3zcurdia. All rights reserved.
//

import UIKit

extension CommentViewController{

func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let editAction = UIContextualAction(style: .normal, title: "Editar") { [unowned self] (action, view, completion) in

let cell = tableView.cellForRow(at: indexPath) as? CommentViewCellTableViewCell

isEditingComment = true
commentEditing = cell?.comment

tableView.selectRow(at: indexPath, animated: true, scrollPosition: .top)
commentTextField.becomeFirstResponder()
commentTextField.text = cell?.comment?.content
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
completion(isEditingComment)
}
editAction.backgroundColor = .systemYellow
return UISwipeActionsConfiguration(actions: [editAction])
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [unowned self](action, view, completion) in

let cell = tableView.cellForRow(at: indexPath) as? CommentViewCellTableViewCell
if let unwrapComment = cell?.comment{
print(unwrapComment)
self.commentService?.delete(unwrapComment, complete: { [unowned self] result in
switch result {
case .success(let comment):
self.showAlert(title: "Comentario Eliminado", message: "\(comment?.id ?? 0)")
tableView.beginUpdates()
self.comments?.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .none)
tableView.endUpdates()
completion(true)
case .failure(let err):
self.errorAlert(err)
completion(false)
}
})
}
completion(true)
}
deleteAction.backgroundColor = .red
return UISwipeActionsConfiguration(actions: [deleteAction])
}
}
Loading