Skip to content

Commit

Permalink
Merge pull request #29 from LearningProcesss/17-bggthingdto-versions-…
Browse files Browse the repository at this point in the history
…deserialization

feat: add thing version deserialization
  • Loading branch information
LearningProcesss authored Jun 19, 2022
2 parents 9877e68 + ba05eb2 commit a78a2b7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/dto/concrete/BggThingDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { JsonAlias, JsonClassType, JsonDeserialize, JsonIgnoreProperties, JsonMa
import { IBggDto } from "../interface";
import { BggPollDto } from "./subdto/BggPollDto";
import { BggStatisticsPaginatedDto, BggThingVideoPaginatedDto, BggThingCommentPaginatedDto} from "./paginated";
import { BggLinkDto, BggThingMarketlistingsDto } from "./subdto";
import { BggLinkDto, BggThingMarketlistingsDto, BggThingVersionDto } from "./subdto";

@JsonIgnoreProperties({ value: ['versions'] })
export class BggThingDto implements IBggDto {

@JsonProperty()
Expand Down Expand Up @@ -132,4 +131,13 @@ export class BggThingDto implements IBggDto {
@JsonManagedReference()
@JsonAlias({ values: ["poll"] })
polls!: BggPollDto[]

@JsonProperty()
@JsonClassType({ type: () => [Array, [BggThingVersionDto]] })
@JsonManagedReference()
@JsonDeserialize({
//eslint-disable-next-line @typescript-eslint/no-explicit-any
using: (items: any[]) => items[0].item
})
versions!: BggThingVersionDto[];
}
81 changes: 81 additions & 0 deletions src/dto/concrete/subdto/BggThingVersionDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { JsonAlias, JsonClassType, JsonDeserialize, JsonManagedReference, JsonProperty } from "jackson-js";
import { BggLinkDto } from ".";


export class BggThingVersionDto {

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonAlias({ values: ["@_type"] })
type!: string;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_id"] })
id!: number;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonAlias({ values: ["thumbnail"] })
thumbnail!: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonAlias({ values: ["image"] })
image!: string;

@JsonProperty()
@JsonClassType({ type: () => [Array, [BggLinkDto]] })
@JsonManagedReference()
@JsonAlias({ values: ["link"] })
links!: BggLinkDto[]

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
name!: string;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
yearpublished!: number;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
productcode!: string;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
width!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
length!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
depth!: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['@_value'])[0]
})
weight!: number;
}
3 changes: 2 additions & 1 deletion src/dto/concrete/subdto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { BggLinkDto } from './BggLinkDto';
export { BggPlaysPlayDto } from './BggPlaySubDtos';
export { BggCollectionItemDto } from './BggCollectionItemDto';
export { BggPollDto } from './BggPollDto';
export { BggSearchItemDto } from './BggSearchItemDto';
export { BggSearchItemDto } from './BggSearchItemDto';
export { BggThingVersionDto } from './BggThingVersionDto';
2 changes: 1 addition & 1 deletion test/unit/utils/reflection/reflectionexport.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[["BggArticleDto",["id","username","body","subject","numedits","editdate","postdate","link"]],["BggCollectionDto",["id","totalitems","pubdate","items"]],["BggFamilyDto",["name","description","thumbnail","image","id","type","things"]],["BggForumDto",["id","lastpostdate","noposting","numthreads","numposts","title","threads"]],["BggForumThreadDto",["id","numarticles","subject","author","postdate","lastpostdate"]],["BggForumlistDto",["id","type","forums"]],["BggForumlistForumDto",["id","groupid","lastpostdate","noposting","numthreads","numposts","title","description"]],["BggGuildDto",["id","name","created","category","website","manager","description","members"]],["BggGuildMemberDto",["name","date"]],["BggGuildMemeberDto",["name","date"]],["BggPlayDto",["id","userid","total","page","username","plays"]],["BggSearchDto",["id","total","items"]],["BggThingDto",["id","name","type","description","thumbnail","image","yearpublished","minplayers","maxplayers","playingtime","minplaytime","maxplaytime","minage","links","statistics","videos","comments","marketplacelistings","polls"]],["BggThreadDto",["id","link","numarticles","subject","articles"]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating","marketrating"]],["index",[]],["BggStatisticsPaginatedDto",["page","ratings"]],["BggStatisticsRatingDto",["average","usersrated","bayesaverage","stddev","median","owned","trading","wanting","wishing","numcomments","numweights","averageweight","ranks"]],["BggStatisticsRatingRanksDto",["type","id","name","friendlyname","value","bayesaverage"]],["BggThingCommentDto",["value","username","rating"]],["BggThingCommentPaginatedDto",["page","totalitems","items"]],["BggThingVideoDto",["category","language","link","postdate","title","username","id","userid"]],["BggThingVideoPaginatedDto",["total","items"]],["BggCollectionItemDto",["objectid","collid","objecttype","subtype","yearpublished","numplays","image","thumbnail","comment","wishlistcomment","name","originalname","status"]],["BggCollectionItemStatusDto",["own","prevowned","fortrade","want","wanttoplay","wanttobuy","wishlist","wishlistpriority","preordered","lastmodified"]],["BggLinkDto",["id","type","value","inbound"]],["BggPlaySubDtos",["id","userid","date","quantity","length","incomplete","nowinstats","location","item","players"]],["BggPlaysPlayItemDto",["name","objecttype","objectid","subtypes"]],["BggPlaysPlayItemSubtypes",["value"]],["BggPlaysPlayPlayerDto",["color","name","new","rating","score","startposition","userid","username","win"]],["BggPollDto",["name","title","totalvotes","results"]],["BggPollResultDto",["numplayers","resultItemList"]],["BggPollResultItemDto",["level","value","numvotes"]],["BggSearchItemDto",["id","type","name","yearpublished"]],["BggThingMarketlistingsDto",["condition","link","listdate","notes","price"]]]
[["BggArticleDto",["id","username","body","subject","numedits","editdate","postdate","link"]],["BggCollectionDto",["id","totalitems","pubdate","items"]],["BggFamilyDto",["name","description","thumbnail","image","id","type","things"]],["BggForumDto",["id","lastpostdate","noposting","numthreads","numposts","title","threads"]],["BggForumThreadDto",["id","numarticles","subject","author","postdate","lastpostdate"]],["BggForumlistDto",["id","type","forums"]],["BggForumlistForumDto",["id","groupid","lastpostdate","noposting","numthreads","numposts","title","description"]],["BggGuildDto",["id","name","created","category","website","manager","description","members"]],["BggGuildMemberDto",["name","date"]],["BggGuildMemeberDto",["name","date"]],["BggPlayDto",["id","userid","total","page","username","plays"]],["BggSearchDto",["id","total","items"]],["BggThingDto",["id","name","type","description","thumbnail","image","yearpublished","minplayers","maxplayers","playingtime","minplaytime","maxplaytime","minage","links","statistics","videos","comments","marketplacelistings","polls","versions"]],["BggThreadDto",["id","link","numarticles","subject","articles"]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating","marketrating"]],["index",[]],["BggStatisticsPaginatedDto",["page","ratings"]],["BggStatisticsRatingDto",["average","usersrated","bayesaverage","stddev","median","owned","trading","wanting","wishing","numcomments","numweights","averageweight","ranks"]],["BggStatisticsRatingRanksDto",["type","id","name","friendlyname","value","bayesaverage"]],["BggThingCommentDto",["value","username","rating"]],["BggThingCommentPaginatedDto",["page","totalitems","items"]],["BggThingVideoDto",["category","language","link","postdate","title","username","id","userid"]],["BggThingVideoPaginatedDto",["total","items"]],["BggCollectionItemDto",["objectid","collid","objecttype","subtype","yearpublished","numplays","image","thumbnail","comment","wishlistcomment","name","originalname","status"]],["BggCollectionItemStatusDto",["own","prevowned","fortrade","want","wanttoplay","wanttobuy","wishlist","wishlistpriority","preordered","lastmodified"]],["BggLinkDto",["id","type","value","inbound"]],["BggPlaySubDtos",["id","userid","date","quantity","length","incomplete","nowinstats","location","item","players"]],["BggPlaysPlayItemDto",["name","objecttype","objectid","subtypes"]],["BggPlaysPlayItemSubtypes",["value"]],["BggPlaysPlayPlayerDto",["color","name","new","rating","score","startposition","userid","username","win"]],["BggPollDto",["name","title","totalvotes","results"]],["BggPollResultDto",["numplayers","resultItemList"]],["BggPollResultItemDto",["level","value","numvotes"]],["BggSearchItemDto",["id","type","name","yearpublished"]],["BggThingMarketlistingsDto",["condition","link","listdate","notes","price"]],["BggThingVersionDto",["type","id","thumbnail","image","links","name","yearpublished","productcode","width","length","depth","weight"]]]

0 comments on commit a78a2b7

Please sign in to comment.