vapor-community / ferno

Vapor Firebase Realtime database provider
MIT License
70 stars 11 forks source link

[WIP] Update to Vapor4 #6

Closed maximkrouk closed 1 year ago

maximkrouk commented 4 years ago

Not sure if the architecture I implemented actually fits Vapor4 enough, so I think some code review would be appreciated 🙂

Readme is related to my personal account and I'll fix it after the review, that's why this PR has WIP label

Steven4294 commented 4 years ago

any shot we could get this merged?

maximkrouk commented 4 years ago

If the code quality is approved, then I fix README and remove WIP mark.

jamesolrog commented 3 years ago

Hey! How are things going with this? I'm looking to start a project using Vapor 4 and I'd love to use this! Any update would be great 😎

maximkrouk commented 3 years ago

As far as I remember it is ready for use, but I wasn't sure if the architecture fits vapor 4. Now I don't have time to maintain or improve the project, but my fork still should probably work 🌚

jamesolrog commented 3 years ago

Haha okay thanks I'll give that a go!

I'm wanting to create a simple web app to communicate with a pre-existing Firebase DB and it would just save me a tonne of time so I'm keen to see if I can get it working 🤓

garymansted commented 3 years ago

@jamesolrog Did you get it to build?

jamesolrog commented 3 years ago

@garymansted I couldn't get @maximkrouk 's branch to work completely. I followed the updated instructions and, quickly looking at it, everything seems like it should work. However, when SPM resolves, I get a "product dependency 'Ferno' in package 'ferno' not found" error and I'm not certain of what is causing it.

My next step was to clone the repository and drag in the files locally (taking the package manager out of the equation) to see if I can get the code itself to work but haven't got round to it yet!

garymansted commented 3 years ago

Hi @jamesolrog thanx for your response. I tried the same thing as you and got the same error - hence my asking. I got it to work after using your wisdom and insight by 'taking the package manager out of the equation'. For anyone wanting to know the full process of how I got it to work this is what I did.

I cloned the repository and dragged the files in (making sure that they were in the right place in the file tree).

Screen Shot 2021-01-04 at 10 51 23 am

Then added the Ferno config to the apps configure.swift file

public func configure(_ app: Application) throws {

let fernoConfiguration = FernoConfiguration(
    basePath: "database-url",
    email: "service-account-email",
    privateKey: "private-key"
)

Tip: Be sure to include the https:// protocol in the basePath: "https://example1234.firebaseio.com"

Then I registered it: app.ferno.use(.default(fernoConfiguration))

My specific usage was just to post (update) some data to my Firebase:

struct BitcoinData: Content {
    var symbol: String
    var price: String
}
private func postResults(app: Application, symbol: String, price: String) {
      let request = Request(application: app, on: app.eventLoopGroup.next())
      let newPrice = BitcoinData(symbol: symbol, price: price)
      do {
          try app.ferno.update("bitcoinPrice", body: newPrice, on: request)
      }
      catch {
          print(error.localizedDescription)
      }
}

@maximkrouk Thanx for your work on this update! Hope this helps someone.

jamesolrog commented 3 years ago

@garymansted Cracking stuff Gary. I'm gunna follow your instructions this week so hopefully I'll be up and running too! Best of luck with your project 😎.

@maximkrouk just curious to whether there is a super easy fix for the error we have discussed?

Just seems like a very weird error considering the previous version's packages appear to work! I appreciate your time is really valuable so no worries if you can't take a look. 💪🏼

maximkrouk commented 3 years ago

@garymansted I couldn't get @maximkrouk 's branch to work completely. I followed the updated instructions and, quickly looking at it, everything seems like it should work. However, when SPM resolves, I get a "product dependency 'Ferno' in package 'ferno' not found" error and I'm not certain of what is causing it.

My next step was to clone the repository and drag in the files locally (taking the package manager out of the equation) to see if I can get the code itself to work but haven't got round to it yet!

Probably the name of the package is case-sensitive "Ferno", so you can edit it in target dependencies or specify a custom name in package dependencies with .package(name:url:from:) overload

jamesolrog commented 3 years ago

@maximkrouk ahhh sure. Thank you for getting back to me! 💙

I did try something like this but interestingly:

and

In the package dependencies:

.package(name: "Ferno", url: "https://github.com/maximkrouk/ferno.git", .branch("master"))

and in the package targets:

targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Leaf", package: "leaf"),
                .product(name: "Vapor", package: "vapor"),
                .product(name: "Ferno", package: "Ferno")
            ],
...

Hope this helps. @garymansted give the above a try and you should be able to remove those local files now! haha 😁