refactor: rename services to controllers

This commit is contained in:
Derrick Hammer 2023-05-10 07:07:56 -04:00
parent 6ceefc11cf
commit 8f3af2084c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
package service
package controller
import (
"crypto/ed25519"
@ -14,7 +14,7 @@ import (
"reflect"
)
type AccountService struct {
type AccountController struct {
Ctx iris.Context
}
@ -64,7 +64,7 @@ func hashPassword(password string) (string, error) {
return string(hashedPassword), nil
}
func (a *AccountService) PostRegister() {
func (a *AccountController) PostRegister() {
var r RegisterRequest
if err := a.Ctx.ReadJSON(&r); err != nil {

View File

@ -1,4 +1,4 @@
package service
package controller
import (
"crypto/ed25519"
@ -22,7 +22,7 @@ func init() {
blocklist = jwt.NewBlocklist(1 * time.Hour)
}
type AuthService struct {
type AuthController struct {
Ctx iris.Context
}
@ -132,7 +132,7 @@ func generateAndSaveChallengeToken(accountID uint, maxAge time.Duration) (string
}
// PostLogin handles the POST /api/auth/login request to authenticate a user and return a JWT token.
func (a *AuthService) PostLogin() {
func (a *AuthController) PostLogin() {
var r LoginRequest
// Read the login request from the client.
@ -169,7 +169,7 @@ func (a *AuthService) PostLogin() {
}
// PostChallenge handles the POST /api/auth/pubkey/challenge request to generate a challenge for a user's public key.
func (a *AuthService) PostPubkeyChallenge() {
func (a *AuthController) PostPubkeyChallenge() {
var r LoginRequest
// Read the login request from the client.
@ -200,7 +200,7 @@ func (a *AuthService) PostPubkeyChallenge() {
}
// PostKeyLogin handles the POST /api/auth/pubkey/login request to authenticate a user using a public key challenge and return a JWT token.
func (a *AuthService) PostPubkeyLogin() {
func (a *AuthController) PostPubkeyLogin() {
var r PubkeyLoginRequest
// Read the key login request from the client.
@ -268,7 +268,7 @@ func (a *AuthService) PostPubkeyLogin() {
}
// PostLogout handles the POST /api/auth/logout request to invalidate a JWT token.
func (a *AuthService) PostLogout() {
func (a *AuthController) PostLogout() {
var r LogoutRequest
// Read the logout request from the client.

View File

@ -1,4 +1,4 @@
package service
package controller
import (
"bytes"
@ -16,7 +16,7 @@ import (
"lukechampine.com/blake3"
)
type FilesService struct {
type FilesController struct {
Ctx iris.Context
}
@ -33,7 +33,7 @@ func InitFiles() {
client.SetDisableWarn(true)
}
func (f *FilesService) PostUpload() {
func (f *FilesController) PostUpload() {
ctx := f.Ctx
file, meta, err := f.Ctx.FormFile("file")
@ -52,7 +52,7 @@ func (f *FilesService) PostUpload() {
hashBytes := blake3.Sum256(buf)
hashHex := hex.EncodeToString(hashBytes[:])
fileCid, err := cid.Encode(hashBytes, uint64(meta.Size))
fileCid, err := cid.EncodeFixed(hashBytes, uint64(meta.Size))
if internalError(ctx, err) {
return
@ -123,7 +123,7 @@ func (f *FilesService) PostUpload() {
ctx.JSON(&UploadResponse{Cid: fileCid})
}
func (f *FilesService) GetDownload() {
func (f *FilesController) GetDownload() {
ctx := f.Ctx
cidString := ctx.URLParam("cid")

View File

@ -3,10 +3,10 @@ package main
import (
"embed"
"git.lumeweb.com/LumeWeb/portal/config"
"git.lumeweb.com/LumeWeb/portal/controller"
"git.lumeweb.com/LumeWeb/portal/db"
_ "git.lumeweb.com/LumeWeb/portal/docs"
"git.lumeweb.com/LumeWeb/portal/renterd"
"git.lumeweb.com/LumeWeb/portal/service"
"git.lumeweb.com/LumeWeb/portal/validator"
"github.com/iris-contrib/swagger"
"github.com/iris-contrib/swagger/swaggerFiles"
@ -45,7 +45,7 @@ func main() {
renterd.Ready()
service.InitFiles()
controller.InitFiles()
// Create a new Iris app instance
app := iris.New()
@ -61,7 +61,7 @@ func main() {
api := app.Party("/api")
v1 := api.Party("/v1")
// Register the AccountService with the MVC framework and attach it to the "/api/account" path
// Register the AccountController with the MVC framework and attach it to the "/api/account" path
mvc.Configure(v1.Party("/account"), func(app *mvc.Application) {
app.Handle(new(service.AccountService))
})
@ -71,7 +71,7 @@ func main() {
})
mvc.Configure(v1.Party("/files"), func(app *mvc.Application) {
app.Handle(new(service.FilesService))
app.Handle(new(controller.FilesController))
})
swaggerConfig := swagger.Config{