mirror of
https://github.com/hexolan/panels.git
synced 2026-03-26 12:40:21 +00:00
style: license headers + gofmt
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
// Copyright 2023 Declan Teevan
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
@@ -21,7 +35,7 @@ func setAuthMethod(userId string, password string) error {
|
||||
_, err := rpc.Svcs.GetAuthSvc().SetPasswordAuth(
|
||||
ctx,
|
||||
&authv1.SetPasswordAuthMethod{
|
||||
UserId: userId,
|
||||
UserId: userId,
|
||||
Password: password,
|
||||
},
|
||||
)
|
||||
@@ -34,7 +48,7 @@ func authWithPassword(userId string, password string) (*authv1.AuthToken, error)
|
||||
token, err := rpc.Svcs.GetAuthSvc().AuthWithPassword(
|
||||
ctx,
|
||||
&authv1.PasswordAuthRequest{
|
||||
UserId: userId,
|
||||
UserId: userId,
|
||||
Password: password,
|
||||
},
|
||||
)
|
||||
@@ -63,8 +77,8 @@ func LoginWithPassword(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "success",
|
||||
"data": fiber.Map{
|
||||
"user": user,
|
||||
"user": user,
|
||||
"token": token,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
// Copyright 2023 Declan Teevan
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
@@ -48,7 +62,7 @@ func UpdateComment(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if (comment.AuthorId != currentUser.Id) {
|
||||
if comment.AuthorId != currentUser.Id {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to update that comment")
|
||||
}
|
||||
|
||||
@@ -64,7 +78,7 @@ func UpdateComment(c *fiber.Ctx) error {
|
||||
comment, err = rpc.Svcs.GetCommentSvc().UpdateComment(
|
||||
ctx,
|
||||
&commentv1.UpdateCommentRequest{
|
||||
Id: c.Params("id"),
|
||||
Id: c.Params("id"),
|
||||
Data: updatedComment,
|
||||
},
|
||||
)
|
||||
@@ -87,7 +101,7 @@ func DeleteComment(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if (comment.AuthorId != currentUser.Id && !currentUser.IsAdmin) {
|
||||
if comment.AuthorId != currentUser.Id && !currentUser.IsAdmin {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to delete that comment")
|
||||
}
|
||||
|
||||
@@ -123,16 +137,16 @@ func CreateComment(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
// Create the comment
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
comment, err := rpc.Svcs.GetCommentSvc().CreateComment(
|
||||
ctx,
|
||||
&commentv1.CreateCommentRequest{
|
||||
PostId: post.Id,
|
||||
PostId: post.Id,
|
||||
AuthorId: tokenClaims.Subject,
|
||||
Data: newComment,
|
||||
Data: newComment,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -140,4 +154,4 @@ func CreateComment(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{"status": "success", "data": comment})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
// Copyright 2023 Declan Teevan
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
@@ -29,7 +43,7 @@ func getPanelIDFromName(name string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
return panel.GetId(), nil
|
||||
}
|
||||
|
||||
@@ -76,7 +90,7 @@ func UpdatePanelById(c *fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
panel, err := rpc.Svcs.GetPanelSvc().UpdatePanel(
|
||||
ctx,
|
||||
ctx,
|
||||
&panelv1.UpdatePanelByIdRequest{Id: c.Params("id"), Data: patchData},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -106,7 +120,7 @@ func UpdatePanelByName(c *fiber.Ctx) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
panel, err := rpc.Svcs.GetPanelSvc().UpdatePanelByName(
|
||||
ctx,
|
||||
ctx,
|
||||
&panelv1.UpdatePanelByNameRequest{Name: c.Params("name"), Data: patchData},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -183,4 +197,4 @@ func CreatePanel(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{"status": "success", "data": panel})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
// Copyright 2023 Declan Teevan
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/hexolan/panels/gateway-service/internal/api/handlers"
|
||||
"github.com/hexolan/panels/gateway-service/internal/rpc"
|
||||
"github.com/hexolan/panels/gateway-service/internal/rpc/postv1"
|
||||
"github.com/hexolan/panels/gateway-service/internal/api/handlers"
|
||||
)
|
||||
|
||||
func getPostById(postId string) (*postv1.Post, error) {
|
||||
@@ -155,7 +169,7 @@ func UpdatePost(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if (post.AuthorId != currentUser.Id) {
|
||||
if post.AuthorId != currentUser.Id {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to update that post")
|
||||
}
|
||||
|
||||
@@ -191,10 +205,10 @@ func DeletePost(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if (post.AuthorId != currentUser.Id && !currentUser.IsAdmin) {
|
||||
if post.AuthorId != currentUser.Id && !currentUser.IsAdmin {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to delete that post")
|
||||
}
|
||||
|
||||
|
||||
// delete the post
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
@@ -235,8 +249,8 @@ func CreatePanelPostFromId(c *fiber.Ctx) error {
|
||||
ctx,
|
||||
&postv1.CreatePostRequest{
|
||||
PanelId: panel.Id,
|
||||
UserId: tokenClaims.Subject,
|
||||
Data: newPost,
|
||||
UserId: tokenClaims.Subject,
|
||||
Data: newPost,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -272,8 +286,8 @@ func CreatePanelPostFromName(c *fiber.Ctx) error {
|
||||
ctx,
|
||||
&postv1.CreatePostRequest{
|
||||
PanelId: panelId,
|
||||
UserId: tokenClaims.Subject,
|
||||
Data: newPost,
|
||||
UserId: tokenClaims.Subject,
|
||||
Data: newPost,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -281,4 +295,4 @@ func CreatePanelPostFromName(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{"status": "success", "data": post})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
// Copyright 2023 Declan Teevan
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/hexolan/panels/gateway-service/internal/api/handlers"
|
||||
"github.com/hexolan/panels/gateway-service/internal/rpc"
|
||||
"github.com/hexolan/panels/gateway-service/internal/rpc/userv1"
|
||||
"github.com/hexolan/panels/gateway-service/internal/api/handlers"
|
||||
)
|
||||
|
||||
type userSignupForm struct {
|
||||
@@ -87,7 +101,7 @@ func DeleteUserById(c *fiber.Ctx) error {
|
||||
if currentUser.Id != c.Params("id") && !currentUser.IsAdmin {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to delete that user")
|
||||
}
|
||||
|
||||
|
||||
// delete the user
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
@@ -113,7 +127,7 @@ func DeleteUserByUsername(c *fiber.Ctx) error {
|
||||
if currentUser.Id != c.Params("id") && !currentUser.IsAdmin {
|
||||
return fiber.NewError(fiber.StatusForbidden, "no permissions to delete that user")
|
||||
}
|
||||
|
||||
|
||||
// delete the user
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
@@ -155,7 +169,7 @@ func UserSignup(c *fiber.Ctx) error {
|
||||
if err := c.BodyParser(form); err != nil {
|
||||
fiber.NewError(fiber.StatusBadRequest, "malformed request")
|
||||
}
|
||||
|
||||
|
||||
// Attempt to create the user
|
||||
// todo: defer this logic away from gateway-service in future (potentially into seperate registration-service)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
@@ -189,8 +203,8 @@ func UserSignup(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
"status": "success",
|
||||
"data": fiber.Map{
|
||||
"user": user,
|
||||
"user": user,
|
||||
"token": token,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user