add show course and map names

This commit is contained in:
Aleksandr Trushkin
2024-01-08 18:31:35 +03:00
parent 48f5d80f7a
commit 2c0564f68c
22 changed files with 166 additions and 90 deletions

View File

@ -14,7 +14,7 @@ import (
"git.loyso.art/frx/kurious/internal/common/generator"
"git.loyso.art/frx/kurious/internal/common/nullable"
"git.loyso.art/frx/kurious/internal/common/xcontext"
"git.loyso.art/frx/kurious/internal/common/xslice"
"git.loyso.art/frx/kurious/internal/common/xslices"
"git.loyso.art/frx/kurious/internal/kurious/app/command"
"git.loyso.art/frx/kurious/internal/kurious/app/query"
"git.loyso.art/frx/kurious/internal/kurious/domain"
@ -126,7 +126,7 @@ func (h *syncSravniHandler) Handle(ctx context.Context) (err error) {
return fmt.Errorf("loading educational products: %w", err)
}
xslice.ForEach(buffer, func(c sravni.Course) {
xslices.ForEach(buffer, func(c sravni.Course) {
c.Learningtype = []string{learningType.Value}
c.CourseThematics = []string{courseThematic}
courses = append(courses, c)
@ -155,7 +155,7 @@ func (h *syncSravniHandler) Handle(ctx context.Context) (err error) {
continue
}
xslice.ForEach(courses, func(c sravni.Course) {
xslices.ForEach(courses, func(c sravni.Course) {
h.knownExternalIDs[c.ID] = struct{}{}
})
@ -212,7 +212,7 @@ func (h *syncSravniHandler) loadEducationalProducts(ctx context.Context, learnin
}
func (h *syncSravniHandler) filterByCache(courses []sravni.Course) (toInsert []sravni.Course) {
toCut := xslice.FilterInplace(courses, xslice.Not(h.isCached))
toCut := xslices.FilterInplace(courses, xslices.Not(h.isCached))
return courses[:toCut]
}
@ -222,7 +222,7 @@ func (h *syncSravniHandler) isCached(course sravni.Course) bool {
}
func (h *syncSravniHandler) insertValues(ctx context.Context, courses []sravni.Course) error {
courseParams := xslice.Map(courses, courseAsCreateCourseParams)
courseParams := xslices.Map(courses, courseAsCreateCourseParams)
err := h.svc.Commands.InsertCourses.Handle(ctx, command.CreateCourses{
Courses: courseParams,
})
@ -249,7 +249,7 @@ func (h *syncSravniHandler) fillCaches(ctx context.Context) error {
h.knownExternalIDs = make(map[string]struct{}, len(courses))
xslice.ForEach(courses, func(c domain.Course) {
xslices.ForEach(courses, func(c domain.Course) {
if !c.ExternalID.Valid() {
return
}

View File

@ -9,7 +9,7 @@ import (
"git.loyso.art/frx/kurious/internal/common/errors"
"git.loyso.art/frx/kurious/internal/common/xcontext"
"git.loyso.art/frx/kurious/internal/common/xslice"
"git.loyso.art/frx/kurious/internal/common/xslices"
"git.loyso.art/frx/kurious/internal/kurious/app/command"
"git.loyso.art/frx/kurious/internal/kurious/app/query"
"git.loyso.art/frx/kurious/internal/kurious/domain"
@ -90,7 +90,7 @@ type listCoursesTemplateParams struct {
func mapDomainCourseToTemplate(in ...domain.Course) listCoursesTemplateParams {
coursesBySubcategory := make(map[string][]domain.Course, len(in))
subcategoriesByCategories := make(map[string]map[string]struct{}, len(in))
xslice.ForEach(in, func(c domain.Course) {
xslices.ForEach(in, func(c domain.Course) {
coursesBySubcategory[c.Thematic] = append(coursesBySubcategory[c.Thematic], c)
if _, ok := subcategoriesByCategories[c.LearningType]; !ok {
subcategoriesByCategories[c.LearningType] = map[string]struct{}{}
@ -216,7 +216,7 @@ func (c courseServer) RenderEditDescription(w http.ResponseWriter, r *http.Reque
func (c courseServer) UpdateCourseDescription(w http.ResponseWriter, r *http.Request) {
type requestModel struct {
ID string `json:"-"`
Text string `json:"text"`
Text string `json:"description"`
}
ctx := r.Context()

View File

@ -9,7 +9,7 @@ import (
"path"
"git.loyso.art/frx/kurious/internal/common/xcontext"
"git.loyso.art/frx/kurious/internal/common/xslice"
"git.loyso.art/frx/kurious/internal/common/xslices"
)
const baseTemplatePath = "./internal/kurious/ports/http/templates/"
@ -22,7 +22,7 @@ func must[T any](t T, err error) T {
}
func scanFiles() []string {
entries := xslice.Map(
entries := xslices.Map(
must(os.ReadDir(baseTemplatePath)),
func(v fs.DirEntry) string {
return path.Join(baseTemplatePath, v.Name())

View File

@ -9,13 +9,16 @@
</div>
<div class="card-content">
<div class="media-content">
<p class="title is-5">{{ .Name }}</p>
<p class="title is-5" onclick="location.href='{{ .OriginLink }}'">{{ .Name }}</p>
<p class="subtitle is-8">{{ .Description }}</p>
</div>
<div class="content">
<p>{{ .FullPrice }} rub.</p>
</div>
<button class="button" onclick="location.href='{{ .OriginLink }}'">
Show Course
</button>
<button class="button" hx-get="/courses/{{ .ID }}/editdesc">
Edit description
</button>
@ -49,7 +52,7 @@
<div class="field-body">
<div class="field">
<div class="control">
<textarea class="textarea" placeholder="Description">{{ .Description }}</textarea>
<textarea class="textarea" name="description" placeholder="Description">{{ .Description }}</textarea>
</div>
</div>
</div>
@ -59,7 +62,7 @@
</div>
<div class="field is-grouped">
<p class="control">
<button class="button is-primary is-link" hx-include="closest .control">
<button class="button is-primary is-link" hx-include="[name='description']">
Submit
</button>
</p>
@ -69,8 +72,6 @@
</button>
</p>
</div>
<!-- <button class="btn">Submit</button>
<button class="btn" hx-get="/courses/{{ .ID }}/short">Cancel</button> -->
</form>
{{ end }}