Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Saroar Khandoker saroar

🏠
Working from home
View GitHub Profile
@saroar
saroar / MongoKittenPaginate.swift
Created Nov 24, 2020
You can use Fluent with MongodbKitten and get fluent like paginate
View MongoKittenPaginate.swift
private func readAll(_ req: Request) throws -> EventLoopFuture<EventPage> {
if req.loggedIn == false {
throw Abort(.unauthorized)
}
//{ coordinates: {$geoWithin: { $centerSphere: [ [ 30.205643177032474, 60.02979119847114 ], 0.008226198370569168 ]}}, $or: [] }
//db.event_places.find({"coordinates" : { $geoWithin : { $centerSphere : [[30.387906785397426, 60.01087797211564], 0.008226198370569168 ]}}}).limit(3) //.pretty()
// .aggregate([.geoNear(longitude: 30.387906785397426, latitude: 60.01087797211564, distanceField: "0.008226198370569168", spherical: false)])
View createContacts.swift
func create(_ req: Request) throws -> EventLoopFuture<[Contact.ReqRes]> {
if req.loggedIn == false { throw Abort(.unauthorized) }
let inputData = try req.content.decode([Contact.ReqRes].self)
return Contact.query(on: req.db).filter(\.$user.$id == req.payload.userId).all().flatMap { contactsRes in
let contacts = contactsRes.map { $0.response }
let setOriginal = Set(inputData)
let setServerContacts = Set(contacts)
@saroar
saroar / Contact.swift
Last active Nov 12, 2020
Save Contacts and get only register user with isRegister = user.phoneNumber == contact.phoneNumber
View Contact.swift
import Foundation
import Vapor
import Fluent
import FluentMongoDriver
public final class User: Model, Content, Hashable {
public static var schema = "users"
public init() {}
View ProfileView.swift
//
// ProfileView.swift
// AddaMeIOS
//
// Created by Saroar Khandoker on 04.09.2020.
//
import SwiftUI
struct ProfileView: View {
@saroar
saroar / ChatBottomView.swift
Last active Nov 10, 2020
SwiftUI Multiple line TextEditor
View ChatBottomView.swift
//
// ChatBottomView.swift
// AddaMeIOS
//
// Created by Saroar Khandoker on 05.09.2020.
//
import SwiftUI
struct ChatBottomView: View {
View FindUserConversations.swift
public final class User: Model, Content, Hashable {
public static var schema = "users"
public init() {}
public init(id: ObjectId? = nil ,phoneNumber: String) {
self.id = id
self.phoneNumber = phoneNumber
self.firstName = nil
@saroar
saroar / docker-compose.yml
Last active Nov 6, 2020
Common docker-compose
View docker-compose.yml
version: '3.7'
x-shared_environment: &shared_environment
LOG_LEVEL: ${LOG_LEVEL:-debug}
JWKS: '{}'
MONGO_DB_PRO: "mongodb://mongo:27017/addameapi"
EVENTS_URL: "http://realIP:9090"
CHATS_URL: "http://realIP:6060"
AUTH_URL: "http://realIP:3030"
TWILIO_ACCOUNT_ID: "id"
View WebsocketClients.swift
final class WebsocketClients {
let lock: Lock
var eventLoop: EventLoop
var allCliendts: [ObjectId: WebSocketClient]
let logger: Logger
func send(_ msg: Message.Item, req: Request) {
let chatClients = self.activeClients.compactMap { $0 as? ChatClient }
View BackGC.swift
var body: some View {
Group {
if !currenuser(chatMessageResponse.sender.id) {
HStack {
Group {
AsyncImage(
avatarLink: chatMessageResponse.sender.avatarUrl,
placeholder: Text("Loading ..."),
View SocketViewModel.swift
//
// SocketViewModel.swift
// AddaMeIOS
//
// Created by Saroar Khandoker on 20.10.2020.
//
import SwiftUI
import Combine
You can’t perform that action at this time.