-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added create, delete, get API + db operations for pip data
- Loading branch information
1 parent
e05676a
commit 9fc51e5
Showing
7 changed files
with
261 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
package pip | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/nuts-foundation/nuts-pxp/db" | ||
) | ||
|
||
var _ StrictServerInterface = (*Wrapper)(nil) | ||
|
||
type Wrapper struct{} | ||
type Wrapper struct { | ||
DB db.DB | ||
} | ||
|
||
func (w Wrapper) CreateData(_ context.Context, request CreateDataRequestObject) (CreateDataResponseObject, error) { | ||
// serialize authInput for storage | ||
authInput, _ := json.Marshal(request.Body.AuthInput) | ||
data := db.SQLData{ | ||
Id: request.Id, | ||
Client: request.Body.ClientId, | ||
Scope: request.Body.Scope, | ||
Verifier: request.Body.VerifierId, | ||
AuthInput: string(authInput), | ||
} | ||
err := w.DB.Create(data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return CreateData204Response{}, nil | ||
} | ||
|
||
func (w Wrapper) GetData(ctx context.Context, request GetDataRequestObject) (GetDataResponseObject, error) { | ||
data, err := w.DB.Get(request.Id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// turn data into map[string]interface{} | ||
var authInput map[string]interface{} | ||
err = json.Unmarshal([]byte(data.AuthInput), &authInput) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return GetData200JSONResponse{ | ||
ClientId: data.Client, | ||
Scope: data.Scope, | ||
VerifierId: data.Verifier, | ||
AuthInput: authInput, | ||
}, nil | ||
} | ||
|
||
func (w Wrapper) CreateData(ctx context.Context, request CreateDataRequestObject) (CreateDataResponseObject, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
func (w Wrapper) DeleteData(ctx context.Context, request DeleteDataRequestObject) (DeleteDataResponseObject, error) { | ||
err := w.DB.Delete(request.Id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return DeleteData204Response{}, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
package db | ||
|
||
type DB interface { | ||
Close() error | ||
Create(data SQLData) error | ||
Delete(id string) error | ||
Get(id string) (SQLData, error) | ||
Query(scope string, verifier string, client string) (string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package db | ||
|
||
import "gorm.io/gorm/schema" | ||
|
||
var _ schema.Tabler = (*SQLData)(nil) | ||
|
||
type SQLData struct { | ||
Id string `gorm:"primaryKey"` | ||
Client string | ||
Scope string | ||
Verifier string | ||
AuthInput string `gorm:"column:auth_input"` | ||
} | ||
|
||
func (s SQLData) TableName() string { | ||
return "data" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters