refactor personlist
This commit is contained in:
parent
cccd5a9d83
commit
3ecc971e8f
@ -41,15 +41,7 @@ fn get_user(
|
|||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn get_users(_token: auth::Token, user_list: &rocket::State<Vec<User>>) -> items::PersonList {
|
fn get_users(_token: auth::Token, user_list: &rocket::State<Vec<User>>) -> items::PersonList {
|
||||||
items::PersonList {
|
items::PersonList {
|
||||||
person: user_list
|
person: user_list.inner().iter().map(|u| u.person.clone()).collect(),
|
||||||
.inner()
|
|
||||||
.iter()
|
|
||||||
.map(|u| {
|
|
||||||
let mut p = u.person.clone();
|
|
||||||
p.opinion.clear();
|
|
||||||
p
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export interface Person {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Opinion {
|
export interface Opinion {
|
||||||
game: Game | undefined;
|
title: string;
|
||||||
wouldPlay: boolean;
|
wouldPlay: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +97,10 @@ export interface AuthStatusResponse {
|
|||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GameRequest {
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
function createBasePerson(): Person {
|
function createBasePerson(): Person {
|
||||||
return { name: "", opinion: [] };
|
return { name: "", opinion: [] };
|
||||||
}
|
}
|
||||||
@ -174,13 +178,13 @@ export const Person: MessageFns<Person> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function createBaseOpinion(): Opinion {
|
function createBaseOpinion(): Opinion {
|
||||||
return { game: undefined, wouldPlay: false };
|
return { title: "", wouldPlay: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Opinion: MessageFns<Opinion> = {
|
export const Opinion: MessageFns<Opinion> = {
|
||||||
encode(message: Opinion, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
encode(message: Opinion, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
if (message.game !== undefined) {
|
if (message.title !== "") {
|
||||||
Game.encode(message.game, writer.uint32(10).fork()).join();
|
writer.uint32(10).string(message.title);
|
||||||
}
|
}
|
||||||
if (message.wouldPlay !== false) {
|
if (message.wouldPlay !== false) {
|
||||||
writer.uint32(16).bool(message.wouldPlay);
|
writer.uint32(16).bool(message.wouldPlay);
|
||||||
@ -200,7 +204,7 @@ export const Opinion: MessageFns<Opinion> = {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.game = Game.decode(reader, reader.uint32());
|
message.title = reader.string();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
@ -222,15 +226,15 @@ export const Opinion: MessageFns<Opinion> = {
|
|||||||
|
|
||||||
fromJSON(object: any): Opinion {
|
fromJSON(object: any): Opinion {
|
||||||
return {
|
return {
|
||||||
game: isSet(object.game) ? Game.fromJSON(object.game) : undefined,
|
title: isSet(object.title) ? globalThis.String(object.title) : "",
|
||||||
wouldPlay: isSet(object.wouldPlay) ? globalThis.Boolean(object.wouldPlay) : false,
|
wouldPlay: isSet(object.wouldPlay) ? globalThis.Boolean(object.wouldPlay) : false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
toJSON(message: Opinion): unknown {
|
toJSON(message: Opinion): unknown {
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
if (message.game !== undefined) {
|
if (message.title !== "") {
|
||||||
obj.game = Game.toJSON(message.game);
|
obj.title = message.title;
|
||||||
}
|
}
|
||||||
if (message.wouldPlay !== false) {
|
if (message.wouldPlay !== false) {
|
||||||
obj.wouldPlay = message.wouldPlay;
|
obj.wouldPlay = message.wouldPlay;
|
||||||
@ -243,7 +247,7 @@ export const Opinion: MessageFns<Opinion> = {
|
|||||||
},
|
},
|
||||||
fromPartial<I extends Exact<DeepPartial<Opinion>, I>>(object: I): Opinion {
|
fromPartial<I extends Exact<DeepPartial<Opinion>, I>>(object: I): Opinion {
|
||||||
const message = createBaseOpinion();
|
const message = createBaseOpinion();
|
||||||
message.game = (object.game !== undefined && object.game !== null) ? Game.fromPartial(object.game) : undefined;
|
message.title = object.title ?? "";
|
||||||
message.wouldPlay = object.wouldPlay ?? false;
|
message.wouldPlay = object.wouldPlay ?? false;
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
@ -917,6 +921,64 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createBaseGameRequest(): GameRequest {
|
||||||
|
return { title: "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GameRequest: MessageFns<GameRequest> = {
|
||||||
|
encode(message: GameRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||||
|
if (message.title !== "") {
|
||||||
|
writer.uint32(10).string(message.title);
|
||||||
|
}
|
||||||
|
return writer;
|
||||||
|
},
|
||||||
|
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): GameRequest {
|
||||||
|
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
|
const end = length === undefined ? reader.len : reader.pos + length;
|
||||||
|
const message = createBaseGameRequest();
|
||||||
|
while (reader.pos < end) {
|
||||||
|
const tag = reader.uint32();
|
||||||
|
switch (tag >>> 3) {
|
||||||
|
case 1: {
|
||||||
|
if (tag !== 10) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.title = reader.string();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tag & 7) === 4 || tag === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reader.skip(tag & 7);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
|
||||||
|
fromJSON(object: any): GameRequest {
|
||||||
|
return { title: isSet(object.title) ? globalThis.String(object.title) : "" };
|
||||||
|
},
|
||||||
|
|
||||||
|
toJSON(message: GameRequest): unknown {
|
||||||
|
const obj: any = {};
|
||||||
|
if (message.title !== "") {
|
||||||
|
obj.title = message.title;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
create<I extends Exact<DeepPartial<GameRequest>, I>>(base?: I): GameRequest {
|
||||||
|
return GameRequest.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<GameRequest>, I>>(object: I): GameRequest {
|
||||||
|
const message = createBaseGameRequest();
|
||||||
|
message.title = object.title ?? "";
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/** Authentication service */
|
/** Authentication service */
|
||||||
export interface AuthService {
|
export interface AuthService {
|
||||||
Login(request: LoginRequest): Promise<LoginResponse>;
|
Login(request: LoginRequest): Promise<LoginResponse>;
|
||||||
@ -954,6 +1016,34 @@ export class AuthServiceClientImpl implements AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MainService {
|
||||||
|
GetGame(request: GameRequest): Promise<Game>;
|
||||||
|
AddOpinion(request: GameRequest): Promise<Person>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MainServiceServiceName = "items.MainService";
|
||||||
|
export class MainServiceClientImpl implements MainService {
|
||||||
|
private readonly rpc: Rpc;
|
||||||
|
private readonly service: string;
|
||||||
|
constructor(rpc: Rpc, opts?: { service?: string }) {
|
||||||
|
this.service = opts?.service || MainServiceServiceName;
|
||||||
|
this.rpc = rpc;
|
||||||
|
this.GetGame = this.GetGame.bind(this);
|
||||||
|
this.AddOpinion = this.AddOpinion.bind(this);
|
||||||
|
}
|
||||||
|
GetGame(request: GameRequest): Promise<Game> {
|
||||||
|
const data = GameRequest.encode(request).finish();
|
||||||
|
const promise = this.rpc.request(this.service, "GetGame", data);
|
||||||
|
return promise.then((data) => Game.decode(new BinaryReader(data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
AddOpinion(request: GameRequest): Promise<Person> {
|
||||||
|
const data = GameRequest.encode(request).finish();
|
||||||
|
const promise = this.rpc.request(this.service, "AddOpinion", data);
|
||||||
|
return promise.then((data) => Person.decode(new BinaryReader(data)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface Rpc {
|
interface Rpc {
|
||||||
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,8 +60,7 @@ function App() {
|
|||||||
<ul>
|
<ul>
|
||||||
{person.opinion.map((op, i) => (
|
{person.opinion.map((op, i) => (
|
||||||
<li key={i}>
|
<li key={i}>
|
||||||
{op.game?.title} -{" "}
|
{op.title} - {op.wouldPlay ? "Would Play" : "Would Not Play"}
|
||||||
{op.wouldPlay ? "Would Play" : "Would Not Play"}
|
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user