forked from Open-CT/OpenPBL
fix: last learn section
This commit is contained in:
parent
2c4307400d
commit
cad71fe927
|
@ -163,7 +163,7 @@ func (u *StudentController) FinishedProject() {
|
|||
// @Param body body models.LearnSection true ""
|
||||
// @Success 200 {object} Response
|
||||
// @Failure 400
|
||||
// @router /section/:sectionId [get]
|
||||
// @router /project/:projectId/section/:sectionId [get]
|
||||
func (u *StudentController) GetLearnSection() {
|
||||
var resp Response
|
||||
user := u.GetSessionUser()
|
||||
|
@ -187,7 +187,8 @@ func (u *StudentController) GetLearnSection() {
|
|||
}
|
||||
uid := user.Username
|
||||
sid, err := u.GetInt64(":sectionId")
|
||||
l, err := models.GetLearnSection(sid, uid)
|
||||
projectId, err := u.GetInt64(":projectId")
|
||||
l, err := models.GetLearnSection(sid, uid, projectId)
|
||||
if err != nil {
|
||||
u.Data["json"] = Response{
|
||||
Code: 400,
|
||||
|
@ -208,7 +209,7 @@ func (u *StudentController) GetLearnSection() {
|
|||
// @Param body body models.LearnSection true ""
|
||||
// @Success 200 {object} Response
|
||||
// @Failure 400
|
||||
// @router /section/:sectionId [post]
|
||||
// @router /project/:projectId/section/:sectionId [post]
|
||||
func (u *StudentController) UpdateLearnSection() {
|
||||
var resp Response
|
||||
user := u.GetSessionUser()
|
||||
|
@ -240,7 +241,8 @@ func (u *StudentController) UpdateLearnSection() {
|
|||
LearnMinute: m,
|
||||
LearnSecond: s,
|
||||
}
|
||||
err = l.Update()
|
||||
pid, err := u.GetInt64(":projectId")
|
||||
err = l.Update(pid)
|
||||
if err != nil {
|
||||
u.Data["json"] = Response{
|
||||
Code: 400,
|
||||
|
@ -259,7 +261,7 @@ func (u *StudentController) UpdateLearnSection() {
|
|||
// @Description
|
||||
// @Success 200 {object} Response
|
||||
// @Failure 400
|
||||
// @router /last-learn [get]
|
||||
// @router /last-learn/project/:projectId [get]
|
||||
func (u *StudentController) GetLastLearnSection() {
|
||||
var resp Response
|
||||
user := u.GetSessionUser()
|
||||
|
@ -282,7 +284,8 @@ func (u *StudentController) GetLastLearnSection() {
|
|||
return
|
||||
}
|
||||
uid := user.Username
|
||||
l, err := models.GetLastLearnSection(uid)
|
||||
projectId := u.GetString(":projectId")
|
||||
l, err := models.GetLastLearnSection(uid, projectId)
|
||||
if err != nil {
|
||||
u.Data["json"] = Response{
|
||||
Code: 400,
|
||||
|
|
|
@ -16,8 +16,8 @@ type LearnProject struct {
|
|||
}
|
||||
|
||||
type LearnSection struct {
|
||||
StudentId string `json:"studentId" xorm:"not null index pk"`
|
||||
SectionId int64 `json:"sectionId" xorm:"not null index pk"`
|
||||
StudentId string `json:"studentId" xorm:"not null pk"`
|
||||
SectionId int64 `json:"sectionId" xorm:"not null pk"`
|
||||
|
||||
LearnMinute int `json:"learnMinute" xorm:"default 0"`
|
||||
LearnSecond int `json:"learnSecond" xorm:"default 0"`
|
||||
|
@ -25,6 +25,7 @@ type LearnSection struct {
|
|||
|
||||
type LastLearn struct {
|
||||
StudentId string `json:"studentId" xorm:"not null pk"`
|
||||
ProjectId int64 `json:"projectId" xorm:"not null pk"`
|
||||
SectionId int64 `json:"sectionId" xorm:"not null index"`
|
||||
ExitAt time.Time `json:"exitAt" xorm:"updated"`
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ func GetProjectStudents(pid string, from int, size int) (s []LearnProject, rows
|
|||
return
|
||||
}
|
||||
|
||||
func GetLearnSection(sectionId int64, studentId string) (l LearnSection, err error) {
|
||||
func GetLearnSection(sectionId int64, studentId string, projectId int64) (l LearnSection, err error) {
|
||||
var b bool
|
||||
b, err = (&LearnSection{}).GetEngine().
|
||||
Where("section_id = ?", sectionId).
|
||||
|
@ -109,39 +110,43 @@ func GetLearnSection(sectionId int64, studentId string) (l LearnSection, err err
|
|||
if !b {
|
||||
l.SectionId = sectionId
|
||||
l.StudentId = studentId
|
||||
err = (&l).Create()
|
||||
err = (&l).Create(projectId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetLastLearnSection(studentId string) (l LastLearnSection, err error) {
|
||||
func GetLastLearnSection(studentId string, projectId string) (l LastLearnSection, err error) {
|
||||
var b bool
|
||||
b, err = (&LastLearn{}).GetEngine().
|
||||
Where("student_id = ?", studentId).
|
||||
Where("project_id = ?", projectId).
|
||||
Join("LEFT OUTER", Section{}, "last_learn.section_id = section.id").
|
||||
Get(&l)
|
||||
l.Last = b
|
||||
return
|
||||
}
|
||||
|
||||
func (l *LearnSection) Create() (err error) {
|
||||
func (l *LearnSection) Create(projectId int64) (err error) {
|
||||
_, err = (&LearnSection{}).GetEngine().Insert(l)
|
||||
_, err = (&LastLearn{}).GetEngine().Insert(&LastLearn{
|
||||
StudentId: l.StudentId,
|
||||
ProjectId: projectId,
|
||||
SectionId: l.SectionId,
|
||||
ExitAt: time.Now(),
|
||||
})
|
||||
return
|
||||
}
|
||||
func (l *LearnSection) Update() (err error) {
|
||||
func (l *LearnSection) Update(projectId int64) (err error) {
|
||||
_, err = (&LearnSection{}).GetEngine().
|
||||
Where("student_id = ?", l.StudentId).
|
||||
Where("section_id = ?", l.SectionId).
|
||||
Update(l)
|
||||
_, err = (&LastLearn{}).GetEngine().
|
||||
Where("student_id = ?", l.StudentId).
|
||||
Where("project_id = ?", projectId).
|
||||
Update(&LastLearn{
|
||||
StudentId: l.StudentId,
|
||||
ProjectId: projectId,
|
||||
SectionId: l.SectionId,
|
||||
ExitAt: time.Now(),
|
||||
})
|
||||
|
|
|
@ -25,22 +25,22 @@ const StudentApi = {
|
|||
})
|
||||
})
|
||||
},
|
||||
getLearnSection(sid) {
|
||||
getLearnSection(pid, sid) {
|
||||
return request({
|
||||
url: `/student/section/${sid}`,
|
||||
url: `/student/project/${pid}/section/${sid}`,
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
updateLearnSection(sid, data) {
|
||||
updateLearnSection(pid, sid, data) {
|
||||
return request({
|
||||
url: `/student/section/${sid}`,
|
||||
url: `/student/project/${pid}/section/${sid}`,
|
||||
method: 'post',
|
||||
data: qs.stringify(data)
|
||||
})
|
||||
},
|
||||
getLastLearnSection() {
|
||||
getLastLearnSection(pid) {
|
||||
return request({
|
||||
url: '/student/last-learn',
|
||||
url: `/student/last-learn/project/${pid}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ function PreviewSection(obj) {
|
|||
learnMinute: m,
|
||||
learnSecond: s
|
||||
}
|
||||
StudentApi.updateLearnSection(sid, data)
|
||||
StudentApi.updateLearnSection(pid, sid, data)
|
||||
.then(res=>{
|
||||
})
|
||||
.catch(e=>{console.log(e)})
|
||||
|
@ -98,7 +98,7 @@ function PreviewSection(obj) {
|
|||
.catch(e=>{console.log(e)})
|
||||
}
|
||||
const getTimer = () => {
|
||||
StudentApi.getLearnSection(sid)
|
||||
StudentApi.getLearnSection(pid, sid)
|
||||
.then(res=>{
|
||||
if (res.data.code === 200) {
|
||||
setSecond(res.data.data.learnSecond)
|
||||
|
@ -146,7 +146,9 @@ function PreviewSection(obj) {
|
|||
/>
|
||||
<div style={{ padding: '20px', margin: 'auto'}}>
|
||||
<Card>
|
||||
<h2 style={{ fontWeight: 'bold' }}>{section.sectionName}</h2>
|
||||
<h2 style={{ fontWeight: 'bold' }}>
|
||||
{util.FormatSectionName(section.sectionName, section.chapterNumber, section.sectionNumber)}
|
||||
</h2>
|
||||
{learning ?
|
||||
<span style={{float: 'right'}}>{minute} : {second}</span>
|
||||
: null}
|
||||
|
|
|
@ -54,7 +54,7 @@ class ProjectInfo extends React.PureComponent {
|
|||
})
|
||||
}
|
||||
loadLastLearn = () => {
|
||||
StudentApi.getLastLearnSection()
|
||||
StudentApi.getLastLearnSection(this.state.pid)
|
||||
.then(res=>{
|
||||
if (res.data.code === 200) {
|
||||
this.setState({
|
||||
|
|
|
@ -45,18 +45,18 @@ func init() {
|
|||
|
||||
beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetProjectDetail",
|
||||
Method: "UpdateProject",
|
||||
Router: "/:id",
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdateProject",
|
||||
Method: "GetProjectDetail",
|
||||
Router: "/:id",
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
@ -433,7 +433,7 @@ func init() {
|
|||
beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetLastLearnSection",
|
||||
Router: "/last-learn",
|
||||
Router: "/last-learn/project/:projectId",
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
|
@ -451,7 +451,7 @@ func init() {
|
|||
beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetLearnSection",
|
||||
Router: "/section/:sectionId",
|
||||
Router: "/project/:projectId/section/:sectionId",
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
|
@ -460,7 +460,7 @@ func init() {
|
|||
beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:StudentController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdateLearnSection",
|
||||
Router: "/section/:sectionId",
|
||||
Router: "/project/:projectId/section/:sectionId",
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
|
|
Loading…
Reference in New Issue