Skip to content

Commit afe29d2

Browse files
committed
Push Codes :)
1 parent b2773aa commit afe29d2

File tree

70 files changed

+3034
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3034
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Package.resolved

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version: 5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "LPGSharedModels",
8+
platforms: [
9+
.iOS(.v16),
10+
.macOS(.v12)
11+
],
12+
products: [
13+
// Products define the executables and libraries a package produces, and make them visible to other packages.
14+
.library(
15+
name: "LPGSharedModels",
16+
targets: ["LPGSharedModels"]),
17+
],
18+
dependencies: [
19+
.package(url: "https://github.com/pointfreeco/swift-url-routing.git", from: "0.5.0"),
20+
.package(url: "https://github.com/orlandos-nl/BSON.git", from: "8.0.9")
21+
],
22+
targets: [
23+
.target(
24+
name: "LPGSharedModels",
25+
dependencies: [
26+
.product(name: "URLRouting", package: "swift-url-routing"),
27+
.product(name: "BSON", package: "BSON")
28+
]
29+
),
30+
.testTarget(
31+
name: "LPGSharedModelsTests",
32+
dependencies: ["LPGSharedModels"]),
33+
]
34+
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Foundation
2+
3+
extension Encodable {
4+
public var jsonData: Data? {
5+
let encoder = JSONEncoder()
6+
encoder.dateEncodingStrategy = .iso8601
7+
do {
8+
return try encoder.encode(self)
9+
} catch {
10+
debugPrint("\(error)")
11+
return nil
12+
}
13+
}
14+
15+
public var jsonString: String? {
16+
guard let data = self.jsonData else { return nil }
17+
return String(data: data, encoding: .utf8)
18+
}
19+
}
20+
21+
22+
23+
extension Decodable {
24+
25+
static public func from(json: String, using encoding: String.Encoding = .utf8) -> Self? {
26+
guard let data = json.data(using: encoding) else { return nil }
27+
return Self.from(data: data)
28+
}
29+
30+
static public func from(data: Data) -> Self? {
31+
32+
do {
33+
return try JSONDecoder().decode(Self.self, from: data)
34+
} catch {
35+
debugPrint("\(error)")
36+
return nil
37+
}
38+
}
39+
40+
static public func decode(json: String, using usingForWebRtcingEncoding: String.Encoding = .utf8) -> Self? {
41+
guard let data = json.data(using: usingForWebRtcingEncoding) else { return nil }
42+
return Self.decode(data: data)
43+
}
44+
45+
static public func decode(data usingForWebRtcingData: Data) -> Self? {
46+
let decoder = JSONDecoder()
47+
decoder.dateDecodingStrategy = .iso8601
48+
49+
do {
50+
return try decoder.decode(Self.self, from: usingForWebRtcingData)
51+
} catch {
52+
debugPrint("\(error)")
53+
return nil
54+
}
55+
}
56+
}
57+
58+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Saroar Khandoker on 29.11.2020.
6+
//
7+
8+
import Foundation
9+
10+
public extension Data {
11+
func toHexString() -> String {
12+
return map { String(format: "%02.2hhx", $0) }.joined()
13+
}
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Saroar Khandoker on 12.10.2020.
6+
//
7+
8+
import Foundation
9+
10+
import Foundation
11+
12+
extension String: CodingKey {
13+
public var stringValue: String {
14+
return self
15+
}
16+
17+
public var intValue: Int? {
18+
return Int(self)
19+
}
20+
21+
public init?(intValue: Int) {
22+
self.init(intValue.description)
23+
}
24+
25+
public init?(stringValue: String) {
26+
self.init(stringValue)
27+
}
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Foundation
2+
3+
extension URL {
4+
static public var home: URL {
5+
return .init(string: "http://0.0.0.0:8080")!
6+
}
7+
8+
static public var empty: URL = .init(string: "")!
9+
}
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public struct LPGSharedModels {
2+
public private(set) var text = "Hello, World!"
3+
4+
public init() {}
5+
6+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
import Foundation
3+
import BSON
4+
5+
public enum AttachmentType: String, Codable {
6+
case file, image, audio, video
7+
}
8+
9+
public struct AttachmentInOutPut: Codable {
10+
11+
public var id: ObjectId?
12+
public var type: AttachmentType
13+
public var userId: ObjectId?
14+
public var swapId: ObjectId?
15+
public var conversationId: ObjectId?
16+
public var imageUrlString: String?
17+
public var audioUrlString: String?
18+
public var videoUrlString: String?
19+
public var fileUrlString: String?
20+
public var createdAt: Date?
21+
public var updatedAt: Date?
22+
public var deletedAt: Date?
23+
24+
public init(
25+
id: ObjectId? = nil,
26+
type: AttachmentType,
27+
userId: ObjectId? = nil,
28+
swapId: ObjectId? = nil,
29+
conversationId: ObjectId? = nil,
30+
imageUrlString: String? = nil,
31+
audioUrlString: String? = nil,
32+
videoUrlString: String? = nil,
33+
fileUrlString: String? = nil,
34+
createdAt: Date? = nil,
35+
updatedAt: Date? = nil,
36+
deletedAt: Date? = nil
37+
) {
38+
self.id = id
39+
self.type = type
40+
self.userId = userId
41+
self.swapId = swapId
42+
self.imageUrlString = imageUrlString
43+
self.audioUrlString = audioUrlString
44+
self.videoUrlString = videoUrlString
45+
self.fileUrlString = fileUrlString
46+
self.createdAt = createdAt
47+
self.updatedAt = updatedAt
48+
self.deletedAt = deletedAt
49+
}
50+
51+
}
52+
53+
extension AttachmentInOutPut: Identifiable {}
54+
55+
extension AttachmentInOutPut: Equatable {
56+
public static func < (lhs: AttachmentInOutPut, rhs: AttachmentInOutPut) -> Bool {
57+
guard let lhsDate = lhs.updatedAt, let rhsDate = rhs.createdAt else { return false }
58+
return lhsDate > rhsDate
59+
}
60+
}
61+
62+
extension AttachmentInOutPut: Hashable {}

0 commit comments

Comments
 (0)