Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace DM.Services.DataAccess.BusinessObjects.Users;
/// <summary>
/// DAL model for authorization token
/// </summary>
[Table("Tokens")]
public class Token : IRemovable
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ await unreadCountersRepository.FillEntityCounters(
var gameRoomIds = roomIds.ToArray();
game.UnreadPostsCount = gameRoomIds.Sum(id =>
unreadPostCounters.TryGetValue(id, out var count) ? count : 0);
game.Pendings = pendingPosts.Where(p => gameRoomIds.Contains(p.RoomId));
game.PendingPosts = pendingPosts.Where(p => gameRoomIds.Contains(p.RoomId));
}

return games;
Expand Down
3 changes: 1 addition & 2 deletions DM/Services/DM.Services.Gaming/Dto/Output/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class Game

/// <summary>
/// Pending assistant if any
/// <remarks>Due to some issues in EFCore 3.1.5 had to move to IEnumerable, but make no mistake - that is a single assistant every time!</remarks>
/// </summary>
public GeneralUser PendingAssistant { get; set; }

Expand All @@ -79,7 +78,7 @@ public class Game
/// <summary>
/// Game pending posts
/// </summary>
public IEnumerable<PendingPost> Pendings { get; set; }
public IEnumerable<PendingPost> PendingPosts { get; set; }

/// <summary>
/// Game title
Expand Down
2 changes: 1 addition & 1 deletion DM/Web/DM.Web.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void Configure(IApplicationBuilder appBuilder,
if (migrateOnStart)
{
dbContext.Database.Migrate();
throw new Exception("Migration is complete");
Environment.Exit(-1);
}

appBuilder
Expand Down
11 changes: 11 additions & 0 deletions DM/Web/DM.Web.Modern/src/api/models/gaming/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { User } from '@/api/models/community';

export * from './games';
export * from './attributes';
export * from './characters';
export * from './rooms';

export interface Comment {
id: string;
author: User;
created: string;
updated: string | null;
text: string;
likes: User[];
}
33 changes: 25 additions & 8 deletions DM/Web/DM.Web.Modern/src/api/requests/gamingApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiResult, Envelope, ListEnvelope } from '@/api/models/common';
import { Game, AttributeSchema, Tag, Character, Room } from '@/api/models/gaming';
import { ApiResult, Envelope, ListEnvelope, PagingQuery } from '@/api/models/common';
import { Game, AttributeSchema, Tag, Character, Room, Comment } from '@/api/models/gaming';
import { User } from '@/api/models/community';
import Api from '@/api';

Expand Down Expand Up @@ -33,6 +33,11 @@ export default new class {
return data!;
}

public async getComments(gameId: string, query: PagingQuery): Promise<ListEnvelope<Comment>> {
const { data } = await Api.get<ListEnvelope<Comment>>(`games/${gameId}/comments`, query);
return data!;
}

public async getSchemas(): Promise<ListEnvelope<AttributeSchema>> {
const { data } = await Api.get<ListEnvelope<AttributeSchema>>('schemata');
return data!;
Expand All @@ -51,15 +56,27 @@ export default new class {
return await Api.post<Envelope<Game>>('games', game);
}

public async createCharacter(id: string, character: Character): Promise<ApiResult<Envelope<Character>>> {
return await Api.post<Envelope<Character>>(`games/${id}/characters`, character);
public async createCharacter(gameId: string, character: Character): Promise<ApiResult<Envelope<Character>>> {
return await Api.post<Envelope<Character>>(`games/${gameId}/characters`, character);
}

public async createComment(gameId: string, comment: Comment): Promise<ApiResult<Envelope<Comment>>> {
return await Api.post<Envelope<Comment>>(`games/${gameId}/comments`, comment);
}

public async subscribe(gameId: string): Promise<ApiResult<Envelope<User>>> {
return await Api.post<Envelope<User>>(`games/${gameId}/readers`);
}

public async unsubscribe(gameId: string): Promise<ApiResult<void>> {
return await Api.delete(`games/${gameId}/readers`);
}

public async subscribe(id: string): Promise<ApiResult<Envelope<User>>> {
return await Api.post<Envelope<User>>(`games/${id}/readers`);
public async updateComment(commentId: string, comment: Comment): Promise<ApiResult<Envelope<Comment>>> {
return await Api.patch<Envelope<Comment>>(`games/comments/${commentId}`, comment);
}

public async unsubscribe(id: string): Promise<ApiResult<void>> {
return await Api.delete(`games/${id}/readers`);
public async deleteComment(commentId: string): Promise<ApiResult<void>> {
return await Api.delete(`games/comments/${commentId}`);
}
}();
11 changes: 8 additions & 3 deletions DM/Web/DM.Web.Modern/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue from 'vue';
import Router from 'vue-router';

import GeneralMenu from './views/layout/GeneralMenu.vue';
import GameMenu from './views/pages/game/GameMenu.vue';
import GameMenu from './views/pages/game/menu/GameMenu.vue';
import GeneralSidebar from './views/layout/GeneralSidebar.vue';

Vue.use(Router);
Expand Down Expand Up @@ -173,10 +173,15 @@ export default new Router({
children: [{
name: 'game',
path: '',
component: () => import('./views/pages/game/Information.vue'),
component: () => import('./views/pages/game/information/Information.vue'),
}, {
name: 'game-comments',
path: 'out-of-session',
component: () => import('./views/pages/game/comments/GameComments.vue'),
children: [{
name: 'game-comments',
path: ':n?',
component: () => import('./views/pages/game/comments/GameCommentsList.vue'),
}],
}, {
name: 'create-character',
path: 'create-character',
Expand Down
2 changes: 1 addition & 1 deletion DM/Web/DM.Web.Modern/src/store/forum/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const actions: ActionTree<ForumState, RootState> = {
commit('updateComment', data?.resource);
}
},
async deleteComment(_0, { id }): Promise<void> {
async deleteComment(_, { id }): Promise<void> {
await forumApi.deleteComment(id);
},
async markAllTopicsAsRead({ commit }, { id }): Promise<void> {
Expand Down
74 changes: 50 additions & 24 deletions DM/Web/DM.Web.Modern/src/store/gaming/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { ActionTree } from 'vuex';
import gamingApi from '@/api/requests/gamingApi';
import GamingState from './gamingState';
import RootState from './../rootState';
import { AttributeSchema } from '@/api/models/gaming';
import {AttributeSchema, Comment} from '@/api/models/gaming';
import { PagingQuery } from '@/api/models/common';

const actions: ActionTree<GamingState, RootState> = {
async fetchOwnGames({ commit }): Promise<void> {
const { resources: games } = await gamingApi.getOwnGames();
commit('updateOwnGames', games);
},

async fetchPopularGames({commit}): Promise<void> {
async fetchPopularGames({ commit }): Promise<void> {
const { resources: games } = await gamingApi.getPopularGames();
commit('updatePopularGames', games);
},
Expand Down Expand Up @@ -44,15 +45,6 @@ const actions: ActionTree<GamingState, RootState> = {
$router.push({ name: 'game', params: { id: game.id } });
}
},
async createCharacter({ state }, { character, $router }): Promise<void> {
const { data, error } = await gamingApi.createCharacter(state.selectedGame!.id, character);
if (error) {
$router.push({ name: 'error', params: { code: error.code } });
} else {
const { resource: character } = data!;
$router.push({ name: 'game-characters', params: { id: state.selectedGame!.id, characterId: character.id } })
}
},

async selectGame({ commit }, { id, router }): Promise<void> {
commit('updateSelectedGame', null);
Expand All @@ -65,26 +57,16 @@ const actions: ActionTree<GamingState, RootState> = {
commit('updateSelectedGame', game);
}
},
async fetchSelectedGameCharacters({ commit }, { id }): Promise<void> {
commit('updateSelectedGameCharacters', null);
const { resources: characters } = await gamingApi.getCharacters(id);
commit('updateSelectedGameCharacters', characters);
},
async fetchSelectedGameRooms({ commit }, { id }): Promise<void> {
commit('updateSelectedGameRooms', null);
const { resources: rooms } = await gamingApi.getRooms(id);
commit('updateSelectedGameRooms', rooms);
},

async fetchSelectedGameReaders({ commit }, { id }): Promise<void> {
commit('updateSelectedGameReaders', null);
const { resources: readers } = await gamingApi.getReaders(id);
commit('updateSelectedGameReaders', readers);
},

async subscribe({ commit, state }, { router }): Promise<void> {
const { data, error } = await gamingApi.subscribe(state.selectedGame!.id);
if (error) {
router.push({ name: 'error', params: { code: error.code }});
router.push({ name: 'error', params: { code: error.code } });
} else {
const { resource: reader } = data!;
commit('addReader', reader);
Expand All @@ -93,11 +75,55 @@ const actions: ActionTree<GamingState, RootState> = {
async unsubscribe({ commit, state, rootState }, { router }): Promise<void> {
const { error } = await gamingApi.unsubscribe(state.selectedGame!.id);
if (error) {
router.push({ name: 'error', params: { code: error.code }});
router.push({ name: 'error', params: { code: error.code } });
} else {
commit('removeReader', rootState.user);
}
},

async fetchSelectedGameCharacters({ commit }, { id }): Promise<void> {
commit('updateSelectedGameCharacters', null);
const { resources: characters } = await gamingApi.getCharacters(id);
commit('updateSelectedGameCharacters', characters);
},
async createCharacter({ state }, { character, $router }): Promise<void> {
const { data, error } = await gamingApi.createCharacter(state.selectedGame!.id, character);
if (error) {
$router.push({ name: 'error', params: { code: error.code } });
} else {
const { resource: character } = data!;
$router.push({ name: 'game-characters', params: { id: state.selectedGame!.id, characterId: character.id } })
}
},

async fetchSelectedGameComments({ commit }, { id, n }): Promise<void> {
commit('updateSelectedGameComments', null);
const data = await gamingApi.getComments(id, { number: n } as PagingQuery);
commit('updateSelectedGameComments', data!);
},
async createComment({ state }, { comment, $router }): Promise<void> {
const { id } = state.selectedGame!;
const { error: postCommentError } = await gamingApi.createComment(id, comment);
if (postCommentError) return Promise.reject();

const data = await gamingApi.getComments(id, { size: 0, number: 0, skip: 0 });
$router.push({ name: 'game-comments', params: { id, n: data.paging!.total } });
},
async updateComment({ commit }, { id, comment }): Promise<void> {
const { data, error } = await gamingApi.updateComment(id, comment as Comment);
if (!error) {
commit('updateComment', data!.resource);
}
},
async deleteComment(_, { id }) {
await gamingApi.deleteComment(id);
},

async fetchSelectedGameRooms({ commit }, { id }): Promise<void> {
commit('updateSelectedGameRooms', null);
const { resources: rooms } = await gamingApi.getRooms(id);
commit('updateSelectedGameRooms', rooms);
},
};

export default actions;
6 changes: 4 additions & 2 deletions DM/Web/DM.Web.Modern/src/store/gaming/gamingState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Game, AttributeSchema, Tag, Character, Room} from '@/api/models/gaming';
import {User} from '@/api/models/community';
import { Game, AttributeSchema, Tag, Character, Room, Comment } from '@/api/models/gaming';
import { User } from '@/api/models/community';
import { ListEnvelope } from '@/api/models/common';

export default interface GamingState {
ownGames: Game[] | null;
Expand All @@ -12,4 +13,5 @@ export default interface GamingState {
selectedGameCharacters: Character[] | null;
selectedGameRooms: Room[] | null;
selectedGameReaders: User[] | null;
selectedGameComments: ListEnvelope<Comment> | null;
}
1 change: 1 addition & 0 deletions DM/Web/DM.Web.Modern/src/store/gaming/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const getters: GetterTree<GamingState, RootState> = {
selectedGameCharacters: (state) => state.selectedGameCharacters,
selectedGameRooms: (state) => state.selectedGameRooms,
selectedGameReaders: (state) => state.selectedGameReaders,
selectedGameComments: (state) => state.selectedGameComments,
};

export default getters;
1 change: 1 addition & 0 deletions DM/Web/DM.Web.Modern/src/store/gaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const state: GamingState = {
selectedGameCharacters: null,
selectedGameRooms: null,
selectedGameReaders: null,
selectedGameComments: null,
};

const gaming: Module<GamingState, RootState> = {
Expand Down
17 changes: 15 additions & 2 deletions DM/Web/DM.Web.Modern/src/store/gaming/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MutationTree } from 'vuex';
import GamingState from './gamingState';
import {Game, AttributeSchema, Tag, Character, Room, GameParticipation} from '@/api/models/gaming';
import {User} from '@/api/models/community';
import { Game, AttributeSchema, Tag, Character, Room, GameParticipation, Comment } from '@/api/models/gaming';
import { User } from '@/api/models/community';
import { ListEnvelope } from '@/api/models/common';

const mutations: MutationTree<GamingState> = {
updateOwnGames(state, payload: Game[]) {
Expand Down Expand Up @@ -34,6 +35,18 @@ const mutations: MutationTree<GamingState> = {
updateSelectedGameReaders(state, payload: User[]) {
state.selectedGameReaders = payload;
},
updateSelectedGameComments(state, payload: ListEnvelope<Comment>) {
state.selectedGameComments = payload;
},
updateComment(state, payload: Comment) {
state.selectedGameComments!.resources = state.selectedGameComments!.resources.map(comment => {
if (comment.id === payload.id) {
return payload;
}

return comment;
});
},

addReader(state, payload: User) {
if (state.selectedGame === null || state.selectedGameReaders === null) return;
Expand Down
8 changes: 6 additions & 2 deletions DM/Web/DM.Web.Modern/src/views/layout/menu/MenuLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<router-link :to="{ name: 'game', params: { id: game.id } }">
{{ game.title }}
</router-link>
<span v-if="counters">
<span v-if="counters" class="menu-game-item__counters">
<router-link :to="{ name: 'game-first-unread-post', params: { id: game.id } }">
<icon :font="game.unreadPostsCount ? IconType.PostsUnread : IconType.PostsNoUnread" />
<template v-if="game.unreadPostsCount">{{ game.unreadPostsCount }}</template>
Expand Down Expand Up @@ -49,11 +49,15 @@ export default class MenuLink extends Vue {

& a.router-link-active
theme(color, $text)
font-weight bold

.menu-game-item__counters
white-space nowrap

.menu-game-item-separator
display inline-block
margin 0 $tiny
vertical-align top
theme(color, $secondaryText)
cursor default
</style>
</style>
Loading