@@ -11,6 +11,7 @@ import (
1111 "github.com/Mad-Pixels/applingo-api/openapi-interface"
1212 "github.com/Mad-Pixels/applingo-api/openapi-interface/gen/applingoapi"
1313 "github.com/Mad-Pixels/applingo-api/pkg/api"
14+ "github.com/Mad-Pixels/applingo-api/pkg/auth"
1415 "github.com/Mad-Pixels/applingo-api/pkg/cloud"
1516 "github.com/Mad-Pixels/applingo-api/pkg/serializer"
1617
@@ -24,6 +25,10 @@ import (
2425const pageLimit = 60
2526
2627func handleGet (ctx context.Context , logger zerolog.Logger , _ json.RawMessage , baseParams openapi.QueryParams ) (any , * api.HandleError ) {
28+ if ! api .MustGetMetaData (ctx ).HasPermissions (auth .Device ) {
29+ return nil , & api.HandleError {Status : http .StatusForbidden , Err : errors .New ("insufficient permissions" )}
30+ }
31+
2732 validSortValues := map [applingoapi.BaseDictSortEnum ]struct {}{
2833 applingoapi .Date : {},
2934 applingoapi .Rating : {},
@@ -58,7 +63,7 @@ func handleGet(ctx context.Context, logger zerolog.Logger, _ json.RawMessage, ba
5863
5964 var (
6065 wg sync.WaitGroup
61- itemsCh = make (chan applingoapi. DictionaryItemV1 , len (result .Items ))
66+ itemsCh = make (chan applingodictionary. SchemaItem , len (result .Items ))
6267 )
6368 response := applingoapi.DictionariesData {
6469 Items : make ([]applingoapi.DictionaryItemV1 , 0 , len (result .Items )),
@@ -68,7 +73,7 @@ func handleGet(ctx context.Context, logger zerolog.Logger, _ json.RawMessage, ba
6873 go func (item map [string ]types.AttributeValue ) {
6974 defer wg .Done ()
7075
71- var dict applingoapi. DictionaryItemV1
76+ var dict applingodictionary. SchemaItem
7277 if err := attributevalue .UnmarshalMap (item , & dict ); err != nil {
7378 logger .Warn ().Err (err ).Msg ("Failed to unmarshal DynamoDB item" )
7479 return
@@ -82,7 +87,17 @@ func handleGet(ctx context.Context, logger zerolog.Logger, _ json.RawMessage, ba
8287 }()
8388
8489 for item := range itemsCh {
85- response .Items = append (response .Items , item )
90+ response .Items = append (response .Items , applingoapi.DictionaryItemV1 {
91+ Category : applingoapi .BaseCategoryEnum (item .Category ),
92+ Public : applingodictionary .IntToBool (item .IsPublic ),
93+ Created : int64 (item .Created ),
94+ Description : item .Description ,
95+ Dictionary : item .Dictionary ,
96+ Author : item .Author ,
97+ Name : item .Name ,
98+ Level : item .Level ,
99+ Topic : item .Topic ,
100+ })
86101 }
87102 if result .LastEvaluatedKey != nil {
88103 var lastEvaluatedKeyMap map [string ]interface {}
0 commit comments