Improved strings, CI & schedules base
Improved some strings, added the basics to prepare for integrating schedules again, and added basic Forgejo CI.
This commit is contained in:
parent
751c841fa2
commit
a3e044dec5
11 changed files with 79 additions and 11 deletions
1
.forgejo/workflows/build.yaml
Symbolic link
1
.forgejo/workflows/build.yaml
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../build/ci/build.yaml
|
7
.vscode/tasks.json
vendored
7
.vscode/tasks.json
vendored
|
@ -17,7 +17,7 @@
|
|||
{
|
||||
"label": "run project",
|
||||
"args": ["run", "./cmd/stbackend/main.go"],
|
||||
"group":"build",
|
||||
"group": "build",
|
||||
"options":{
|
||||
"env":{
|
||||
"DATABASE_URL": "test",
|
||||
|
@ -26,6 +26,11 @@
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "build project",
|
||||
"args": ["build", "-x", "-v", "-o=stbackend", "-buildvcs=true", "./cmd/stbackend/main.go"],
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "test",
|
||||
"args": ["test", "-v", "./..."],
|
||||
|
|
12
build/ci/build.yaml
Normal file
12
build/ci/build.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: build-artifact
|
||||
path: ./stbackend
|
43
internal/api/handlers/schedule_handler.go
Normal file
43
internal/api/handlers/schedule_handler.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
ScheduleTogether Backend
|
||||
Copyright (C) 2024, Zervó Zadachin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
|
||||
"git.zervo.org/scheduletogether/backend/internal/api/middlewares"
|
||||
perms "git.zervo.org/scheduletogether/backend/pkg/permissions"
|
||||
)
|
||||
|
||||
// ScheduleHandler_RegisterRoutes registers routes for the ScheduleHandler
|
||||
func ScheduleHandler_RegisterRoutes(party iris.Party) {
|
||||
party.Use(middlewares.Authenticate()) // only allow authenticated users for the following endpoints
|
||||
party.Post("/", middlewares.Authorize(perms.CreateSchedule))
|
||||
}
|
||||
|
||||
// ScheduleCreate_Handler handles the POST /schedules endpoint
|
||||
func ScheduleCreate_Handler(ctx iris.Context) {
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ func UsersGet_Service(ctx iris.Context) {
|
|||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.JSON(types.CommonErrorResponse{
|
||||
Error: "Failed to retrieve users from the database",
|
||||
Error: "Failed to retrieve users",
|
||||
})
|
||||
logboi.Warn("Failed to retrieve users from the database: " + err.Error())
|
||||
return
|
||||
|
|
|
@ -49,7 +49,7 @@ func UsersGetById_Service(ctx iris.Context) {
|
|||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.JSON(types.CommonErrorResponse{
|
||||
Error: "Failed to retrieve user from the database",
|
||||
Error: "Failed to retrieve user",
|
||||
})
|
||||
logboi.Warn("Failed to retrieve user from the database: " + err.Error())
|
||||
return
|
||||
|
|
|
@ -49,7 +49,7 @@ func UsersGetByUuid_Service(ctx iris.Context) {
|
|||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.JSON(types.CommonErrorResponse{
|
||||
Error: "Failed to retrieve user from the database",
|
||||
Error: "Failed to retrieve user",
|
||||
})
|
||||
logboi.Warn("Failed to retrieve user from the database: " + err.Error())
|
||||
return
|
||||
|
|
|
@ -44,12 +44,12 @@ func UsersGetSelf_Service(ctx iris.Context) {
|
|||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.JSON(types.CommonErrorResponse{
|
||||
Error: "Failed to retrieve user from the database",
|
||||
Error: "Failed to retrieve user",
|
||||
})
|
||||
logboi.Warn("Failed to retrieve user from the database: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Return users
|
||||
// Return user
|
||||
ctx.JSON(user)
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (l *Reporter) Fail(msg string) {
|
|||
// Finish wraps logboi.Info and announces end of a job
|
||||
func (l *Reporter) Finish() {
|
||||
logboi.Info("<" + l.workerName + "/" + l.jobName + "> " + "[ " + logging.Green + logging.Bold + "OK " + logging.Reset + " ]")
|
||||
logboi.Info("Job took \"" + l.jobName + "\" " + time.Since(l.startTime).String() + " to complete.")
|
||||
logboi.Info("Job \"" + l.jobName + "\" " + " took " + time.Since(l.startTime).String() + " to complete.")
|
||||
}
|
||||
|
||||
// Schedule workers with cron
|
||||
|
@ -71,7 +71,7 @@ func ScheduleWorkers() {
|
|||
|
||||
// Add functions / jobs
|
||||
c.AddFunc("@every 30m", workerFriends_PurgeAbandonedRequests)
|
||||
c.AddFunc("@every 30m", workerSchedules_PurgeAbandonedData)
|
||||
c.AddFunc("@every 60m", workerSchedules_PurgeAbandonedData)
|
||||
|
||||
c.Start()
|
||||
logboi.Info("Worker jobs scheduled")
|
||||
|
|
|
@ -34,11 +34,11 @@ import (
|
|||
)
|
||||
|
||||
var logboi = logging.NewLogger("crypto")
|
||||
var lettersAndNumbers = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
var tokenComponents = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
// HashString hashes a string
|
||||
func HashString(raw string) (string, error) {
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(raw), bcrypt.DefaultCost) // replace with safer seed?
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(raw), bcrypt.DefaultCost) // TODO: replace with safer seed?
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func GenerateToken(length int) (string, error) {
|
|||
}
|
||||
|
||||
for k, v := range bytes {
|
||||
bytes[k] = lettersAndNumbers[v%byte(len(lettersAndNumbers))]
|
||||
bytes[k] = tokenComponents[v%byte(len(tokenComponents))]
|
||||
}
|
||||
|
||||
return string(bytes), nil
|
||||
|
|
|
@ -19,6 +19,7 @@ const (
|
|||
GetOwnFriendRequests
|
||||
GetFriendRequestsById
|
||||
OverrideInteractionPreferences
|
||||
CreateSchedule
|
||||
)
|
||||
|
||||
var Permissions = map[types.PermissionKey]types.Permission{
|
||||
|
@ -106,4 +107,10 @@ var Permissions = map[types.PermissionKey]types.Permission{
|
|||
Description: "Allows user to interact with other users no matter their interaction preferences",
|
||||
Roles: []string{"admin"},
|
||||
},
|
||||
CreateSchedule: {
|
||||
Key: "create_schedule",
|
||||
Name: "Create Schedule",
|
||||
Description: "Allows user to create a schedule on their account",
|
||||
Roles: []string{"admin", "user", "member"},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue