Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
refactor: replace book -> movie
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh committed Feb 15, 2024
1 parent 261d8cc commit 90f8c32
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 78 deletions.
149 changes: 85 additions & 64 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,7 @@ export interface SchemaAuth {
username?: string
}

export interface SchemaBook {
/** @maxLength 255 */
author: string
created_at?: string
id?: string
meta: SchemaMeta
status: number
/** @maxLength 255 */
title: string
updated_at?: string
user_id: string
}

export interface SchemaBookListResponse {
count?: number
data?: SchemaBook[]
limit?: number
offset?: number
}

export interface SchemaCreateBook {
export interface SchemaCreateMovie {
/** @maxLength 255 */
author: string
meta: SchemaMeta
Expand Down Expand Up @@ -87,6 +67,26 @@ export interface SchemaMeta {
rating?: number
}

export interface SchemaMovie {
/** @maxLength 255 */
author: string
created_at?: string
id?: string
meta: SchemaMeta
status: number
/** @maxLength 255 */
title: string
updated_at?: string
user_id: string
}

export interface SchemaMovieListResponse {
count?: number
data?: SchemaMovie[]
limit?: number
offset?: number
}

export interface SchemaTokenResponse {
access_token?: string
msg?: string
Expand Down Expand Up @@ -559,16 +559,16 @@ export class Api<
...params
})
}
book = {
movie = {
/**
* @description Get all books.
* @description Get all movies.
*
* @tags Book
* @name V1BooksList
* @summary get all books
* @request GET:/api/v1/books
* @tags Movie
* @name V1MoviesList
* @summary get all movies
* @request GET:/api/v1/movies
*/
v1BooksList: (
v1MoviesList: (
query?: {
/** offset */
offset?: number
Expand All @@ -577,8 +577,8 @@ export class Api<
},
params: RequestParams = {}
) =>
this.request<SchemaBookListResponse, SchemaErrorResponse>({
path: `/api/v1/books`,
this.request<SchemaMovieListResponse, SchemaErrorResponse>({
path: `/api/v1/movies`,
method: 'GET',
query: query,
type: ContentType.Json,
Expand All @@ -587,78 +587,81 @@ export class Api<
}),

/**
* @description Create a new book.
* @description Create a new movie.
*
* @tags Book
* @name V1BooksCreate
* @summary create a new book
* @request POST:/api/v1/books
* @tags Movie
* @name V1MoviesCreate
* @summary create a new movie
* @request POST:/api/v1/movies
* @secure
*/
v1BooksCreate: (createbook: SchemaCreateBook, params: RequestParams = {}) =>
this.request<SchemaBook, SchemaErrorResponse>({
path: `/api/v1/books`,
v1MoviesCreate: (
createmovie: SchemaCreateMovie,
params: RequestParams = {}
) =>
this.request<SchemaMovie, SchemaErrorResponse>({
path: `/api/v1/movies`,
method: 'POST',
body: createbook,
body: createmovie,
secure: true,
type: ContentType.Json,
format: 'json',
...params
}),

/**
* @description a book.
* @description a movie.
*
* @tags Book
* @name V1BooksDetail
* @summary get a book
* @request GET:/api/v1/books/{id}
* @tags Movie
* @name V1MoviesDetail
* @summary get a movie
* @request GET:/api/v1/movies/{id}
*/
v1BooksDetail: (id: string, params: RequestParams = {}) =>
this.request<SchemaBook, SchemaErrorResponse>({
path: `/api/v1/books/${id}`,
v1MoviesDetail: (id: string, params: RequestParams = {}) =>
this.request<SchemaMovie, SchemaErrorResponse>({
path: `/api/v1/movies/${id}`,
method: 'GET',
type: ContentType.Json,
format: 'json',
...params
}),

/**
* @description update book
* @description update movie
*
* @tags Book
* @name V1BooksUpdate
* @summary update a book
* @request PUT:/api/v1/books/{id}
* @tags Movie
* @name V1MoviesUpdate
* @summary update a movie
* @request PUT:/api/v1/movies/{id}
* @secure
*/
v1BooksUpdate: (
v1MoviesUpdate: (
id: string,
updatebook: SchemaBook,
updatemovie: SchemaMovie,
params: RequestParams = {}
) =>
this.request<SchemaBook, SchemaErrorResponse>({
path: `/api/v1/books/${id}`,
this.request<SchemaMovie, SchemaErrorResponse>({
path: `/api/v1/movies/${id}`,
method: 'PUT',
body: updatebook,
body: updatemovie,
secure: true,
type: ContentType.Json,
format: 'json',
...params
}),

/**
* @description delete book
* @description delete movie
*
* @tags Book
* @name V1BooksDelete
* @summary delete a book
* @request DELETE:/api/v1/books/{id}
* @tags Movie
* @name V1MoviesDelete
* @summary delete a movie
* @request DELETE:/api/v1/movies/{id}
* @secure
*/
v1BooksDelete: (id: string, params: RequestParams = {}) =>
v1MoviesDelete: (id: string, params: RequestParams = {}) =>
this.request<object, SchemaErrorResponse>({
path: `/api/v1/books/${id}`,
path: `/api/v1/movies/${id}`,
method: 'DELETE',
secure: true,
type: ContentType.Json,
Expand Down Expand Up @@ -686,4 +689,22 @@ export class Api<
...params
})
}
misc = {
/**
* No description
*
* @tags Misc
* @name V1VersionList
* @summary get current software version
* @request GET:/api/v1/version
*/
v1VersionList: (params: RequestParams = {}) =>
this.request<object, any>({
path: `/api/v1/version`,
method: 'GET',
type: ContentType.Json,
format: 'json',
...params
})
}
}
8 changes: 4 additions & 4 deletions src/pages/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ListGroup from 'react-bootstrap/ListGroup'
import Backend from 'utils/service'

const Index: React.FC = () => {
const { data, loading } = useRequest(async () => Backend.book.v1BooksList())
const { data, loading } = useRequest(async () => Backend.movie.v1MoviesList())
return (
<PageContainer>
<div className='text-center'>
Expand All @@ -26,13 +26,13 @@ const Index: React.FC = () => {
<Card style={{ width: '18rem' }}>
<Card.Body>
<Card.Title>
<b>{loading ? 'loading...' : 'Books'}</b>
<b>{loading ? 'loading...' : 'Movies'}</b>
</Card.Title>
</Card.Body>
{!loading && (
<ListGroup variant='flush'>
{data?.data.data?.map(book => (
<ListGroup.Item key={book.id}>{book.title}</ListGroup.Item>
{data?.data.data?.map(movie => (
<ListGroup.Item key={movie.id}>{movie.title}</ListGroup.Item>
))}
</ListGroup>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import Backend from 'utils/service'
const Index: React.FC = () => {
const { user } = useAuth()
const navigate = useNavigate()
const [bookTitle, setBookTitle] = useState('my book')
const [movieTitle, setMovieTitle] = useState('my movie')
const { run: create } = useRequest(
async () =>
Backend.book.v1BooksCreate({
Backend.movie.v1MoviesCreate({
author: 'string',
meta: {
description: 'string',
picture: 'string',
rating: 10
},
status: 0,
title: bookTitle,
title: movieTitle,
user_id: user?.id ?? ''
}),
{
Expand All @@ -34,17 +34,17 @@ const Index: React.FC = () => {
return (
<PageContainer>
<div className='text-center'>
<h1>Create Book</h1>
<h1>Create Movie</h1>
</div>
<Form>
<Form.Group className='mb-3'>
<Form.Label>Book Title</Form.Label>
<Form.Label>Movie Title</Form.Label>
<Form.Control
type='text'
placeholder='Book title'
defaultValue={bookTitle}
placeholder='Movie title'
defaultValue={movieTitle}
onChange={e => {
setBookTitle(e.target.value)
setMovieTitle(e.target.value)
}}
/>
</Form.Group>
Expand Down
4 changes: 2 additions & 2 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ProtectedRoute } from 'components/ProtectedRoute'
import BookCreate from 'pages/BookCreate'
import Login from 'pages/Login'
import Logout from 'pages/Logout'
import Main from 'pages/Main'
import MovieCreate from 'pages/MovieCreate'
import NotFound from 'pages/NotFound'
import Register from 'pages/Register'
import type { RouteObject } from 'react-router-dom'
Expand All @@ -29,7 +29,7 @@ const children: RouteObject[] = [
children: [
{
path: '/create',
element: <BookCreate />
element: <MovieCreate />
}
]
},
Expand Down

0 comments on commit 90f8c32

Please sign in to comment.