Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Consumer deletion #124

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/generated/openapi/openapi.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ components:
updated_at:
type: string
format: date-time
deleted_at:
type: string
format: date-time
ConsumerList:
allOf:
- $ref: '#/components/schemas/List'
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/openapi/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ components:
updated_at:
format: date-time
type: string
deleted_at:
format: date-time
type: string
type: object
example: null
ConsumerList_allOf:
Expand Down
26 changes: 26 additions & 0 deletions pkg/api/openapi/docs/Consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Name | Type | Description | Notes
**Labels** | Pointer to **map[string]string** | | [optional]
**CreatedAt** | Pointer to **time.Time** | | [optional]
**UpdatedAt** | Pointer to **time.Time** | | [optional]
**DeletedAt** | Pointer to **time.Time** | | [optional]

## Methods

Expand Down Expand Up @@ -206,6 +207,31 @@ SetUpdatedAt sets UpdatedAt field to given value.

HasUpdatedAt returns a boolean if a field has been set.

### GetDeletedAt

`func (o *Consumer) GetDeletedAt() time.Time`

GetDeletedAt returns the DeletedAt field if non-nil, zero value otherwise.

### GetDeletedAtOk

`func (o *Consumer) GetDeletedAtOk() (*time.Time, bool)`

GetDeletedAtOk returns a tuple with the DeletedAt field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetDeletedAt

`func (o *Consumer) SetDeletedAt(v time.Time)`

SetDeletedAt sets DeletedAt field to given value.

### HasDeletedAt

`func (o *Consumer) HasDeletedAt() bool`

HasDeletedAt returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
26 changes: 26 additions & 0 deletions pkg/api/openapi/docs/ConsumerAllOf.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Name | Type | Description | Notes
**Labels** | Pointer to **map[string]string** | | [optional]
**CreatedAt** | Pointer to **time.Time** | | [optional]
**UpdatedAt** | Pointer to **time.Time** | | [optional]
**DeletedAt** | Pointer to **time.Time** | | [optional]

## Methods

Expand Down Expand Up @@ -128,6 +129,31 @@ SetUpdatedAt sets UpdatedAt field to given value.

HasUpdatedAt returns a boolean if a field has been set.

### GetDeletedAt

`func (o *ConsumerAllOf) GetDeletedAt() time.Time`

GetDeletedAt returns the DeletedAt field if non-nil, zero value otherwise.

### GetDeletedAtOk

`func (o *ConsumerAllOf) GetDeletedAtOk() (*time.Time, bool)`

GetDeletedAtOk returns a tuple with the DeletedAt field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetDeletedAt

`func (o *ConsumerAllOf) SetDeletedAt(v time.Time)`

SetDeletedAt sets DeletedAt field to given value.

### HasDeletedAt

`func (o *ConsumerAllOf) HasDeletedAt() bool`

HasDeletedAt returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
36 changes: 36 additions & 0 deletions pkg/api/openapi/model_consumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions pkg/api/openapi/model_consumer_all_of.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkg/api/presenters/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ConvertConsumer(consumer openapi.Consumer) *api.Consumer {

func PresentConsumer(consumer *api.Consumer) openapi.Consumer {
reference := PresentReference(consumer.ID, consumer)
return openapi.Consumer{
converted := openapi.Consumer{
Id: reference.Id,
Kind: reference.Kind,
Href: reference.Href,
Expand All @@ -28,4 +28,8 @@ func PresentConsumer(consumer *api.Consumer) openapi.Consumer {
CreatedAt: openapi.PtrTime(consumer.CreatedAt),
UpdatedAt: openapi.PtrTime(consumer.UpdatedAt),
}
if !consumer.DeletedAt.Time.IsZero() {
converted.DeletedAt = openapi.PtrTime(consumer.DeletedAt.Time)
}
return converted
}
2 changes: 1 addition & 1 deletion pkg/dao/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewConsumerDao(sessionFactory *db.SessionFactory) ConsumerDao {
func (d *sqlConsumerDao) Get(ctx context.Context, id string) (*api.Consumer, error) {
g2 := (*d.sessionFactory).New(ctx)
var consumer api.Consumer
if err := g2.Take(&consumer, "id = ?", id).Error; err != nil {
if err := g2.Unscoped().Take(&consumer, "id = ?", id).Error; err != nil {
return nil, err
}
return &consumer, nil
Expand Down
9 changes: 7 additions & 2 deletions pkg/handlers/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h consumerHandler) List(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

listArgs := services.NewListArguments(r.URL.Query())
var consumers = []api.Consumer{}
consumers := []api.Consumer{}
paging, err := h.generic.List(ctx, "username", listArgs, &consumers)
if err != nil {
return nil, err
Expand Down Expand Up @@ -132,10 +132,15 @@ func (h consumerHandler) Get(w http.ResponseWriter, r *http.Request) {
handleGet(w, r, cfg)
}

// Delete will softly delete the consumer(hard deletion is restricted by the foreign key in resources table)
func (h consumerHandler) Delete(w http.ResponseWriter, r *http.Request) {
cfg := &handlerConfig{
Action: func() (interface{}, *errors.ServiceError) {
return nil, errors.NotImplemented("delete")
id := mux.Vars(r)["id"]
if err := h.consumer.Delete(r.Context(), id); err != nil {
return nil, err
}
return nil, nil
},
}
handleDelete(w, r, cfg, http.StatusNoContent)
Expand Down
Loading