Skip to content

Commit

Permalink
refactor: add public into fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gulivero1773 committed Jun 13, 2024
1 parent 104e96d commit 65dc418
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
//

import Vapor
import ErrorMiddleware

public enum HostError: AbortError, DebuggableError {
public enum HostError: AppError {
case notAcceptable
case unauthorizedAccessAttempt(ipAddress: String)

Expand Down Expand Up @@ -55,7 +56,7 @@ public enum HostError: AbortError, DebuggableError {
}
}

var number: String {
public var number: String {
switch self {
case .notAcceptable:
return "0001"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
//

import Vapor
import ErrorMiddleware

/// A generic `AuthenticationError` data.
enum AuthenticationError: AbortError, DebuggableError {
public enum AuthenticationError: AppError {
/// The `AuthorizationError` not found bearer token
case missingAuthorizationHeader

case claimVerificationFailure

/// Http response status of error
var status: HTTPResponseStatus {
public var status: HTTPResponseStatus {
switch self {
case .missingAuthorizationHeader:
return .unauthorized
Expand All @@ -43,7 +44,7 @@ enum AuthenticationError: AbortError, DebuggableError {
}

/// Reason of error
var reason: String {
public var reason: String {
switch self {
case .missingAuthorizationHeader:
return "Missing authorization header"
Expand All @@ -54,7 +55,7 @@ enum AuthenticationError: AbortError, DebuggableError {
}

/// Identifier of error
var identifier: String {
public var identifier: String {
switch self {
case .missingAuthorizationHeader:
return "missing_authorization_header"
Expand All @@ -64,7 +65,7 @@ enum AuthenticationError: AbortError, DebuggableError {
}
}

var number: String {
public var number: String {
switch self {
case .missingAuthorizationHeader:
return "0001"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ extension Application {
set { storage[MongoClusterKey.self] = newValue }
}

/*
/// For example setup mongo cluster need use method like this:
app.mongoCluster = try await MongoCluster(connectingTo: ConnectionSettings(connectionString))
*/
/// Initialize MongoCluster
/// - Parameter connectionString: URI as `String`. Example: "mongodb://localhost/myapp
public func initializeMongoCluster(connectionString: String) throws {
self.mongoCluster = try MongoCluster(lazyConnectingTo: ConnectionSettings(connectionString))
}
}

extension Application {
Expand All @@ -71,8 +72,9 @@ extension Application {
set { storage[MongoDBKey.self] = newValue }
}

/*
/// For example setup mongo database need use method like this:
app.mongoDB = try await try MongoDatabase.lazyConnect(to: connectionString)
*/
/// Initialize MongoDB
/// - Parameter connectionString: URI as `String`. Example: "mongodb://localhost/myapp
public func initializeMongoDB(connectionString: String) throws {
self.mongoDB = try MongoDatabase.lazyConnect(to: connectionString)
}
}
2 changes: 1 addition & 1 deletion Services/MongoComponents/Sources/MongoComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct MongoComponents: MongoComponentsProtocol {
self.app = app
}

public func getConnection(by url: String) async -> MongoConnectionState {
public func checkConnection(by url: String) async -> MongoConnectionState {
let result = app.mongoCluster?.connectionState
app.logger.debug("Connect to mongo have result: \(String(describing: result))")
guard let result else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ import MongoClient

/// Groups func for get mongo components
public protocol MongoComponentsProtocol {
func getConnection(by url: String) async -> MongoConnectionState
func checkConnection(by url: String) async -> MongoConnectionState
}
2 changes: 1 addition & 1 deletion Tests/fs-componentsTests/Mock/MongoComponentsMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import MongoClient
@testable import MongoComponents

public struct MongoComponentsMock: MongoComponentsProtocol {
public func getConnection(by url: String) async -> MongoConnectionState {
public func checkConnection(by url: String) async -> MongoConnectionState {
MongoConnectionState.connecting
}
}

0 comments on commit 65dc418

Please sign in to comment.