Skip to content

Commit cf3ac40

Browse files
committed
reaction: add delete query + fix reactionid input hook.
1 parent f412e95 commit cf3ac40

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

graph/reaction_resolver.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Fractale - Self-organisation for humans.
3+
* Copyright (C) 2022 Fractale Co
4+
*
5+
* This file is part of Fractale.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with Fractale. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package graph
22+
23+
import (
24+
//"fmt"
25+
"context"
26+
"strings"
27+
"strconv"
28+
"github.com/99designs/gqlgen/graphql"
29+
"fractale/fractal6.go/graph/model"
30+
"fractale/fractal6.go/web/auth"
31+
. "fractale/fractal6.go/tools"
32+
)
33+
34+
35+
36+
func addReactionInputHook(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) {
37+
// Get User context
38+
ctx, uctx, err := auth.GetUserContext(ctx)
39+
if err != nil { return nil, LogErr("Access denied", err) }
40+
41+
data, err := next(ctx)
42+
if err != nil {
43+
return data, err
44+
}
45+
46+
// Move pendingCandidate to candidate if email exists in User
47+
newData := data.([]*model.AddReactionInput)
48+
for i, input := range newData {
49+
ids := []string{uctx.Username, *input.Comment.ID, strconv.Itoa(input.Type)}
50+
reactionid := strings.Join(ids, "#")
51+
input.Reactionid = &reactionid
52+
newData[i] = input
53+
}
54+
55+
return newData, err
56+
}

graph/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func Init() gen.Config {
150150
//Reaction
151151
c.Directives.Hook_getReactionInput = nothing
152152
c.Directives.Hook_queryReactionInput = nothing
153-
c.Directives.Hook_addReactionInput = nothing
153+
c.Directives.Hook_addReactionInput = addReactionInputHook
154154
c.Directives.Hook_updateReactionInput = nothing
155155
c.Directives.Hook_deleteReactionInput = nothing
156156
// --

graph/schema.resolvers.go

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)