diff --git a/backend/api/handlers/notificationHandler.go b/backend/api/handlers/notificationHandler.go index 5958089..28a7a23 100644 --- a/backend/api/handlers/notificationHandler.go +++ b/backend/api/handlers/notificationHandler.go @@ -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 { diff --git a/backend/api/handlers/penaltyHandlers.go b/backend/api/handlers/penaltyHandlers.go index 9690ac1..d779d78 100644 --- a/backend/api/handlers/penaltyHandlers.go +++ b/backend/api/handlers/penaltyHandlers.go @@ -5,6 +5,7 @@ import ( "github.com/Ygg-Drasill/PenaltyThing/backend/models" "github.com/gin-gonic/gin" "net/http" + "strings" ) type AddPenaltyRequest struct { @@ -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 diff --git a/backend/main.go b/backend/main.go index cdecfa6..a3f3da5 100644 --- a/backend/main.go +++ b/backend/main.go @@ -81,7 +81,7 @@ func main() { notification := v1.Group("/notification") { - notification.GET("/getFiltered", dbContext.GetNotifications) + notification.GET("/getFiltered", dbContext.GetNotificationsFiltered) } health := v1.Group("/health") diff --git a/backend/repository/invitation.go b/backend/repository/invitation.go index 8a69f08..e943b8d 100644 --- a/backend/repository/invitation.go +++ b/backend/repository/invitation.go @@ -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 } diff --git a/backend/repository/lawRepository.go b/backend/repository/lawRepository.go index c056c73..aa294c5 100644 --- a/backend/repository/lawRepository.go +++ b/backend/repository/lawRepository.go @@ -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 } diff --git a/backend/repository/notificationRepository.go b/backend/repository/notificationRepository.go index c9a40ef..5d86b17 100644 --- a/backend/repository/notificationRepository.go +++ b/backend/repository/notificationRepository.go @@ -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 } diff --git a/backend/repository/penaltyRepository.go b/backend/repository/penaltyRepository.go index c4189cd..657dd69 100644 --- a/backend/repository/penaltyRepository.go +++ b/backend/repository/penaltyRepository.go @@ -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 +} diff --git a/frontend/src/components/NotificationList.tsx b/frontend/src/components/NotificationList.tsx index 4dce2f6..dd9096c 100644 --- a/frontend/src/components/NotificationList.tsx +++ b/frontend/src/components/NotificationList.tsx @@ -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()) @@ -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 = () => {}