Skip to content

Commit

Permalink
Merge pull request #60 from Ygg-Drasill/merge-failure-fix
Browse files Browse the repository at this point in the history
Merge failure fix
  • Loading branch information
alexrefshauge authored Oct 25, 2024
2 parents d36ba65 + 0bb03f7 commit 017d74d
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/api/handlers/notificationHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type GetFilteredNotificationsRequest struct {
// @Produce json
// @Success 200 {array} Notification
// @Router /notification/getFiltered [get]
func (db *DbContext) GetNotifications(ctx *gin.Context) {
func (db *DbContext) GetNotificationsFiltered(ctx *gin.Context) {
var request GetFilteredNotificationsRequest
err := ctx.ShouldBindQuery(&request)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions backend/api/handlers/penaltyHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Ygg-Drasill/PenaltyThing/backend/models"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)

type AddPenaltyRequest struct {
Expand Down Expand Up @@ -59,6 +60,22 @@ type GetPenaltyHistoryResponse struct {
PenaltyEntries models.PenaltyEntry `json:"penaltyEntries"`
} // @name GetPenaltyHistoryResponse

// Get
//
// @Id get
// @Param ids query string true "ids"
// @Success 200 {array} PenaltyEntry
// @Router /penalty/get [get]
func (db *DbContext) Get(ctx *gin.Context) {
ids := ctx.Param("ids")
idList := strings.Split(ids, ",")
penaltyEntriesResult, err := db.repo.GetPenaltiesById(idList)
if err != nil {
ctx.String(http.StatusInternalServerError, err.Error())
}
ctx.JSON(http.StatusOK, penaltyEntriesResult)
}

// GetPenaltyHistory
//
// @Id getPenaltyHistory
Expand Down
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func main() {

notification := v1.Group("/notification")
{
notification.GET("/getFiltered", dbContext.GetNotifications)
notification.GET("/getFiltered", dbContext.GetNotificationsFiltered)
}

health := v1.Group("/health")
Expand Down
2 changes: 1 addition & 1 deletion backend/repository/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (repo *Repository) GetInvitationById(id string) (*models.Invitation, error)
}

func (repo *Repository) DeleteInvitation(id string) error {
res := repo.db.Delete(&models.Invitation{}, id)
res := repo.db.Delete(&models.Invitation{Id: id})
if res.Error != nil {
return res.Error
}
Expand Down
2 changes: 1 addition & 1 deletion backend/repository/lawRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (repo *Repository) UpdateLaw(law models.Law) error {
}

func (repo *Repository) DeleteLawById(lawId string) error {
res := repo.db.Delete(&models.Law{}, lawId)
res := repo.db.Delete(&models.Law{Id: lawId})
if res.Error != nil {
return res.Error
}
Expand Down
2 changes: 1 addition & 1 deletion backend/repository/notificationRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (repo *Repository) GetNotificationsByUserId(userId string) ([]models.Notifi
}

func (repo *Repository) DeleteNotification(id string) error {
res := repo.db.Delete(&models.Notification{}, id)
res := repo.db.Delete(&models.Notification{Id: id})
if res.Error != nil {
return res.Error
}
Expand Down
10 changes: 10 additions & 0 deletions backend/repository/penaltyRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ func (repo *Repository) GetPenaltiesByUserId(userId string) ([]models.PenaltyEnt
}
return penalties, nil
}

func (repo *Repository) GetPenaltiesById(ids []string) ([]models.PenaltyEntry, error) {
var penalties []models.PenaltyEntry
var err error
err = repo.db.Find(&penalties, ids).Error
if err != nil {
return nil, err
}
return penalties, nil
}
24 changes: 16 additions & 8 deletions frontend/src/components/NotificationList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Button, CircularProgress, IconButton, LinearProgress, Stack, Typography } from '@mui/material'
import useAppContext from './hooks/appContext'
import useAppContext, { AppContext } from './hooks/appContext'
import { useInvitationServiceAcceptInvitation } from './openapi/queries'
import { Check, Clear } from '@mui/icons-material'
import { Notification } from './openapi/requests'
import { useQueryClient } from '@tanstack/react-query'

function bytesToString(bytes: number[]): string {
const str = atob(bytes.toString())
Expand All @@ -11,15 +12,22 @@ function bytesToString(bytes: number[]): string {

function InvitationNotification(props: { notification: Notification }) {
const acceptInvitation = useInvitationServiceAcceptInvitation()

const client = useQueryClient()
const onClickAccept = () => {
acceptInvitation.mutate({
request: {
invitationId: bytesToString(props.notification.data),
userId: props.notification.receiverId,
notificationId: props.notification.id,
acceptInvitation.mutate(
{
request: {
invitationId: bytesToString(props.notification.data),
userId: props.notification.receiverId,
notificationId: props.notification.id,
},
},
{
onSuccess: () => {
client.invalidateQueries({ queryKey: ['NotificationServiceGetFiltered'] })
},
},
})
)
}

const onClickClear = () => {}
Expand Down

0 comments on commit 017d74d

Please sign in to comment.