mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: trail minor issues
This commit is contained in:
parent
2b01852d31
commit
99146ca02b
3 changed files with 46 additions and 20 deletions
|
|
@ -96,15 +96,41 @@ async def get_user_trails(
|
||||||
return trail_read
|
return trail_read
|
||||||
|
|
||||||
|
|
||||||
async def get_user_trail_with_orgid(
|
async def check_trail_presence(
|
||||||
request: Request, user: PublicUser | AnonymousUser, org_id: int, db_session: Session
|
org_id: int,
|
||||||
) -> TrailRead:
|
user_id: int,
|
||||||
|
request: Request,
|
||||||
|
user: PublicUser,
|
||||||
|
db_session: Session,
|
||||||
|
):
|
||||||
statement = select(Trail).where(Trail.org_id == org_id, Trail.user_id == user.id)
|
statement = select(Trail).where(Trail.org_id == org_id, Trail.user_id == user.id)
|
||||||
trail = db_session.exec(statement).first()
|
trail = db_session.exec(statement).first()
|
||||||
|
|
||||||
if not trail:
|
if not trail:
|
||||||
raise HTTPException(
|
trail = await create_user_trail(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Trail not found"
|
request,
|
||||||
|
user,
|
||||||
|
TrailCreate(
|
||||||
|
org_id=org_id,
|
||||||
|
user_id=user.id,
|
||||||
|
),
|
||||||
|
db_session,
|
||||||
|
)
|
||||||
|
return trail
|
||||||
|
|
||||||
|
return trail
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_trail_with_orgid(
|
||||||
|
request: Request, user: PublicUser, org_id: int, db_session: Session
|
||||||
|
) -> TrailRead:
|
||||||
|
|
||||||
|
trail = await check_trail_presence(
|
||||||
|
org_id=org_id,
|
||||||
|
user_id=user.id,
|
||||||
|
request=request,
|
||||||
|
user=user,
|
||||||
|
db_session=db_session,
|
||||||
)
|
)
|
||||||
|
|
||||||
statement = select(TrailRun).where(TrailRun.trail_id == trail.id)
|
statement = select(TrailRun).where(TrailRun.trail_id == trail.id)
|
||||||
|
|
@ -172,14 +198,12 @@ async def add_activity_to_trail(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Course not found"
|
status_code=status.HTTP_404_NOT_FOUND, detail="Course not found"
|
||||||
)
|
)
|
||||||
|
|
||||||
statement = select(Trail).where(
|
trail = await check_trail_presence(
|
||||||
Trail.org_id == course.org_id, Trail.user_id == user.id
|
org_id=course.org_id,
|
||||||
)
|
user_id=user.id,
|
||||||
trail = db_session.exec(statement).first()
|
request=request,
|
||||||
|
user=user,
|
||||||
if not trail:
|
db_session=db_session,
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Trail not found"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
statement = select(TrailRun).where(
|
statement = select(TrailRun).where(
|
||||||
|
|
@ -208,7 +232,7 @@ async def add_activity_to_trail(
|
||||||
if not trailstep:
|
if not trailstep:
|
||||||
trailstep = TrailStep(
|
trailstep = TrailStep(
|
||||||
trailrun_id=trailrun.id if trailrun.id is not None else 0,
|
trailrun_id=trailrun.id if trailrun.id is not None else 0,
|
||||||
activity_id=activity.id,
|
activity_id=activity.id if activity.id is not None else 0,
|
||||||
course_id=course.id if course.id is not None else 0,
|
course_id=course.id if course.id is not None else 0,
|
||||||
trail_id=trail.id if trail.id is not None else 0,
|
trail_id=trail.id if trail.id is not None else 0,
|
||||||
org_id=course.org_id,
|
org_id=course.org_id,
|
||||||
|
|
@ -306,7 +330,8 @@ async def add_course_to_trail(
|
||||||
trail_runs = db_session.exec(statement).all()
|
trail_runs = db_session.exec(statement).all()
|
||||||
|
|
||||||
trail_runs = [
|
trail_runs = [
|
||||||
TrailRunRead(**trail_run.__dict__, course={}, steps=[], course_total_steps=0 ) for trail_run in trail_runs
|
TrailRunRead(**trail_run.__dict__, course={}, steps=[], course_total_steps=0)
|
||||||
|
for trail_run in trail_runs
|
||||||
]
|
]
|
||||||
|
|
||||||
for trail_run in trail_runs:
|
for trail_run in trail_runs:
|
||||||
|
|
@ -374,7 +399,8 @@ async def remove_course_from_trail(
|
||||||
trail_runs = db_session.exec(statement).all()
|
trail_runs = db_session.exec(statement).all()
|
||||||
|
|
||||||
trail_runs = [
|
trail_runs = [
|
||||||
TrailRunRead(**trail_run.__dict__, course={}, steps=[], course_total_steps=0 ) for trail_run in trail_runs
|
TrailRunRead(**trail_run.__dict__, course={}, steps=[], course_total_steps=0)
|
||||||
|
for trail_run in trail_runs
|
||||||
]
|
]
|
||||||
|
|
||||||
for trail_run in trail_runs:
|
for trail_run in trail_runs:
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ const CourseClient = (props: any) => {
|
||||||
</div>
|
</div>
|
||||||
<div className="-space-y-2 ">
|
<div className="-space-y-2 ">
|
||||||
<div className="text-[12px] text-neutral-400 font-semibold">Author</div>
|
<div className="text-[12px] text-neutral-400 font-semibold">Author</div>
|
||||||
<div className="text-xl font-bold text-neutral-800">{course.authors[0].first_name} {course.authors[0].last_name}</div>
|
<div className="text-xl font-bold text-neutral-800">{course.authors[0].first_name} {course.authors[0].last_name} { (course.authors[0].first_name && course.authors[0].last_name) ? course.authors[0].first_name + ' ' + course.authors[0].last_name : course.authors[0].username }</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ export async function generateMetadata(
|
||||||
},
|
},
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title: course_meta.name + ` — ${org.name}`,
|
title: course_meta.name + ` — ${org.name}`,
|
||||||
description: course_meta.description,
|
description: course_meta.description ? course_meta.description : '',
|
||||||
type: 'article',
|
type: 'article',
|
||||||
publishedTime: course_meta.creation_date,
|
publishedTime: course_meta.creation_date ? course_meta.creation_date : '',
|
||||||
tags: course_meta.learnings,
|
tags: course_meta.learnings ? course_meta.learnings : [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue