feat: ftime logic for usertitle is changed
This commit is contained in:
parent
5acc53ec9d
commit
00894f4526
12 changed files with 113 additions and 35 deletions
|
|
@ -395,6 +395,9 @@ paths:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
ftime:
|
||||
type: string
|
||||
format: date-time
|
||||
required:
|
||||
- title_id
|
||||
- status
|
||||
|
|
@ -478,6 +481,9 @@ paths:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
ftime:
|
||||
type: string
|
||||
format: date-time
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
|
|
|
|||
|
|
@ -262,6 +262,7 @@ type GetUserTitlesParams struct {
|
|||
|
||||
// AddUserTitleJSONBody defines parameters for AddUserTitle.
|
||||
type AddUserTitleJSONBody struct {
|
||||
Ftime *time.Time `json:"ftime,omitempty"`
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
|
|
@ -271,6 +272,7 @@ type AddUserTitleJSONBody struct {
|
|||
|
||||
// UpdateUserTitleJSONBody defines parameters for UpdateUserTitle.
|
||||
type UpdateUserTitleJSONBody struct {
|
||||
Ftime *time.Time `json:"ftime,omitempty"`
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ patch:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
ftime:
|
||||
type: string
|
||||
format: date-time
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ post:
|
|||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
ftime:
|
||||
type: string
|
||||
format: date-time
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully added to user
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ func sqlDate2oapi(p_date pgtype.Timestamptz) *time.Time {
|
|||
return nil
|
||||
}
|
||||
|
||||
func oapiDate2sql(t *time.Time) pgtype.Timestamptz {
|
||||
if t == nil {
|
||||
return pgtype.Timestamptz{Valid: false}
|
||||
}
|
||||
return pgtype.Timestamptz{
|
||||
Time: *t,
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
// func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) (*SqlcUserStatus, error) {
|
||||
// var sqlc_status SqlcUserStatus
|
||||
// if s == nil {
|
||||
|
|
@ -365,6 +375,7 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
|
|||
TitleID: request.Body.TitleId,
|
||||
Status: *status,
|
||||
Rate: request.Body.Rate,
|
||||
Ftime: oapiDate2sql(request.Body.Ftime),
|
||||
}
|
||||
|
||||
user_title, err := s.db.InsertUserTitle(ctx, params)
|
||||
|
|
@ -428,6 +439,7 @@ func (s Server) UpdateUserTitle(ctx context.Context, request oapi.UpdateUserTitl
|
|||
Rate: request.Body.Rate,
|
||||
UserID: request.UserId,
|
||||
TitleID: request.TitleId,
|
||||
Ftime: oapiDate2sql(request.Body.Ftime),
|
||||
}
|
||||
|
||||
user_title, err := s.db.UpdateUserTitle(ctx, params)
|
||||
|
|
|
|||
|
|
@ -400,13 +400,14 @@ FROM reviews
|
|||
WHERE review_id = sqlc.arg('review_id')::bigint;
|
||||
|
||||
-- name: InsertUserTitle :one
|
||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id, ctime)
|
||||
VALUES (
|
||||
sqlc.arg('user_id')::bigint,
|
||||
sqlc.arg('title_id')::bigint,
|
||||
sqlc.arg('status')::usertitle_status_t,
|
||||
sqlc.narg('rate')::int,
|
||||
sqlc.narg('review_id')::bigint
|
||||
sqlc.narg('review_id')::bigint,
|
||||
sqlc.narg('ftime')::timestamptz
|
||||
)
|
||||
RETURNING user_id, title_id, status, rate, review_id, ctime;
|
||||
|
||||
|
|
@ -415,7 +416,8 @@ RETURNING user_id, title_id, status, rate, review_id, ctime;
|
|||
UPDATE usertitles
|
||||
SET
|
||||
status = COALESCE(sqlc.narg('status')::usertitle_status_t, status),
|
||||
rate = COALESCE(sqlc.narg('rate')::int, rate)
|
||||
rate = COALESCE(sqlc.narg('rate')::int, rate),
|
||||
ctime = COALESCE(sqlc.narg('ftime')::timestamptz, ctime)
|
||||
WHERE
|
||||
user_id = sqlc.arg('user_id')
|
||||
AND title_id = sqlc.arg('title_id')
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|||
*/
|
||||
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
||||
|
||||
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://10.1.0.65:8081/api/v1' }));
|
||||
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: '/api/v1' }));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import type { Client, Options as Options2, TDataShape } from './client';
|
||||
import { client } from './client.gen';
|
||||
import type { AddUserTitleData, AddUserTitleErrors, AddUserTitleResponses, DeleteUserTitleData, DeleteUserTitleErrors, DeleteUserTitleResponses, GetTitleData, GetTitleErrors, GetTitleResponses, GetTitlesData, GetTitlesErrors, GetTitlesResponses, GetUsersIdData, GetUsersIdErrors, GetUsersIdResponses, GetUserTitleData, GetUserTitleErrors, GetUserTitleResponses, GetUserTitlesData, GetUserTitlesErrors, GetUserTitlesResponses, UpdateUserData, UpdateUserErrors, UpdateUserResponses, UpdateUserTitleData, UpdateUserTitleErrors, UpdateUserTitleResponses } from './types.gen';
|
||||
import type { AddUserTitleData, AddUserTitleErrors, AddUserTitleResponses, DeleteUserTitleData, DeleteUserTitleErrors, DeleteUserTitleResponses, GetTitleData, GetTitleErrors, GetTitleResponses, GetTitlesData, GetTitlesErrors, GetTitlesResponses, GetUsersData, GetUsersErrors, GetUsersIdData, GetUsersIdErrors, GetUsersIdResponses, GetUsersResponses, GetUserTitleData, GetUserTitleErrors, GetUserTitleResponses, GetUserTitlesData, GetUserTitlesErrors, GetUserTitlesResponses, UpdateUserData, UpdateUserErrors, UpdateUserResponses, UpdateUserTitleData, UpdateUserTitleErrors, UpdateUserTitleResponses } from './types.gen';
|
||||
|
||||
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
|
||||
/**
|
||||
|
|
@ -32,6 +32,11 @@ export const getTitles = <ThrowOnError extends boolean = false>(options?: Option
|
|||
*/
|
||||
export const getTitle = <ThrowOnError extends boolean = false>(options: Options<GetTitleData, ThrowOnError>) => (options.client ?? client).get<GetTitleResponses, GetTitleErrors, ThrowOnError>({ url: '/titles/{title_id}', ...options });
|
||||
|
||||
/**
|
||||
* Search user by nickname or dispname (both in one param), response is always sorted by id
|
||||
*/
|
||||
export const getUsers = <ThrowOnError extends boolean = false>(options?: Options<GetUsersData, ThrowOnError>) => (options?.client ?? client).get<GetUsersResponses, GetUsersErrors, ThrowOnError>({ url: '/users/', ...options });
|
||||
|
||||
/**
|
||||
* Get user info
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -60,6 +60,12 @@ export type Title = {
|
|||
title_names: {
|
||||
[key: string]: Array<string>;
|
||||
};
|
||||
/**
|
||||
* Localized description. Key = language (ISO 639-1), value = description.
|
||||
*/
|
||||
title_desc?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
studio?: Studio;
|
||||
tags: Tags;
|
||||
poster?: Image;
|
||||
|
|
@ -231,6 +237,50 @@ export type GetTitleResponses = {
|
|||
|
||||
export type GetTitleResponse = GetTitleResponses[keyof GetTitleResponses];
|
||||
|
||||
export type GetUsersData = {
|
||||
body?: never;
|
||||
path?: never;
|
||||
query?: {
|
||||
word?: string;
|
||||
limit?: number;
|
||||
/**
|
||||
* pass cursor naked
|
||||
*/
|
||||
cursor_id?: number;
|
||||
};
|
||||
url: '/users/';
|
||||
};
|
||||
|
||||
export type GetUsersErrors = {
|
||||
/**
|
||||
* Request params are not correct
|
||||
*/
|
||||
400: unknown;
|
||||
/**
|
||||
* Unknown server error
|
||||
*/
|
||||
500: unknown;
|
||||
};
|
||||
|
||||
export type GetUsersResponses = {
|
||||
/**
|
||||
* List of users with cursor
|
||||
*/
|
||||
200: {
|
||||
/**
|
||||
* List of users
|
||||
*/
|
||||
data: Array<User>;
|
||||
cursor: number;
|
||||
};
|
||||
/**
|
||||
* No users found
|
||||
*/
|
||||
204: void;
|
||||
};
|
||||
|
||||
export type GetUsersResponse = GetUsersResponses[keyof GetUsersResponses];
|
||||
|
||||
export type GetUsersIdData = {
|
||||
body?: never;
|
||||
path: {
|
||||
|
|
|
|||
0
modules/frontend/src/pages/UsersPage/UsersPage.tsx
Normal file
0
modules/frontend/src/pages/UsersPage/UsersPage.tsx
Normal file
|
|
@ -171,16 +171,3 @@ CREATE TRIGGER trg_notify_new_signal
|
|||
AFTER INSERT ON signals
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION notify_new_signal();
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_ctime()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.ctime = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER set_ctime_on_update
|
||||
BEFORE UPDATE ON usertitles
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_ctime();
|
||||
|
|
@ -9,6 +9,8 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createImage = `-- name: CreateImage :one
|
||||
|
|
@ -394,13 +396,14 @@ func (q *Queries) InsertTitleTags(ctx context.Context, arg InsertTitleTagsParams
|
|||
}
|
||||
|
||||
const insertUserTitle = `-- name: InsertUserTitle :one
|
||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id)
|
||||
INSERT INTO usertitles (user_id, title_id, status, rate, review_id, ctime)
|
||||
VALUES (
|
||||
$1::bigint,
|
||||
$2::bigint,
|
||||
$3::usertitle_status_t,
|
||||
$4::int,
|
||||
$5::bigint
|
||||
$5::bigint,
|
||||
$6::timestamptz
|
||||
)
|
||||
RETURNING user_id, title_id, status, rate, review_id, ctime
|
||||
`
|
||||
|
|
@ -411,6 +414,7 @@ type InsertUserTitleParams struct {
|
|||
Status UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
ReviewID *int64 `json:"review_id"`
|
||||
Ftime pgtype.Timestamptz `json:"ftime"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertUserTitle(ctx context.Context, arg InsertUserTitleParams) (Usertitle, error) {
|
||||
|
|
@ -420,6 +424,7 @@ func (q *Queries) InsertUserTitle(ctx context.Context, arg InsertUserTitleParams
|
|||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.ReviewID,
|
||||
arg.Ftime,
|
||||
)
|
||||
var i Usertitle
|
||||
err := row.Scan(
|
||||
|
|
@ -1017,16 +1022,18 @@ const updateUserTitle = `-- name: UpdateUserTitle :one
|
|||
UPDATE usertitles
|
||||
SET
|
||||
status = COALESCE($1::usertitle_status_t, status),
|
||||
rate = COALESCE($2::int, rate)
|
||||
rate = COALESCE($2::int, rate),
|
||||
ctime = COALESCE($3::timestamptz, ctime)
|
||||
WHERE
|
||||
user_id = $3
|
||||
AND title_id = $4
|
||||
user_id = $4
|
||||
AND title_id = $5
|
||||
RETURNING user_id, title_id, status, rate, review_id, ctime
|
||||
`
|
||||
|
||||
type UpdateUserTitleParams struct {
|
||||
Status *UsertitleStatusT `json:"status"`
|
||||
Rate *int32 `json:"rate"`
|
||||
Ftime pgtype.Timestamptz `json:"ftime"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TitleID int64 `json:"title_id"`
|
||||
}
|
||||
|
|
@ -1036,6 +1043,7 @@ func (q *Queries) UpdateUserTitle(ctx context.Context, arg UpdateUserTitleParams
|
|||
row := q.db.QueryRow(ctx, updateUserTitle,
|
||||
arg.Status,
|
||||
arg.Rate,
|
||||
arg.Ftime,
|
||||
arg.UserID,
|
||||
arg.TitleID,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue