Skip to content

Commit

Permalink
load clap on post
Browse files Browse the repository at this point in the history
  • Loading branch information
tungphuong committed Dec 13, 2017
1 parent eeb7fa0 commit 57993c3
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/modules/CRMCore.Module.Post/CRMCore.Module.Post.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Folder Include="Features\" />
<Folder Include="Features\GetPosts\" />
<Folder Include="Features\CreateCommment\" />
<Folder Include="Features\Clap\" />
<Folder Include="Features\CreateClap\" />
<Folder Include="Features\GetClap\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using CRMCore.Module.Post.Models;

namespace CRMCore.Module.Post.Features.CreateClap
{
public class CreateClapRequest
{
public Guid EntityId
{
get;
set;
}

public EntityType Type
{
get;
set;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
namespace CRMCore.Module.Post.Features.GetClap
{
public class GetClapResponse
{
public Guid Id
{
get;
set;
}

public Guid EntityId
{
get;
set;
}

public string OwnerName
{
get;
set;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using CRMCore.Module.Post.Features.GetClap;

namespace CRMCore.Module.Post.Features.GetPosts
{
Expand Down Expand Up @@ -40,5 +41,11 @@ public List<GetPostCommentResponse> Comments
get;
set;
}

public List<GetClapResponse> Claps
{
get;
set;
}
}
}
13 changes: 11 additions & 2 deletions src/modules/CRMCore.Module.Post/Features/PostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using CRMCore.Framework.Entities;
using CRMCore.Module.Data;
using CRMCore.Module.Data.Extensions;
using CRMCore.Module.Post.Features.Clap;
using CRMCore.Module.Post.Features.CreateClap;
using CRMCore.Module.Post.Features.CreateCommment;
using CRMCore.Module.Post.Features.GetClap;
using CRMCore.Module.Post.Features.GetPosts;
using CRMCore.Module.Post.ViewModels;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -59,6 +60,14 @@ public async Task<PaginatedItem<GetPostsResponse>> Get([FromQuery] GetPostsReque
OwnerName = x.OwnerName,
Description = x.Content,
CreatedDate = x.Created,
Claps = x.Claps
.Where(c => c.EntityId == x.Id)
.Select(c => new GetClapResponse
{
EntityId = c.EntityId,
Id = c.Id,
OwnerName = c.OwnerName
}).ToList(),
Comments = x.Comments
.Where(c => c.PostId == x.Id)
.Select(c => new GetPostCommentResponse
Expand Down Expand Up @@ -151,7 +160,7 @@ public async Task<IActionResult> Delete(Guid id)
}

[HttpPost("clap")]
public async Task<IActionResult> Clap([FromBody]ClapRequest model)
public async Task<IActionResult> Clap([FromBody]CreateClapRequest model)
{
var clap = new Models.Clap
{
Expand Down
12 changes: 7 additions & 5 deletions src/modules/CRMCore.Module.Post/Models/Post.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using CRMCore.Framework.Entities;

namespace CRMCore.Module.Post.Models
Expand Down Expand Up @@ -36,10 +37,11 @@ public List<PostComment> Comments
set;
}

//public List<Clap> Claps
//{
// get;
// set;
//}
[ForeignKey("EntityId")]
public List<Clap> Claps
{
get;
set;
}
}
}
9 changes: 9 additions & 0 deletions src/modules/CRMCore.Module.Post/Models/PostComment.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using CRMCore.Framework.Entities;

namespace CRMCore.Module.Post.Models
Expand Down Expand Up @@ -28,5 +30,12 @@ public string OwnerName
get;
set;
}

[ForeignKey("EntityId")]
public List<Clap> Claps
{
get;
set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h5>
</div>
<a [routerLink]="[post.id]" class="button button--smaller button--chromeless u-baseColor--buttonNormal">Read more…</a>
<div class="none-line-divider"></div>
<post-clap></post-clap>
<post-clap [NumberOfClaps] = "post.claps.length"></post-clap>
</ng-template>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Clap {
clapId: string;
entityId: string;
ownerName: string;
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './post.model';
export * from './comment.model';
export * from './clap.model';
export * from './schema';
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { normalize, schema } from 'normalizr';

// Define a users schema
export const comment = new schema.Entity('comments');
export const commentSchema = new schema.Entity('comments');

export const clapSchema = new schema.Entity('claps');

export const postSchema = new schema.Entity('posts', {
comments: [ comment ]
comments: [ commentSchema ],
claps: [clapSchema]
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as postAction from '../actions/post.action';
import * as ActionType from '../actions/post-constant-type.action';
import { Post, Comment } from '../../models';
import { Post, Comment, Clap } from '../../models';

import { debug } from 'util';

Expand All @@ -11,6 +11,7 @@ export interface State {
postIds: string[];
posts: { [id: string]: Post };
comments: { [id: string]: Comment };
claps: { [id: string]: Clap };
selectedPostId: string | null;
}

Expand All @@ -20,6 +21,7 @@ const initialState: State = {
postIds: [],
posts: {},
comments: {},
claps: {},
selectedPostId: null
};

Expand All @@ -42,6 +44,7 @@ export function reducer(
loading: false,
posts: { ...state.posts, ...action.payload.entities.posts },
comments: { ...state.comments, ...action.payload.entities.comments },
claps: { ...state.claps, ...action.payload.entities.claps },
postIds: [...state.postIds, ...action.payload.result]
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</g></svg>
</button>
</div>
<div>30<div>
<div>{{NumberOfClaps}}<div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Component} from '@angular/core';
import {Component, Input} from '@angular/core';
@Component({
selector: 'post-clap',
templateUrl: './post-clap.component.html'
})
export class PostClapComponent {
@Input() NumberOfClaps: number;
}

0 comments on commit 57993c3

Please sign in to comment.