summaryrefslogtreecommitdiff
path: root/app/controllers/sparkles/init.go
blob: c85a49d434c0be1abf438d35d6c68d68cc3ea6b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package sparkles

import (
	"net/http"

	"github.com/xlgmokha/x/pkg/mapper"
	"github.com/xlgmokha/x/pkg/serde"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)

func init() {
	mapper.Register[*http.Request, *domain.Sparkle](func(r *http.Request) *domain.Sparkle {
		sparkle, err := serde.FromHTTP[*domain.Sparkle](r)
		if err != nil {
			pls.LogError(r.Context(), err)
		}
		sparkle.Author = cfg.CurrentUser.From(r.Context())
		return sparkle
	})
}