diff --git a/docs/mammon-api.yml b/docs/mammon-api.yml new file mode 100644 index 0000000..f3de671 --- /dev/null +++ b/docs/mammon-api.yml @@ -0,0 +1,365 @@ +openapi: 3.1.0 +info: + title: OpenAPI definition + version: v0 +servers: +- url: http://localhost:8080 + description: Generated server url +paths: + /ledgers/main/{ledgerId}: + put: + tags: + - ledger-controller + operationId: updateMainLedger + parameters: + - name: ledgerId + in: path + required: true + schema: + type: string + format: uuid + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateMainLedgerRequest" + required: true + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/MainLedgerResponse" + /ledgers/combined/{ledgerId}: + put: + tags: + - ledger-controller + operationId: updateCombinedLedger + parameters: + - name: ledgerId + in: path + required: true + schema: + type: string + format: uuid + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/UpdateCombinedLedgerRequest" + required: true + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/CombinedLedgerResponse" + /ledgers/main: + post: + tags: + - ledger-controller + operationId: createMainLedger + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/CreateMainLedgerRequest" + required: true + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/MainLedgerResponse" + /ledgers/combined: + post: + tags: + - ledger-controller + operationId: createCombinedLedger + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/CreateCombinedLedgerRequest" + required: true + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/CombinedLedgerResponse" + /activity/fetch/{characterId}: + post: + tags: + - activity-controller + operationId: fetchNewActivitiesForCharacter + parameters: + - name: characterId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + /ledgers: + get: + tags: + - ledger-controller + operationId: findAll + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + type: array + items: + oneOf: + - $ref: "#/components/schemas/CombinedLedgerResponse" + - $ref: "#/components/schemas/MainLedgerResponse" + /ledgers/{ledgerId}: + get: + tags: + - ledger-controller + operationId: findById + parameters: + - name: ledgerId + in: path + required: true + schema: + type: string + format: uuid + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + oneOf: + - $ref: "#/components/schemas/CombinedLedgerResponse" + - $ref: "#/components/schemas/MainLedgerResponse" + /characters: + get: + tags: + - character-controller + operationId: getCharacters + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + type: array + items: + $ref: "#/components/schemas/CharacterResponse" + /characters/{characterId}/rule-book: + get: + tags: + - rule-book-controller + operationId: findByCharacterId + parameters: + - name: characterId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "404": + description: Not Found + "400": + description: Bad Request + "200": + description: OK + content: + '*/*': + schema: + $ref: "#/components/schemas/RuleBookResponse" +components: + schemas: + UpdateMainLedgerRequest: + type: object + properties: + name: + type: string + required: + - name + MainLedgerResponse: + allOf: + - $ref: "#/components/schemas/LedgerResponse" + - type: object + properties: + ledgerId: + type: string + format: uuid + name: + type: string + balance: + type: number + type: + type: string + enum: + - MAIN + required: + - balance + - ledgerId + - name + UpdateCombinedLedgerRequest: + type: object + properties: + name: + type: string + memberLedgerIds: + type: array + items: + type: string + format: uuid + required: + - memberLedgerIds + - name + CombinedLedgerResponse: + allOf: + - $ref: "#/components/schemas/LedgerResponse" + - type: object + properties: + ledgerId: + type: string + format: uuid + name: + type: string + balance: + type: number + memberLedgerIds: + type: array + items: + type: string + format: uuid + type: + type: string + enum: + - COMBINED + required: + - balance + - ledgerId + - memberLedgerIds + - name + CreateMainLedgerRequest: + type: object + properties: + name: + type: string + required: + - name + CreateCombinedLedgerRequest: + type: object + properties: + name: + type: string + memberLedgerIds: + type: array + items: + type: string + format: uuid + required: + - memberLedgerIds + - name + LedgerResponse: + type: object + discriminator: + propertyName: type + properties: + type: + type: string + enum: + - MAIN + - COMBINED + CharacterResponse: + type: object + properties: + characterId: + type: integer + format: int64 + name: + type: string + required: + - characterId + - name + RuleBookResponse: + type: object + properties: + characterId: + type: integer + format: int64 + ruleSets: + type: object + additionalProperties: + $ref: "#/components/schemas/RuleSetResponse" + required: + - characterId + - ruleSets + RuleResponse: + type: object + properties: + rate: + type: string + enum: + - NONE + - VALUE + - JITA_BUY + - JITA_SELL + - EVE_ESTIMATE + fromLedgerId: + type: string + format: uuid + toLedgerId: + type: string + format: uuid + required: + - rate + RuleSetResponse: + type: object + properties: + rules: + type: array + items: + $ref: "#/components/schemas/RuleResponse" + required: + - rules diff --git a/src/characters/chartacters.ts b/src/characters/chartacters.ts index 63d4512..32a5f7b 100644 --- a/src/characters/chartacters.ts +++ b/src/characters/chartacters.ts @@ -8,7 +8,15 @@ export type Character = CharacterResponse export const useCharactersStore = defineStore('characters', () => { const characters = ref([]); - const findById = (characterId: number): Character | undefined => characters.value.find(c => c.characterId === characterId); + const findById = async (characterId: number): Promise => { + let character = characters.value.find(c => c.characterId === characterId); + + if (!character) { + await refresh(); // TODO call api instead of refresh + character = characters.value.find(c => c.characterId === characterId); + } + return character; + } const refresh = () => characterControllerApi.getCharacters().then(response => characters.value = response.data); diff --git a/src/formaters.ts b/src/formaters.ts index 8048d63..59129ba 100644 --- a/src/formaters.ts +++ b/src/formaters.ts @@ -11,7 +11,6 @@ export const percentFormater = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }); - const timeFormat = new Intl.NumberFormat("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 0, diff --git a/src/generated/mammon/api.ts b/src/generated/mammon/api.ts index 3c379b5..30078db 100644 --- a/src/generated/mammon/api.ts +++ b/src/generated/mammon/api.ts @@ -83,8 +83,8 @@ export interface RuleBookResponse { } export interface RuleResponse { 'rate': RuleResponseRateEnum; - 'fromLedgerId': string; - 'toLedgerId': string; + 'fromLedgerId'?: string; + 'toLedgerId'?: string; } export const RuleResponseRateEnum = { @@ -736,7 +736,7 @@ export const RuleBookControllerApiAxiosParamCreator = function (configuration?: findByCharacterId: async (characterId: number, options: RawAxiosRequestConfig = {}): Promise => { // verify required parameter 'characterId' is not null or undefined assertParamExists('findByCharacterId', 'characterId', characterId) - const localVarPath = `/rule-books/{characterId}` + const localVarPath = `/characters/{characterId}/rule-book` .replace('{characterId}', encodeURIComponent(String(characterId))); // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); diff --git a/src/ledger/CreateLedgerModal.vue b/src/ledger/CreateLedgerModal.vue index 6508dd5..b11a9d2 100644 --- a/src/ledger/CreateLedgerModal.vue +++ b/src/ledger/CreateLedgerModal.vue @@ -6,6 +6,7 @@ import {isCombined, Ledger, LedgerType, LedgerTypes, useLedgersStore} from "./le import {Modal} from "@/components"; import LedgerLabel from "./LedgerLabel.vue"; import {PlusIcon, TrashIcon} from '@heroicons/vue/24/outline'; +import LedgerSelect from "@/ledger/LedgerSelect.vue"; interface Props { ledgerId?: string; @@ -119,9 +120,7 @@ defineExpose({ open });
- +
diff --git a/src/ledger/LedgerSelect.vue b/src/ledger/LedgerSelect.vue new file mode 100644 index 0000000..ef81af3 --- /dev/null +++ b/src/ledger/LedgerSelect.vue @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/src/ledger/index.ts b/src/ledger/index.ts index c808622..10638d5 100644 --- a/src/ledger/index.ts +++ b/src/ledger/index.ts @@ -1,4 +1,5 @@ export * from './ledger'; export {default as LedgerLabel} from './LedgerLabel.vue'; +export {default as LedgerSelect} from './LedgerSelect.vue'; export {default as CreateLedgerModal} from './CreateLedgerModal.vue'; \ No newline at end of file diff --git a/src/mammon/mammonService.ts b/src/mammon/mammonService.ts index ba051b1..8f527fc 100644 --- a/src/mammon/mammonService.ts +++ b/src/mammon/mammonService.ts @@ -1,6 +1,6 @@ import {logResource} from "@/service"; import axios from "axios"; -import {CharacterControllerApi, LedgerControllerApi} from "@/generated/mammon"; +import {CharacterControllerApi, LedgerControllerApi, RuleBookControllerApi} from "@/generated/mammon"; export const mammonUrl = import.meta.env.VITE_MAMMON_URL; export const mammonAddCharacterUrl = mammonUrl + "oauth2/authorization/esi" @@ -16,3 +16,4 @@ logResource(mammonAxiosInstance) export const ledgerControllerApi = new LedgerControllerApi(undefined, mammonUrl, mammonAxiosInstance); export const characterControllerApi = new CharacterControllerApi(undefined, mammonUrl, mammonAxiosInstance); +export const ruleBookControllerApi = new RuleBookControllerApi(undefined, mammonUrl, mammonAxiosInstance); diff --git a/src/pages/rules/EditRuleBook.vue b/src/pages/rules/EditRuleBook.vue index b30b06f..8c47c93 100644 --- a/src/pages/rules/EditRuleBook.vue +++ b/src/pages/rules/EditRuleBook.vue @@ -1,18 +1,28 @@ + + + + \ No newline at end of file diff --git a/src/rules/RuleSetInput.vue b/src/rules/RuleSetInput.vue new file mode 100644 index 0000000..d12b546 --- /dev/null +++ b/src/rules/RuleSetInput.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/rules/index.ts b/src/rules/index.ts index e69de29..7139a2f 100644 --- a/src/rules/index.ts +++ b/src/rules/index.ts @@ -0,0 +1,3 @@ +export * from "./rules"; + +export {default as RuleSetInput} from './RuleSetInput.vue'; \ No newline at end of file diff --git a/src/rules/rules.ts b/src/rules/rules.ts new file mode 100644 index 0000000..a92d1c4 --- /dev/null +++ b/src/rules/rules.ts @@ -0,0 +1,16 @@ +import {ruleBookControllerApi} from "@/mammon"; +import {RuleBookResponse, RuleSetResponse} from "@/generated/mammon"; + +export const activityTypes = { + itemBought: "ITEM_BOUGHT", + itemSold: "ITEM_SOLD", + bountyEarned: "BOUNTY_EARNED", + itemManufactured: "ITEM_MANUFACTURED" +} as const; + +export type ActivityType = typeof activityTypes[keyof typeof activityTypes]; +export type RuleBook = RuleBookResponse & { ruleSets: { [key: ActivityType]: RuleSetResponse; } } + +export const findByCharacterId = (characterId: number): Promise => ruleBookControllerApi.findByCharacterId(characterId) + .then(response => response.data) + .catch(() => ({characterId, ruleSets: {}})); \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index e99fc39..d1d6dd7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1 +1 @@ -export const copyToClipboard = (s: string) => navigator.clipboard.writeText(s); \ No newline at end of file +export const copyToClipboard = (s: string) => navigator.clipboard.writeText(s);