From 709626c936d974c708c69623450a3936db4d8cd6 Mon Sep 17 00:00:00 2001
From: eMe-404 <838702939>
Date: Mon, 24 Sep 2018 15:42:15 +0800
Subject: [PATCH 1/5] [yaer][#49]: Fix frontend date format
---
.../practise-diary-editor-body.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/web/src/component/my-practise-diary/practise-diary-editor-body.js b/web/src/component/my-practise-diary/practise-diary-editor-body.js
index 1ccd061..fcef188 100644
--- a/web/src/component/my-practise-diary/practise-diary-editor-body.js
+++ b/web/src/component/my-practise-diary/practise-diary-editor-body.js
@@ -13,12 +13,12 @@ const { TextArea } = Input
const DATE_FORMAT = 'YYYY/MM/DD'
const date = new Date()
-const formatedDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
+const formatedDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
let storage = window.localStorage
let initDiaryContent = '## 我做了什么\n## 学了什么\n## 有什么印象深刻的收获'
let initGoalContent = '## 目标是什么\n## 目标会持续几天\n## 每天的具体行动是什么'
export default class PractiseDiaryEditorBody extends Component {
- constructor (props) {
+ constructor(props) {
super(props)
let practiseDiary = this.props.practiseDiary
this.state = ({
@@ -29,7 +29,7 @@ export default class PractiseDiaryEditorBody extends Component {
})
}
- componentWillReceiveProps (nextProps) {
+ componentWillReceiveProps(nextProps) {
if (nextProps.practiseDiary) {
this.setState({
content: nextProps.practiseDiary.content
@@ -47,7 +47,7 @@ export default class PractiseDiaryEditorBody extends Component {
}
}
- handleInputChange (tag, e) {
+ handleInputChange(tag, e) {
const stateObject = {}
storage.setItem(this.state.contentId, JSON.stringify(e.target.value))
@@ -63,14 +63,14 @@ export default class PractiseDiaryEditorBody extends Component {
this.setState(stateObject)
}
- handleDateChange (date) {
+ handleDateChange(date) {
if (!date) return
this.setState({
- date: date.format('YYYY/MM/DD')
+ date: date.format('YYYY-MM-DD')
})
}
- submitPractiseDiary () {
+ submitPractiseDiary() {
if (this.props.operationType === 'update') {
this.props.closeModal(false)
}
@@ -83,7 +83,7 @@ export default class PractiseDiaryEditorBody extends Component {
})
}
- cancelEditPractiseDiary () {
+ cancelEditPractiseDiary() {
if (this.props.operationType === 'update') {
this.props.closeModal(false)
}
--
Gitee
From e4e95b885f10f103f1976ef77a746fe0f1f110e4 Mon Sep 17 00:00:00 2001
From: eMe-404 <838702939>
Date: Mon, 24 Sep 2018 20:43:46 +0800
Subject: [PATCH 2/5] [yaer][#72]: Add monthView component to practiseDiaryList
---
web/src/action/comment.js | 15 ++++-
web/src/action/follow.js | 15 +----
web/src/action/practise-diary.js | 31 ++++++++--
.../my-practise-diary/practise-diary-list.js | 61 +++++++++++++++++--
web/src/reducer/index.js | 4 +-
...owee-monthly-diary.js => monthly-diary.js} | 2 +-
...r-submit-count.js => year-submit-count.js} | 2 +-
7 files changed, 104 insertions(+), 26 deletions(-)
rename web/src/reducer/{followee-monthly-diary.js => monthly-diary.js} (76%)
rename web/src/reducer/{followee-year-submit-count.js => year-submit-count.js} (71%)
diff --git a/web/src/action/comment.js b/web/src/action/comment.js
index f79ed78..bd58dce 100644
--- a/web/src/action/comment.js
+++ b/web/src/action/comment.js
@@ -4,13 +4,24 @@ import * as practiseDiary from './practise-diary'
import * as excellentDiary from './excellent-diary'
import * as follow from './follow'
+export const refreshMonthlyDiaries = monthlyDiaries => ({
+ type: 'REFRESH_MONTHLY_DIARIES',
+ monthlyDiaries
+})
+
+export const refreshYearSubmitCount = yearSubmitCount => ({
+ type: 'REFRESH_YEAR_SUBMIT_COUNT',
+ yearSubmitCount
+})
+
+
export const submitComments = (followeeId, id, commentContent, callback) => {
const comments = {
practiseDiaryId: id,
commentContent
}
return dispatch => {
- ;(async () => {
+ ; (async () => {
const res = await request.post(`./api/comments`, comments)
if (res.status === HTTP_CODE.CREATED) {
callback()
@@ -24,3 +35,5 @@ export const submitComments = (followeeId, id, commentContent, callback) => {
})()
}
}
+
+
diff --git a/web/src/action/follow.js b/web/src/action/follow.js
index e3a1aa5..fc0f340 100644
--- a/web/src/action/follow.js
+++ b/web/src/action/follow.js
@@ -2,6 +2,7 @@ import HTTP_CODE from '../constant/httpCode'
import * as request from '../constant/fetchRequest'
import constant from '../constant/constant'
import { message } from 'antd'
+import { refreshMonthlyDiaries, refreshYearSubmitCount } from './comment';
export const refreshFolloweeListAndDiaries = followeeListAndDiaries => ({
type: 'REFRESH_PRACTISE_CONTACTS',
@@ -26,16 +27,6 @@ export const refreshFolloweeDiariesAndComments = followeeDiariesAndComments => (
followeeDiariesAndComments
})
-export const refreshFolloweeMonthlyDiaries = followeeMonthlyDiaries => ({
- type: 'REFRESH_MONTHLY_DIARIES',
- followeeMonthlyDiaries
-})
-
-export const refreshFolloweeYearSubmitCount = followeeYearSubmitCount => ({
- type: 'REFRESH_YEAR_SUBMIT_COUNT',
- followeeYearSubmitCount
-})
-
export const search = value => {
return dispatch => {
; (async () => {
@@ -103,7 +94,7 @@ export const getFolloweeMonthlyDiaries = (followeeId, month, year) => {
`./api/followees/${followeeId}/practise-diaries?year=${year}&month=${month}`
)
if (res.status === HTTP_CODE.OK) {
- dispatch(refreshFolloweeMonthlyDiaries(res.body))
+ dispatch(refreshMonthlyDiaries(res.body))
}
})()
}
@@ -116,7 +107,7 @@ export const getFolloweeYearSubmitCount = (followeeId, year) => {
`./api/followees/${followeeId}/practise-diaries/monthly-count?year=${year}`
)
if (res.status === HTTP_CODE.OK) {
- dispatch(refreshFolloweeYearSubmitCount(res.body))
+ dispatch(refreshYearSubmitCount(res.body))
}
})()
}
diff --git a/web/src/action/practise-diary.js b/web/src/action/practise-diary.js
index ec5141f..bc2eb79 100644
--- a/web/src/action/practise-diary.js
+++ b/web/src/action/practise-diary.js
@@ -1,6 +1,7 @@
import HTTP_CODE from '../constant/httpCode'
import * as request from '../constant/fetchRequest'
import constant from '../constant/constant'
+import { refreshMonthlyDiaries, refreshYearSubmitCount } from './comment';
export const refreshPractiseDiary = practiseDiaryAndComments => ({
type: 'REFRESH_PRACTISE_DIARY_COMMENT',
@@ -9,7 +10,7 @@ export const refreshPractiseDiary = practiseDiaryAndComments => ({
export const getPractiseDiary = (page = 1, pageSize = constant.PAGE_SIZE) => {
return dispatch => {
- ;(async () => {
+ ; (async () => {
const res = await request.get(
`./api/diaries/?page=${page}& pageSize=${pageSize}`
)
@@ -20,9 +21,31 @@ export const getPractiseDiary = (page = 1, pageSize = constant.PAGE_SIZE) => {
}
}
+export const getMonthlyDiaries = (month, year) => {
+ return dispatch => {
+ ; (async () => {
+ const res = await request.get(`./api/diaries?month=${month}&year=${year}`)
+ if (res.status === HTTP_CODE.OK) {
+ dispatch(refreshMonthlyDiaries(res.body))
+ }
+ })()
+ }
+}
+
+export const getYearSubmitCount = (year) => {
+ return dispatch => {
+ ; (async () => {
+ const res = await request.get(`./api/diaries?year=${year}`)
+ if (res.status === HTTP_CODE.OK) {
+ dispatch(refreshYearSubmitCount(res.body))
+ }
+ })()
+ }
+}
+
export const deletePractiseDiary = (rawId, page, pageSize) => {
return dispatch => {
- ;(async () => {
+ ; (async () => {
const res = await request.del(`./api/diaries/${rawId}`)
if (res.status === HTTP_CODE.NO_CONTENT) {
dispatch(getPractiseDiary(page, pageSize))
@@ -33,7 +56,7 @@ export const deletePractiseDiary = (rawId, page, pageSize) => {
export const createPractiseDiary = growthNote => {
return dispatch => {
- ;(async () => {
+ ; (async () => {
const res = await request.post(`./api/diaries`, growthNote)
if (res.status === HTTP_CODE.CREATED) {
dispatch(getPractiseDiary())
@@ -44,7 +67,7 @@ export const createPractiseDiary = growthNote => {
export const updatePractiseDiary = (growthNote, rawId) => {
return dispatch => {
- ;(async () => {
+ ; (async () => {
const res = await request.update(`./api/diaries/${rawId}`, growthNote)
if (res.status === HTTP_CODE.NO_CONTENT) {
dispatch(getPractiseDiary())
diff --git a/web/src/component/my-practise-diary/practise-diary-list.js b/web/src/component/my-practise-diary/practise-diary-list.js
index a8a33fb..499a8de 100644
--- a/web/src/component/my-practise-diary/practise-diary-list.js
+++ b/web/src/component/my-practise-diary/practise-diary-list.js
@@ -6,15 +6,18 @@ import PractiseDiary from './practise-diary'
import PractiseDiaryEditor from './practise-diary-editor'
import constant from '../../constant/constant'
import 'antd/dist/antd.css'
-import { Pagination } from 'antd'
+import { Pagination, Row, Col, Button } from 'antd'
import * as followActions from '../../action/follow'
+import moment from 'moment'
+import FolloweeDiaryListMonthView from '../follow/followee-diary-list-month-view';
class PractiseDiaryList extends Component {
constructor(props) {
super(props)
this.state = {
page: 1,
- pageSize: constant.PAGE_SIZE
+ pageSize: constant.PAGE_SIZE,
+ isShowMonthView: false
}
}
@@ -27,10 +30,23 @@ class PractiseDiaryList extends Component {
this.setState({ page })
this.props.getPractiseDiaries(page, this.state.pageSize)
}
+ showAndCloseMonthView() {
+ this.setState({
+ isShowMonthView: !this.state.isShowMonthView
+ })
+ const currentMonth = moment().month()
+ const currentYear = moment().year()
+ this.props.getMonthlyContactDiaries(currentMonth, currentYear)
+ this.props.getYearSubmitCount(currentYear)
+ }
+ onMonthChange(month, year) {
+ this.props.getMonthlyContactDiaries(month, year)
+ this.props.getYearSubmitCount(year)
+ }
render() {
const practiseDiaryAndComments = this.props.practiseDiariesInfo.practiseDiaryAndComments || []
- return (
+ const practiseDiaryListView =
{practiseDiaryAndComments.map((practiseDiaryAndComment, index) =>
@@ -45,14 +61,49 @@ class PractiseDiaryList extends Component {
defaultCurrent={this.state.page} total={this.props.practiseDiariesInfo.total}
defaultPageSize={constant.PAGE_SIZE} />
+ return (
+
+
+
+
+
+
+
+
+ {
+ !this.state.isShowMonthView ?
+ practiseDiaryListView :
+ this.onMonthChange(month, year)}
+ />
+ }
+
)
}
}
-const mapStateToProps = state => ({ practiseDiariesInfo: state.practiseDiariesInfo })
+const mapStateToProps = state => (
+ {
+ practiseDiariesInfo: state.practiseDiariesInfo,
+ monthlyDiaries: state.monthlyDiaries,
+ yearSubmitCount: state.yearSubmitCount
+ }
+)
const mapDispatchToProps = dispatch => ({
getPractiseDiaries: (page, pageSize) => dispatch(actions.getPractiseDiary(page, pageSize)),
- getFollowTutors: () => { dispatch(followActions.getFollowTutors()) }
+ getFollowTutors: () => { dispatch(followActions.getFollowTutors()) },
+ getMonthlyContactDiaries: (month, year) => dispatch(actions.getMonthlyDiaries(month, year)),
+ getYearSubmitCount: (year) => dispatch(actions.getYearSubmitCount(year))
+
})
export default connect(mapStateToProps, mapDispatchToProps)(PractiseDiaryList)
diff --git a/web/src/reducer/index.js b/web/src/reducer/index.js
index d027841..177b8fe 100644
--- a/web/src/reducer/index.js
+++ b/web/src/reducer/index.js
@@ -9,8 +9,8 @@ import user from './user'
import settings from './settings'
import notifications from './notifications'
import users from './users'
-import monthlyDiaries from './followee-monthly-diary'
-import yearSubmitCount from './followee-year-submit-count'
+import monthlyDiaries from './monthly-diary'
+import yearSubmitCount from './year-submit-count'
export default combineReducers({
user,
diff --git a/web/src/reducer/followee-monthly-diary.js b/web/src/reducer/monthly-diary.js
similarity index 76%
rename from web/src/reducer/followee-monthly-diary.js
rename to web/src/reducer/monthly-diary.js
index 49fafaf..16344e1 100644
--- a/web/src/reducer/followee-monthly-diary.js
+++ b/web/src/reducer/monthly-diary.js
@@ -1,7 +1,7 @@
export default (state = [], action) => {
switch (action.type) {
case 'REFRESH_MONTHLY_DIARIES':
- return action.followeeMonthlyDiaries
+ return action.monthlyDiaries
default:
return state
}
diff --git a/web/src/reducer/followee-year-submit-count.js b/web/src/reducer/year-submit-count.js
similarity index 71%
rename from web/src/reducer/followee-year-submit-count.js
rename to web/src/reducer/year-submit-count.js
index 63ca06d..94328a1 100644
--- a/web/src/reducer/followee-year-submit-count.js
+++ b/web/src/reducer/year-submit-count.js
@@ -1,6 +1,6 @@
export default (state = [],action) => {
if(action.type === 'REFRESH_YEAR_SUBMIT_COUNT') {
- return action.followeeYearSubmitCount
+ return action.yearSubmitCount
}
return state
}
\ No newline at end of file
--
Gitee
From c38b2015dafbf5b46a45c888dc7d3bcbdad352f4 Mon Sep 17 00:00:00 2001
From: eMe-404 <838702939>
Date: Mon, 24 Sep 2018 22:10:54 +0800
Subject: [PATCH 3/5] [yaer][#72]: Add API getMonthlyDiaryByAuthorId and
getYearSubmitCountByAuthorId
---
.../controllers/PractiseDiaryController.java | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/backend/src/main/java/cn/thoughtworks/school/controllers/PractiseDiaryController.java b/backend/src/main/java/cn/thoughtworks/school/controllers/PractiseDiaryController.java
index d102e40..2bae14a 100644
--- a/backend/src/main/java/cn/thoughtworks/school/controllers/PractiseDiaryController.java
+++ b/backend/src/main/java/cn/thoughtworks/school/controllers/PractiseDiaryController.java
@@ -6,6 +6,9 @@ import cn.thoughtworks.school.entities.PractiseDiary;
import cn.thoughtworks.school.entities.User;
import cn.thoughtworks.school.repositories.ExcellentDiaryRepository;
import cn.thoughtworks.school.repositories.PractiseDiaryRepository;
+import cn.thoughtworks.school.response.PractiseDiaryCount;
+import cn.thoughtworks.school.response.PractiseDiaryResource;
+import cn.thoughtworks.school.services.PractiseDiaryService;
import cn.thoughtworks.school.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -19,6 +22,7 @@ import org.springframework.web.client.RestTemplate;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/api/diaries")
@@ -29,6 +33,8 @@ public class PractiseDiaryController {
private ExcellentDiaryRepository excellentDiaryRepository;
@Autowired
private UserService userService;
+ @Autowired
+ private PractiseDiaryService practiseDiaryService;
@RequestMapping(value = "", method = RequestMethod.GET)
@@ -47,6 +53,31 @@ public class PractiseDiaryController {
return new ResponseEntity<>(practiseAndComments, HttpStatus.OK);
}
+ @RequestMapping(value = "", method = RequestMethod.GET, params = {"year", "month"})
+ public ResponseEntity> getMonthlyDiaryByAuthorId(@Auth User user,
+ @RequestParam(value = "year") int year,
+ @RequestParam(value = "month") int month) {
+
+ List practiseDiaries = practiseDiaryService.findMonthlyDiariesByAuthorId(user.getId(), year, month);
+
+ final List practiseDiaryResources = practiseDiaries.stream()
+ .map(PractiseDiaryResource::toResource)
+ .collect(Collectors.toList());
+
+ return new ResponseEntity<>(practiseDiaryResources, HttpStatus.OK);
+ }
+
+ @RequestMapping(value = "/monthly-count", method = RequestMethod.GET)
+ public ResponseEntity> getYearSubmitCountByAuthorId(@Auth User user,
+ @RequestParam(value = "year") int year) {
+
+ List practiseDiaryCounts = practiseDiaryService.findYearSubmitCountByAuthorId(user.getId(), year);
+
+
+ return new ResponseEntity<>(practiseDiaryCounts, HttpStatus.OK);
+ }
+
+
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity