Skip to content

Commit ea1b2b0

Browse files
committed
feat: Set PictureItem ItemID via gRPC
1 parent d235a7b commit ea1b2b0

File tree

7 files changed

+281
-30
lines changed

7 files changed

+281
-30
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {HttpErrorResponse} from '@angular/common/http';
22
import {Component, OnInit} from '@angular/core';
33
import {ActivatedRoute, Router} from '@angular/router';
4-
import {APIGetItemVehicleTypesRequest, ItemType} from '@grpc/spec.pb';
5-
import {ItemsClient} from '@grpc/spec.pbsc';
4+
import {APIGetItemVehicleTypesRequest, ItemType, SetPictureItemItemIDRequest} from '@grpc/spec.pb';
5+
import {ItemsClient, PicturesClient} from '@grpc/spec.pbsc';
66
import {APIService} from '@services/api.service';
77
import {APIItem, ItemService} from '@services/item';
88
import {PageEnvService} from '@services/page-env.service';
@@ -107,6 +107,7 @@ export class ModerItemsItemPicturesOrganizeComponent implements OnInit {
107107
private readonly pictureItemService: PictureItemService,
108108
private readonly pageEnv: PageEnvService,
109109
private readonly itemsClient: ItemsClient,
110+
private readonly picturesClient: PicturesClient,
110111
) {}
111112

112113
ngOnInit(): void {
@@ -180,11 +181,16 @@ export class ModerItemsItemPicturesOrganizeComponent implements OnInit {
180181
...pictures
181182
.filter((p) => event.pictures.includes(p.picture_id))
182183
.map((picture) =>
183-
this.api.request<void>(
184-
'PUT',
185-
'picture-item/' + picture.picture_id + '/' + picture.item_id + '/' + picture.type,
186-
{body: {item_id: newItem.id}},
187-
),
184+
this.picturesClient
185+
.setPictureItemItemID(
186+
new SetPictureItemItemIDRequest({
187+
itemId: '' + picture.item_id,
188+
newItemId: '' + newItem.id,
189+
pictureId: '' + picture.picture_id,
190+
type: picture.type,
191+
}),
192+
)
193+
.pipe(map(() => void 0)),
188194
),
189195
);
190196

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ <h1 i18n>Picture №{{ id }}</h1>
168168
<div class="dropdown-menu" ngbDropdownMenu>
169169
<button
170170
class="dropdown-item"
171-
(click)="moveItem(picture.id, item.type, item.item_id, lastItem.item.id)"
171+
(click)="moveItem(picture.id + '', item.type, item.item_id + '', lastItem.item.id)"
172172
*ngIf="lastItem.item && !lastItem.hasItem"
173173
>
174174
<i class="bi bi-arrow-right" aria-hidden="true"></i>

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ItemRequest,
99
ItemType,
1010
PictureIDRequest,
11+
SetPictureItemItemIDRequest,
1112
SetPictureItemPerspectiveRequest,
1213
} from '@grpc/spec.pb';
1314
import {APIItem} from '@grpc/spec.pb';
@@ -268,18 +269,27 @@ export class ModerPicturesItemComponent {
268269
});
269270
}
270271

271-
protected moveItem(id: number, type: number, srcItemId: number, dstItemId: string) {
272+
protected moveItem(id: string, type: number, srcItemId: string, dstItemId: string) {
272273
this.pictureItemLoading = true;
273-
this.pictureItemService.changeItem$(id, type, srcItemId, dstItemId).subscribe({
274-
error: () => {
275-
this.pictureItemLoading = false;
276-
},
277-
next: () => {
278-
localStorage.setItem('last_item', dstItemId.toString());
279-
this.change$.next();
280-
this.pictureItemLoading = false;
281-
},
282-
});
274+
this.picturesClient
275+
.setPictureItemItemID(
276+
new SetPictureItemItemIDRequest({
277+
itemId: '' + srcItemId,
278+
newItemId: dstItemId,
279+
pictureId: '' + id,
280+
type: type,
281+
}),
282+
)
283+
.subscribe({
284+
error: () => {
285+
this.pictureItemLoading = false;
286+
},
287+
next: () => {
288+
localStorage.setItem('last_item', dstItemId);
289+
this.change$.next();
290+
this.pictureItemLoading = false;
291+
},
292+
});
283293
}
284294

285295
protected saveSpecialName(picture: APIPicture) {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ListItemsRequest,
99
Pages,
1010
PictureItemType,
11+
SetPictureItemItemIDRequest,
1112
SetPictureItemPerspectiveRequest,
1213
} from '@grpc/spec.pb';
1314
import {ItemsClient, PicturesClient} from '@grpc/spec.pbsc';
@@ -357,8 +358,15 @@ export class ModerPicturesItemMoveComponent implements OnInit {
357358
const dstPerspectiveID = selection.perspectiveId;
358359

359360
if (srcItemID && srcType) {
360-
this.pictureItemService
361-
.changeItem$(id, srcType, srcItemID, dstItemID)
361+
this.picturesClient
362+
.setPictureItemItemID(
363+
new SetPictureItemItemIDRequest({
364+
itemId: '' + srcItemID,
365+
newItemId: dstItemID,
366+
pictureId: '' + id,
367+
type: srcType,
368+
}),
369+
)
362370
.pipe(
363371
switchMap(() => {
364372
if (!dstPerspectiveID) {

src/app/services/picture-item.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ export class PictureItemService {
5151
return this.api.request<void>('DELETE', 'picture-item/' + pictureId + '/' + itemId + '/' + type);
5252
}
5353

54-
public changeItem$(pictureId: number, type: number, srcItemId: number, dstItemId: string): Observable<void> {
55-
const url = 'picture-item/' + pictureId + '/' + srcItemId + '/' + type;
56-
return this.api.request<void>('PUT', url, {
57-
body: {
58-
item_id: dstItemId,
59-
},
60-
});
61-
}
62-
6354
public get$(
6455
pictureId: number,
6556
itemId: number,

src/grpc/spec.pb.ts

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24322,6 +24322,205 @@ export module SetPictureItemPerspectiveRequest {
2432224322
}
2432324323
}
2432424324

24325+
/**
24326+
* Message implementation for goautowp.SetPictureItemItemIDRequest
24327+
*/
24328+
export class SetPictureItemItemIDRequest implements GrpcMessage {
24329+
static id = 'goautowp.SetPictureItemItemIDRequest';
24330+
24331+
/**
24332+
* Deserialize binary data to message
24333+
* @param instance message instance
24334+
*/
24335+
static deserializeBinary(bytes: ByteSource) {
24336+
const instance = new SetPictureItemItemIDRequest();
24337+
SetPictureItemItemIDRequest.deserializeBinaryFromReader(
24338+
instance,
24339+
new BinaryReader(bytes)
24340+
);
24341+
return instance;
24342+
}
24343+
24344+
/**
24345+
* Check all the properties and set default protobuf values if necessary
24346+
* @param _instance message instance
24347+
*/
24348+
static refineValues(_instance: SetPictureItemItemIDRequest) {
24349+
_instance.pictureId = _instance.pictureId || '0';
24350+
_instance.itemId = _instance.itemId || '0';
24351+
_instance.type = _instance.type || 0;
24352+
_instance.newItemId = _instance.newItemId || '0';
24353+
}
24354+
24355+
/**
24356+
* Deserializes / reads binary message into message instance using provided binary reader
24357+
* @param _instance message instance
24358+
* @param _reader binary reader instance
24359+
*/
24360+
static deserializeBinaryFromReader(
24361+
_instance: SetPictureItemItemIDRequest,
24362+
_reader: BinaryReader
24363+
) {
24364+
while (_reader.nextField()) {
24365+
if (_reader.isEndGroup()) break;
24366+
24367+
switch (_reader.getFieldNumber()) {
24368+
case 1:
24369+
_instance.pictureId = _reader.readInt64String();
24370+
break;
24371+
case 2:
24372+
_instance.itemId = _reader.readInt64String();
24373+
break;
24374+
case 3:
24375+
_instance.type = _reader.readEnum();
24376+
break;
24377+
case 4:
24378+
_instance.newItemId = _reader.readInt64String();
24379+
break;
24380+
default:
24381+
_reader.skipField();
24382+
}
24383+
}
24384+
24385+
SetPictureItemItemIDRequest.refineValues(_instance);
24386+
}
24387+
24388+
/**
24389+
* Serializes a message to binary format using provided binary reader
24390+
* @param _instance message instance
24391+
* @param _writer binary writer instance
24392+
*/
24393+
static serializeBinaryToWriter(
24394+
_instance: SetPictureItemItemIDRequest,
24395+
_writer: BinaryWriter
24396+
) {
24397+
if (_instance.pictureId) {
24398+
_writer.writeInt64String(1, _instance.pictureId);
24399+
}
24400+
if (_instance.itemId) {
24401+
_writer.writeInt64String(2, _instance.itemId);
24402+
}
24403+
if (_instance.type) {
24404+
_writer.writeEnum(3, _instance.type);
24405+
}
24406+
if (_instance.newItemId) {
24407+
_writer.writeInt64String(4, _instance.newItemId);
24408+
}
24409+
}
24410+
24411+
private _pictureId: string;
24412+
private _itemId: string;
24413+
private _type: PictureItemType;
24414+
private _newItemId: string;
24415+
24416+
/**
24417+
* Message constructor. Initializes the properties and applies default Protobuf values if necessary
24418+
* @param _value initial values object or instance of SetPictureItemItemIDRequest to deeply clone from
24419+
*/
24420+
constructor(_value?: RecursivePartial<SetPictureItemItemIDRequest.AsObject>) {
24421+
_value = _value || {};
24422+
this.pictureId = _value.pictureId;
24423+
this.itemId = _value.itemId;
24424+
this.type = _value.type;
24425+
this.newItemId = _value.newItemId;
24426+
SetPictureItemItemIDRequest.refineValues(this);
24427+
}
24428+
get pictureId(): string {
24429+
return this._pictureId;
24430+
}
24431+
set pictureId(value: string) {
24432+
this._pictureId = value;
24433+
}
24434+
get itemId(): string {
24435+
return this._itemId;
24436+
}
24437+
set itemId(value: string) {
24438+
this._itemId = value;
24439+
}
24440+
get type(): PictureItemType {
24441+
return this._type;
24442+
}
24443+
set type(value: PictureItemType) {
24444+
this._type = value;
24445+
}
24446+
get newItemId(): string {
24447+
return this._newItemId;
24448+
}
24449+
set newItemId(value: string) {
24450+
this._newItemId = value;
24451+
}
24452+
24453+
/**
24454+
* Serialize message to binary data
24455+
* @param instance message instance
24456+
*/
24457+
serializeBinary() {
24458+
const writer = new BinaryWriter();
24459+
SetPictureItemItemIDRequest.serializeBinaryToWriter(this, writer);
24460+
return writer.getResultBuffer();
24461+
}
24462+
24463+
/**
24464+
* Cast message to standard JavaScript object (all non-primitive values are deeply cloned)
24465+
*/
24466+
toObject(): SetPictureItemItemIDRequest.AsObject {
24467+
return {
24468+
pictureId: this.pictureId,
24469+
itemId: this.itemId,
24470+
type: this.type,
24471+
newItemId: this.newItemId
24472+
};
24473+
}
24474+
24475+
/**
24476+
* Convenience method to support JSON.stringify(message), replicates the structure of toObject()
24477+
*/
24478+
toJSON() {
24479+
return this.toObject();
24480+
}
24481+
24482+
/**
24483+
* Cast message to JSON using protobuf JSON notation: https://developers.google.com/protocol-buffers/docs/proto3#json
24484+
* Attention: output differs from toObject() e.g. enums are represented as names and not as numbers, Timestamp is an ISO Date string format etc.
24485+
* 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
24486+
*/
24487+
toProtobufJSON(
24488+
// @ts-ignore
24489+
options?: ToProtobufJSONOptions
24490+
): SetPictureItemItemIDRequest.AsProtobufJSON {
24491+
return {
24492+
pictureId: this.pictureId,
24493+
itemId: this.itemId,
24494+
type:
24495+
PictureItemType[
24496+
this.type === null || this.type === undefined ? 0 : this.type
24497+
],
24498+
newItemId: this.newItemId
24499+
};
24500+
}
24501+
}
24502+
export module SetPictureItemItemIDRequest {
24503+
/**
24504+
* Standard JavaScript object representation for SetPictureItemItemIDRequest
24505+
*/
24506+
export interface AsObject {
24507+
pictureId: string;
24508+
itemId: string;
24509+
type: PictureItemType;
24510+
newItemId: string;
24511+
}
24512+
24513+
/**
24514+
* Protobuf JSON representation for SetPictureItemItemIDRequest
24515+
*/
24516+
export interface AsProtobufJSON {
24517+
pictureId: string;
24518+
itemId: string;
24519+
type: string;
24520+
newItemId: string;
24521+
}
24522+
}
24523+
2432524524
/**
2432624525
* Message implementation for goautowp.DeleteSimilarRequest
2432724526
*/

src/grpc/spec.pbsc.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,6 +3821,27 @@ export class PicturesClient {
38213821
requestClass: thisProto.SetPictureItemPerspectiveRequest,
38223822
responseClass: googleProtobuf001.Empty
38233823
});
3824+
},
3825+
/**
3826+
* Unary call: /goautowp.Pictures/SetPictureItemItemID
3827+
*
3828+
* @param requestMessage Request message
3829+
* @param requestMetadata Request metadata
3830+
* @returns Observable<GrpcEvent<googleProtobuf001.Empty>>
3831+
*/
3832+
setPictureItemItemID: (
3833+
requestData: thisProto.SetPictureItemItemIDRequest,
3834+
requestMetadata = new GrpcMetadata()
3835+
): Observable<GrpcEvent<googleProtobuf001.Empty>> => {
3836+
return this.handler.handle({
3837+
type: GrpcCallType.unary,
3838+
client: this.client,
3839+
path: '/goautowp.Pictures/SetPictureItemItemID',
3840+
requestData,
3841+
requestMetadata,
3842+
requestClass: thisProto.SetPictureItemItemIDRequest,
3843+
responseClass: googleProtobuf001.Empty
3844+
});
38243845
}
38253846
};
38263847

@@ -4055,6 +4076,22 @@ export class PicturesClient {
40554076
.setPictureItemPerspective(requestData, requestMetadata)
40564077
.pipe(throwStatusErrors(), takeMessages());
40574078
}
4079+
4080+
/**
4081+
* Unary call @/goautowp.Pictures/SetPictureItemItemID
4082+
*
4083+
* @param requestMessage Request message
4084+
* @param requestMetadata Request metadata
4085+
* @returns Observable<googleProtobuf001.Empty>
4086+
*/
4087+
setPictureItemItemID(
4088+
requestData: thisProto.SetPictureItemItemIDRequest,
4089+
requestMetadata = new GrpcMetadata()
4090+
): Observable<googleProtobuf001.Empty> {
4091+
return this.$raw
4092+
.setPictureItemItemID(requestData, requestMetadata)
4093+
.pipe(throwStatusErrors(), takeMessages());
4094+
}
40584095
}
40594096
/**
40604097
* Service client implementation for goautowp.Messaging

0 commit comments

Comments
 (0)