Skip to content

Commit 9af57c9

Browse files
committed
feat: migrate SetPictureCopyrights to gRPC API
1 parent d96d414 commit 9af57c9

File tree

4 files changed

+229
-28
lines changed

4 files changed

+229
-28
lines changed

src/app/moder/items/item/name/name.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {map, switchMap} from 'rxjs/operators';
99

1010
export interface ItemLanguage {
1111
fullText: null | string;
12-
fullTextId: null | string;
12+
fullTextId: null | number;
1313
language: string;
1414
name: null | string;
1515
text: null | string;
16-
textId: null | string;
16+
textId: null | number;
1717
}
1818

1919
@Component({
@@ -62,11 +62,11 @@ export class ModerItemsItemNameComponent {
6262
for (const value of items ? items : []) {
6363
languages.set(value.language, {
6464
fullText: value.fullText,
65-
fullTextId: value.fullTextId === '0' ? null : value.fullTextId,
65+
fullTextId: value.fullTextId === 0 ? null : value.fullTextId,
6666
language: value.language,
6767
name: value.name,
6868
text: value.text,
69-
textId: value.textId === '0' ? null : value.textId,
69+
textId: value.textId === 0 ? null : value.textId,
7070
});
7171
}
7272

src/app/moder/pictures/item/item.component.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ItemRequest,
1212
ItemType,
1313
PictureIDRequest,
14+
SetPictureCopyrightsRequest,
1415
SetPictureItemItemIDRequest,
1516
SetPictureItemPerspectiveRequest,
1617
UpdatePictureRequest,
@@ -342,16 +343,21 @@ export class ModerPicturesItemComponent {
342343
protected saveCopyrights(picture: APIPicture) {
343344
this.copyrightsLoading = true;
344345

345-
this.api
346-
.request<void>('PUT', 'picture/' + picture.id, {
347-
body: {
346+
this.picturesClient
347+
.setPictureCopyrights(
348+
new SetPictureCopyrightsRequest({
348349
copyrights: picture.copyrights,
349-
},
350-
})
351-
.subscribe({
352-
error: () => {
350+
id: picture.id + '',
351+
}),
352+
)
353+
.pipe(
354+
catchError((error: unknown) => {
353355
this.copyrightsLoading = false;
354-
},
356+
this.toastService.handleError(error);
357+
return EMPTY;
358+
}),
359+
)
360+
.subscribe({
355361
next: () => {
356362
this.copyrightsLoading = false;
357363
},

src/grpc/spec.pb.ts

Lines changed: 174 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25325,6 +25325,164 @@ export module UpdatePictureRequest {
2532525325
}
2532625326
}
2532725327

25328+
/**
25329+
* Message implementation for goautowp.SetPictureCopyrightsRequest
25330+
*/
25331+
export class SetPictureCopyrightsRequest implements GrpcMessage {
25332+
static id = 'goautowp.SetPictureCopyrightsRequest';
25333+
25334+
/**
25335+
* Deserialize binary data to message
25336+
* @param instance message instance
25337+
*/
25338+
static deserializeBinary(bytes: ByteSource) {
25339+
const instance = new SetPictureCopyrightsRequest();
25340+
SetPictureCopyrightsRequest.deserializeBinaryFromReader(
25341+
instance,
25342+
new BinaryReader(bytes)
25343+
);
25344+
return instance;
25345+
}
25346+
25347+
/**
25348+
* Check all the properties and set default protobuf values if necessary
25349+
* @param _instance message instance
25350+
*/
25351+
static refineValues(_instance: SetPictureCopyrightsRequest) {
25352+
_instance.id = _instance.id || '0';
25353+
_instance.copyrights = _instance.copyrights || '';
25354+
}
25355+
25356+
/**
25357+
* Deserializes / reads binary message into message instance using provided binary reader
25358+
* @param _instance message instance
25359+
* @param _reader binary reader instance
25360+
*/
25361+
static deserializeBinaryFromReader(
25362+
_instance: SetPictureCopyrightsRequest,
25363+
_reader: BinaryReader
25364+
) {
25365+
while (_reader.nextField()) {
25366+
if (_reader.isEndGroup()) break;
25367+
25368+
switch (_reader.getFieldNumber()) {
25369+
case 1:
25370+
_instance.id = _reader.readInt64String();
25371+
break;
25372+
case 2:
25373+
_instance.copyrights = _reader.readString();
25374+
break;
25375+
default:
25376+
_reader.skipField();
25377+
}
25378+
}
25379+
25380+
SetPictureCopyrightsRequest.refineValues(_instance);
25381+
}
25382+
25383+
/**
25384+
* Serializes a message to binary format using provided binary reader
25385+
* @param _instance message instance
25386+
* @param _writer binary writer instance
25387+
*/
25388+
static serializeBinaryToWriter(
25389+
_instance: SetPictureCopyrightsRequest,
25390+
_writer: BinaryWriter
25391+
) {
25392+
if (_instance.id) {
25393+
_writer.writeInt64String(1, _instance.id);
25394+
}
25395+
if (_instance.copyrights) {
25396+
_writer.writeString(2, _instance.copyrights);
25397+
}
25398+
}
25399+
25400+
private _id: string;
25401+
private _copyrights: string;
25402+
25403+
/**
25404+
* Message constructor. Initializes the properties and applies default Protobuf values if necessary
25405+
* @param _value initial values object or instance of SetPictureCopyrightsRequest to deeply clone from
25406+
*/
25407+
constructor(_value?: RecursivePartial<SetPictureCopyrightsRequest.AsObject>) {
25408+
_value = _value || {};
25409+
this.id = _value.id;
25410+
this.copyrights = _value.copyrights;
25411+
SetPictureCopyrightsRequest.refineValues(this);
25412+
}
25413+
get id(): string {
25414+
return this._id;
25415+
}
25416+
set id(value: string) {
25417+
this._id = value;
25418+
}
25419+
get copyrights(): string {
25420+
return this._copyrights;
25421+
}
25422+
set copyrights(value: string) {
25423+
this._copyrights = value;
25424+
}
25425+
25426+
/**
25427+
* Serialize message to binary data
25428+
* @param instance message instance
25429+
*/
25430+
serializeBinary() {
25431+
const writer = new BinaryWriter();
25432+
SetPictureCopyrightsRequest.serializeBinaryToWriter(this, writer);
25433+
return writer.getResultBuffer();
25434+
}
25435+
25436+
/**
25437+
* Cast message to standard JavaScript object (all non-primitive values are deeply cloned)
25438+
*/
25439+
toObject(): SetPictureCopyrightsRequest.AsObject {
25440+
return {
25441+
id: this.id,
25442+
copyrights: this.copyrights
25443+
};
25444+
}
25445+
25446+
/**
25447+
* Convenience method to support JSON.stringify(message), replicates the structure of toObject()
25448+
*/
25449+
toJSON() {
25450+
return this.toObject();
25451+
}
25452+
25453+
/**
25454+
* Cast message to JSON using protobuf JSON notation: https://developers.google.com/protocol-buffers/docs/proto3#json
25455+
* Attention: output differs from toObject() e.g. enums are represented as names and not as numbers, Timestamp is an ISO Date string format etc.
25456+
* If the message itself or some of descendant messages is google.protobuf.Any, you MUST provide a message pool as options. If not, the messagePool is not required
25457+
*/
25458+
toProtobufJSON(
25459+
// @ts-ignore
25460+
options?: ToProtobufJSONOptions
25461+
): SetPictureCopyrightsRequest.AsProtobufJSON {
25462+
return {
25463+
id: this.id,
25464+
copyrights: this.copyrights
25465+
};
25466+
}
25467+
}
25468+
export module SetPictureCopyrightsRequest {
25469+
/**
25470+
* Standard JavaScript object representation for SetPictureCopyrightsRequest
25471+
*/
25472+
export interface AsObject {
25473+
id: string;
25474+
copyrights: string;
25475+
}
25476+
25477+
/**
25478+
* Protobuf JSON representation for SetPictureCopyrightsRequest
25479+
*/
25480+
export interface AsProtobufJSON {
25481+
id: string;
25482+
copyrights: string;
25483+
}
25484+
}
25485+
2532825486
/**
2532925487
* Message implementation for goautowp.DeleteSimilarRequest
2533025488
*/
@@ -32522,9 +32680,9 @@ export class ItemLanguage implements GrpcMessage {
3252232680
_instance.itemId = _instance.itemId || '0';
3252332681
_instance.language = _instance.language || '';
3252432682
_instance.name = _instance.name || '';
32525-
_instance.textId = _instance.textId || '0';
32683+
_instance.textId = _instance.textId || 0;
3252632684
_instance.text = _instance.text || '';
32527-
_instance.fullTextId = _instance.fullTextId || '0';
32685+
_instance.fullTextId = _instance.fullTextId || 0;
3252832686
_instance.fullText = _instance.fullText || '';
3252932687
}
3253032688

@@ -32551,13 +32709,13 @@ export class ItemLanguage implements GrpcMessage {
3255132709
_instance.name = _reader.readString();
3255232710
break;
3255332711
case 4:
32554-
_instance.textId = _reader.readInt64String();
32712+
_instance.textId = _reader.readInt32();
3255532713
break;
3255632714
case 5:
3255732715
_instance.text = _reader.readString();
3255832716
break;
3255932717
case 6:
32560-
_instance.fullTextId = _reader.readInt64String();
32718+
_instance.fullTextId = _reader.readInt32();
3256132719
break;
3256232720
case 7:
3256332721
_instance.fullText = _reader.readString();
@@ -32589,13 +32747,13 @@ export class ItemLanguage implements GrpcMessage {
3258932747
_writer.writeString(3, _instance.name);
3259032748
}
3259132749
if (_instance.textId) {
32592-
_writer.writeInt64String(4, _instance.textId);
32750+
_writer.writeInt32(4, _instance.textId);
3259332751
}
3259432752
if (_instance.text) {
3259532753
_writer.writeString(5, _instance.text);
3259632754
}
3259732755
if (_instance.fullTextId) {
32598-
_writer.writeInt64String(6, _instance.fullTextId);
32756+
_writer.writeInt32(6, _instance.fullTextId);
3259932757
}
3260032758
if (_instance.fullText) {
3260132759
_writer.writeString(7, _instance.fullText);
@@ -32605,9 +32763,9 @@ export class ItemLanguage implements GrpcMessage {
3260532763
private _itemId: string;
3260632764
private _language: string;
3260732765
private _name: string;
32608-
private _textId: string;
32766+
private _textId: number;
3260932767
private _text: string;
32610-
private _fullTextId: string;
32768+
private _fullTextId: number;
3261132769
private _fullText: string;
3261232770

3261332771
/**
@@ -32643,10 +32801,10 @@ export class ItemLanguage implements GrpcMessage {
3264332801
set name(value: string) {
3264432802
this._name = value;
3264532803
}
32646-
get textId(): string {
32804+
get textId(): number {
3264732805
return this._textId;
3264832806
}
32649-
set textId(value: string) {
32807+
set textId(value: number) {
3265032808
this._textId = value;
3265132809
}
3265232810
get text(): string {
@@ -32655,10 +32813,10 @@ export class ItemLanguage implements GrpcMessage {
3265532813
set text(value: string) {
3265632814
this._text = value;
3265732815
}
32658-
get fullTextId(): string {
32816+
get fullTextId(): number {
3265932817
return this._fullTextId;
3266032818
}
32661-
set fullTextId(value: string) {
32819+
set fullTextId(value: number) {
3266232820
this._fullTextId = value;
3266332821
}
3266432822
get fullText(): string {
@@ -32728,9 +32886,9 @@ export module ItemLanguage {
3272832886
itemId: string;
3272932887
language: string;
3273032888
name: string;
32731-
textId: string;
32889+
textId: number;
3273232890
text: string;
32733-
fullTextId: string;
32891+
fullTextId: number;
3273432892
fullText: string;
3273532893
}
3273632894

@@ -32741,9 +32899,9 @@ export module ItemLanguage {
3274132899
itemId: string;
3274232900
language: string;
3274332901
name: string;
32744-
textId: string;
32902+
textId: number;
3274532903
text: string;
32746-
fullTextId: string;
32904+
fullTextId: number;
3274732905
fullText: string;
3274832906
}
3274932907
}

src/grpc/spec.pbsc.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,6 +3970,27 @@ export class PicturesClient {
39703970
requestClass: thisProto.UpdatePictureRequest,
39713971
responseClass: googleProtobuf001.Empty
39723972
});
3973+
},
3974+
/**
3975+
* Unary call: /goautowp.Pictures/SetPictureCopyrights
3976+
*
3977+
* @param requestMessage Request message
3978+
* @param requestMetadata Request metadata
3979+
* @returns Observable<GrpcEvent<googleProtobuf001.Empty>>
3980+
*/
3981+
setPictureCopyrights: (
3982+
requestData: thisProto.SetPictureCopyrightsRequest,
3983+
requestMetadata = new GrpcMetadata()
3984+
): Observable<GrpcEvent<googleProtobuf001.Empty>> => {
3985+
return this.handler.handle({
3986+
type: GrpcCallType.unary,
3987+
client: this.client,
3988+
path: '/goautowp.Pictures/SetPictureCopyrights',
3989+
requestData,
3990+
requestMetadata,
3991+
requestClass: thisProto.SetPictureCopyrightsRequest,
3992+
responseClass: googleProtobuf001.Empty
3993+
});
39733994
}
39743995
};
39753996

@@ -4316,6 +4337,22 @@ export class PicturesClient {
43164337
.updatePicture(requestData, requestMetadata)
43174338
.pipe(throwStatusErrors(), takeMessages());
43184339
}
4340+
4341+
/**
4342+
* Unary call @/goautowp.Pictures/SetPictureCopyrights
4343+
*
4344+
* @param requestMessage Request message
4345+
* @param requestMetadata Request metadata
4346+
* @returns Observable<googleProtobuf001.Empty>
4347+
*/
4348+
setPictureCopyrights(
4349+
requestData: thisProto.SetPictureCopyrightsRequest,
4350+
requestMetadata = new GrpcMetadata()
4351+
): Observable<googleProtobuf001.Empty> {
4352+
return this.$raw
4353+
.setPictureCopyrights(requestData, requestMetadata)
4354+
.pipe(throwStatusErrors(), takeMessages());
4355+
}
43194356
}
43204357
/**
43214358
* Service client implementation for goautowp.Messaging

0 commit comments

Comments
 (0)