Skip to content

Commit

Permalink
fix categories to be addressed by slugs instead of name
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Sep 30, 2023
1 parent b976f73 commit 012ddfc
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 183 deletions.
8 changes: 4 additions & 4 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ paths:
description: Show only results with these categories
required: false
in: query
schema: { $ref: "#/components/schemas/CategoryNameList" }
schema: { $ref: "#/components/schemas/CategorySlugList" }
responses:
default: { $ref: "#/components/responses/InternalServerError" }
"404": { $ref: "#/components/responses/NotFound" }
Expand Down Expand Up @@ -1925,7 +1925,7 @@ components:

CategoryCommonProps:
type: object
required: [name, sort]
required: [name, slug, description, colour, sort, admin, meta]
properties:
name:
$ref: "#/components/schemas/CategoryName"
Expand Down Expand Up @@ -1980,11 +1980,11 @@ components:
description: A category's URL-safe slug.
type: string

CategoryNameList:
CategorySlugList:
description: A list of category names.
type: array
items:
$ref: "#/components/schemas/CategoryName"
$ref: "#/components/schemas/CategorySlug"

CategoryAdditional:
type: object
Expand Down
2 changes: 1 addition & 1 deletion app/resources/thread/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func HasTags(ids []xid.ID) Query {

func HasCategories(ids []string) Query {
return func(q *ent.PostQuery) {
q.Where(ent_post.HasCategoryWith(ent_category.NameIn(ids...)))
q.Where(ent_post.HasCategoryWith(ent_category.SlugIn(ids...)))
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/transports/openapi/bindings/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ func (c Categories) CategoryUpdateOrder(ctx context.Context, request openapi.Cat
func (c Categories) CategoryUpdate(ctx context.Context, request openapi.CategoryUpdateRequestObject) (openapi.CategoryUpdateResponseObject, error) {
cat, err := c.category_svc.Update(ctx, category.CategoryID(deserialiseID(request.CategoryId)), category_svc.Partial{
Name: opt.NewPtr(request.Body.Name),
Slug: opt.NewPtr(request.Body.Slug),
Description: opt.NewPtr(request.Body.Description),
Colour: opt.NewPtr(request.Body.Colour),
Admin: opt.NewPtr(request.Body.Admin),
Meta: opt.NewPtr((*map[string]any)(request.Body.Meta)),
})
if err != nil {
return nil, fault.Wrap(err, fctx.With(ctx))
Expand Down
16 changes: 10 additions & 6 deletions app/transports/openapi/bindings/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,27 @@ func serialiseProfileReference(a profile.Profile) openapi.ProfileReference {
func serialiseCategory(c *category.Category) openapi.Category {
return openapi.Category{
Id: *openapi.IdentifierFrom(xid.ID(c.ID)),
Admin: &c.Admin,
Colour: &c.Colour,
Description: &c.Description,
Name: c.Name,
Slug: c.Slug,
Colour: c.Colour,
Description: c.Description,
PostCount: c.PostCount,
Admin: c.Admin,
Sort: c.Sort,
Meta: c.Metadata,
}
}

func serialiseCategoryReference(c *category.Category) openapi.CategoryReference {
return openapi.CategoryReference{
Id: *openapi.IdentifierFrom(xid.ID(c.ID)),
Admin: &c.Admin,
Colour: &c.Colour,
Description: &c.Description,
Name: c.Name,
Slug: c.Slug,
Admin: c.Admin,
Colour: c.Colour,
Description: c.Description,
Sort: c.Sort,
Meta: (openapi.Metadata)(c.Metadata),
}
}

Expand Down
320 changes: 160 additions & 160 deletions internal/openapi/generated.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions web/src/api/openapi/schemas/categoryCommonProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import type { Metadata } from "./metadata";

export interface CategoryCommonProps {
name: CategoryName;
slug?: CategorySlug;
description?: string;
colour?: string;
slug: CategorySlug;
description: string;
colour: string;
sort: number;
admin?: boolean;
meta?: Metadata;
admin: boolean;
meta: Metadata;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Storyden social API for building community driven platforms.
* OpenAPI spec version: 1
*/
import type { CategoryName } from "./categoryName";
import type { CategorySlug } from "./categorySlug";

/**
* A list of category names.
*/
export type CategoryNameList = CategoryName[];
export type CategorySlugList = CategorySlug[];
2 changes: 1 addition & 1 deletion web/src/api/openapi/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export * from "./categoryList";
export * from "./categoryListOKResponse";
export * from "./categoryMutableProps";
export * from "./categoryName";
export * from "./categoryNameList";
export * from "./categoryReference";
export * from "./categorySlug";
export * from "./categorySlugList";
export * from "./categoryUpdateBody";
export * from "./categoryUpdateOKResponse";
export * from "./categoryUpdateOrderBody";
Expand Down
4 changes: 2 additions & 2 deletions web/src/api/openapi/schemas/threadListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* OpenAPI spec version: 1
*/
import type { AccountHandle } from "./accountHandle";
import type { CategoryNameList } from "./categoryNameList";
import type { CategorySlugList } from "./categorySlugList";
import type { TagListIDs } from "./tagListIDs";

export type ThreadListParams = {
Expand All @@ -21,5 +21,5 @@ export type ThreadListParams = {
/**
* Show only results with these categories
*/
categories?: CategoryNameList;
categories?: CategorySlugList;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Unready } from "src/components/site/Unready";
function CategoryListItem(props: Category) {
const pathname = usePathname();

const href = `/c/${props.name}`;
const href = `/c/${props.slug}`;
const selected = href === pathname;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function CategoryListItem(props: Category & { isAdmin: boolean }) {
} = useSortable({ id: props.id });
const pathname = usePathname();

const href = `/c/${props.name}`;
const href = `/c/${props.slug}`;
const selected = href === pathname;

const style = {
Expand Down

2 comments on commit 012ddfc

@vercel
Copy link

@vercel vercel bot commented on 012ddfc Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 012ddfc Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.