feat(api): add employer need contract with requirement versions and recommendations
This commit is contained in:
1 parent
3adb0ef9e4
commit
a7d5781f2d
95 files changed
+25352
-26
No files matched your search
@@ -21,6 +21,7 @@ var regexMap = map[string]ogenregex.Regexp{
|
||||
"^[A-Za-z0-9._-]+$": ogenregex.MustCompile("^[A-Za-z0-9._-]+$"),
|
||||
"^[A-Za-z0-9._:-]+$": ogenregex.MustCompile("^[A-Za-z0-9._:-]+$"),
|
||||
"^[A-Za-z0-9_-]+$": ogenregex.MustCompile("^[A-Za-z0-9_-]+$"),
|
||||
"^[a-z0-9][a-z0-9_.+#-]*$": ogenregex.MustCompile("^[a-z0-9][a-z0-9_.+#-]*$"),
|
||||
"^[a-z0-9_+-]+$": ogenregex.MustCompile("^[a-z0-9_+-]+$"),
|
||||
"^[a-z0-9_]+$": ogenregex.MustCompile("^[a-z0-9_]+$"),
|
||||
"^[a-z][a-z0-9_]*$": ogenregex.MustCompile("^[a-z][a-z0-9_]*$"),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -9,6 +9,10 @@ type CreateMyAssessmentAttemptRes interface {
|
||||
createMyAssessmentAttemptRes()
|
||||
}
|
||||
|
||||
type CreateOrganizationNeedRes interface {
|
||||
createOrganizationNeedRes()
|
||||
}
|
||||
|
||||
type FinalizeMyAssessmentAttemptRes interface {
|
||||
finalizeMyAssessmentAttemptRes()
|
||||
}
|
||||
@@ -41,6 +45,14 @@ type GetMyQuestionnaireRes interface {
|
||||
getMyQuestionnaireRes()
|
||||
}
|
||||
|
||||
type GetOrganizationNeedRes interface {
|
||||
getOrganizationNeedRes()
|
||||
}
|
||||
|
||||
type ListOrganizationNeedsRes interface {
|
||||
listOrganizationNeedsRes()
|
||||
}
|
||||
|
||||
type LoginRes interface {
|
||||
loginRes()
|
||||
}
|
||||
@@ -64,3 +76,7 @@ type SaveMyQuestionnaireRes interface {
|
||||
type SubmitMyAssessmentAnswerRes interface {
|
||||
submitMyAssessmentAnswerRes()
|
||||
}
|
||||
|
||||
type UpdateOrganizationNeedRes interface {
|
||||
updateOrganizationNeedRes()
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,7 @@ type OperationName = string
|
||||
const (
|
||||
ConfirmEmailOperation OperationName = "ConfirmEmail"
|
||||
CreateMyAssessmentAttemptOperation OperationName = "CreateMyAssessmentAttempt"
|
||||
CreateOrganizationNeedOperation OperationName = "CreateOrganizationNeed"
|
||||
FinalizeMyAssessmentAttemptOperation OperationName = "FinalizeMyAssessmentAttempt"
|
||||
GetConsentTextOperation OperationName = "GetConsentText"
|
||||
GetCurrentAccountOperation OperationName = "GetCurrentAccount"
|
||||
@@ -17,11 +18,14 @@ const (
|
||||
GetMyAssessmentAvailabilityOperation OperationName = "GetMyAssessmentAvailability"
|
||||
GetMyAssessmentResultOperation OperationName = "GetMyAssessmentResult"
|
||||
GetMyQuestionnaireOperation OperationName = "GetMyQuestionnaire"
|
||||
GetOrganizationNeedOperation OperationName = "GetOrganizationNeed"
|
||||
GetSpecializationCatalogOperation OperationName = "GetSpecializationCatalog"
|
||||
ListOrganizationNeedsOperation OperationName = "ListOrganizationNeeds"
|
||||
LoginOperation OperationName = "Login"
|
||||
LogoutOperation OperationName = "Logout"
|
||||
RegisterAccountOperation OperationName = "RegisterAccount"
|
||||
ResendEmailVerificationOperation OperationName = "ResendEmailVerification"
|
||||
SaveMyQuestionnaireOperation OperationName = "SaveMyQuestionnaire"
|
||||
SubmitMyAssessmentAnswerOperation OperationName = "SubmitMyAssessmentAnswer"
|
||||
UpdateOrganizationNeedOperation OperationName = "UpdateOrganizationNeed"
|
||||
)
|
||||
@@ -109,6 +109,157 @@ func decodeCreateMyAssessmentAttemptParams(args [0]string, argsEscaped bool, r *
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// CreateOrganizationNeedParams is parameters of CreateOrganizationNeed operation.
|
||||
type CreateOrganizationNeedParams struct {
|
||||
// Identifier of an organization. Access comes only from an active membership of the session account in
|
||||
// this organization, checked by the server on every request; the identifier itself grants nothing. An
|
||||
// organization without such a membership and an unknown identifier both answer 404 not_found, so
|
||||
// organizations cannot be enumerated.
|
||||
OrgID uuid.UUID
|
||||
// Client-generated key that makes a retried mutating command safe; a UUID v4 is recommended. The value
|
||||
// is sent without quotes. The server scopes the key by caller and operation and fingerprints the
|
||||
// request by method, path, and body.
|
||||
//
|
||||
// Stored for 24 hours after the first request and replayed with the same status, headers, and body:
|
||||
// the final 2xx outcome and final deterministic 4xx business outcomes of the command, such as 404
|
||||
// not_found or 409 state_conflict. A replay does not repeat the side effect.
|
||||
//
|
||||
// Not stored, so a retry with the same key is evaluated again: 400 validation_failed, 413, and 415 for
|
||||
// the request itself, 401 and 403, 409 idempotency_in_progress, 412 version_conflict and 428
|
||||
// precondition_required (nothing changed; read the resource again and retry), 422
|
||||
// idempotency_key_reused, 429, and every 5xx.
|
||||
//
|
||||
// Order of checks: authentication (401), request validation (400, 413, 415), authorization (403), then
|
||||
// the key. A stored or running request with a different fingerprint returns 422 idempotency_key_reused
|
||||
// before any other key check; a running request with the same fingerprint returns 409
|
||||
// idempotency_in_progress; a stored outcome with the same fingerprint is replayed. Only after that
|
||||
// does the server check If-Match, so a retry of a completed change replays its outcome instead of
|
||||
// failing on the version it has just changed. After 24 hours the key may be accepted as new.
|
||||
IdempotencyKey string
|
||||
}
|
||||
|
||||
func unpackCreateOrganizationNeedParams(packed middleware.Parameters) (params CreateOrganizationNeedParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "Idempotency-Key",
|
||||
In: "header",
|
||||
}
|
||||
params.IdempotencyKey = packed[key].(string)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeCreateOrganizationNeedParams(args [1]string, argsEscaped bool, r *http.Request) (params CreateOrganizationNeedParams, _ error) {
|
||||
h := uri.NewHeaderDecoder(r.Header)
|
||||
// Decode path: org_id.
|
||||
if err := func() error {
|
||||
param := args[0]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[0])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "org_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.OrgID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode header: Idempotency-Key.
|
||||
if err := func() error {
|
||||
cfg := uri.HeaderParameterDecodingConfig{
|
||||
Name: "Idempotency-Key",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.HasParam(cfg); err == nil {
|
||||
if err := h.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToString(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.IdempotencyKey = c
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 255,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: regexMap["^[A-Za-z0-9._:-]+$"],
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(params.IdempotencyKey)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "Idempotency-Key",
|
||||
In: "header",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// FinalizeMyAssessmentAttemptParams is parameters of FinalizeMyAssessmentAttempt operation.
|
||||
type FinalizeMyAssessmentAttemptParams struct {
|
||||
// Identifier of an assessment attempt of the current candidate. An attempt of another candidate and an
|
||||
@@ -466,6 +617,363 @@ func decodeGetMyAssessmentResultParams(args [1]string, argsEscaped bool, r *http
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// GetOrganizationNeedParams is parameters of GetOrganizationNeed operation.
|
||||
type GetOrganizationNeedParams struct {
|
||||
// Identifier of an organization. Access comes only from an active membership of the session account in
|
||||
// this organization, checked by the server on every request; the identifier itself grants nothing. An
|
||||
// organization without such a membership and an unknown identifier both answer 404 not_found, so
|
||||
// organizations cannot be enumerated.
|
||||
OrgID uuid.UUID
|
||||
// Identifier of a need of the organization in the path. A need of another organization and an unknown
|
||||
// identifier both answer 404 not_found.
|
||||
NeedID uuid.UUID
|
||||
}
|
||||
|
||||
func unpackGetOrganizationNeedParams(packed middleware.Parameters) (params GetOrganizationNeedParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "need_id",
|
||||
In: "path",
|
||||
}
|
||||
params.NeedID = packed[key].(uuid.UUID)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeGetOrganizationNeedParams(args [2]string, argsEscaped bool, r *http.Request) (params GetOrganizationNeedParams, _ error) {
|
||||
// Decode path: org_id.
|
||||
if err := func() error {
|
||||
param := args[0]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[0])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "org_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.OrgID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode path: need_id.
|
||||
if err := func() error {
|
||||
param := args[1]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[1])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "need_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.NeedID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "need_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListOrganizationNeedsParams is parameters of ListOrganizationNeeds operation.
|
||||
type ListOrganizationNeedsParams struct {
|
||||
// Identifier of an organization. Access comes only from an active membership of the session account in
|
||||
// this organization, checked by the server on every request; the identifier itself grants nothing. An
|
||||
// organization without such a membership and an unknown identifier both answer 404 not_found, so
|
||||
// organizations cannot be enumerated.
|
||||
OrgID uuid.UUID
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
// `page.has_more` to detect the end.
|
||||
Limit OptInt32 `json:",omitempty,omitzero"`
|
||||
// Opaque `page.next_cursor` value from the previous page of the same listing. Omit it to read the
|
||||
// first page. A malformed or foreign cursor returns 400 with code validation_failed.
|
||||
Cursor OptString `json:",omitempty,omitzero"`
|
||||
}
|
||||
|
||||
func unpackListOrganizationNeedsParams(packed middleware.Parameters) (params ListOrganizationNeedsParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Limit = v.(OptInt32)
|
||||
}
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Cursor = v.(OptString)
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeListOrganizationNeedsParams(args [1]string, argsEscaped bool, r *http.Request) (params ListOrganizationNeedsParams, _ error) {
|
||||
q := uri.NewQueryDecoder(r.URL.Query())
|
||||
// Decode path: org_id.
|
||||
if err := func() error {
|
||||
param := args[0]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[0])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "org_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.OrgID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Set default value for query: limit.
|
||||
{
|
||||
val := int32(20)
|
||||
params.Limit.SetTo(val)
|
||||
}
|
||||
// Decode query: limit.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "limit",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotLimitVal int32
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToInt32(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotLimitVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Limit.SetTo(paramsDotLimitVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Limit.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Int{
|
||||
MinSet: true,
|
||||
Min: 1,
|
||||
MaxSet: true,
|
||||
Max: 100,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: 0,
|
||||
Pattern: nil,
|
||||
}).Validate(int64(value)); err != nil {
|
||||
return errors.Wrap(err, "int")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode query: cursor.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "cursor",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotCursorVal string
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToString(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotCursorVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Cursor.SetTo(paramsDotCursorVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Cursor.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 512,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: regexMap["^[A-Za-z0-9_-]+$"],
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(value)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// RegisterAccountParams is parameters of RegisterAccount operation.
|
||||
type RegisterAccountParams struct {
|
||||
// Client-generated key that makes a retried mutating command safe; a UUID v4 is recommended. The value
|
||||
@@ -708,3 +1216,127 @@ func decodeSubmitMyAssessmentAnswerParams(args [1]string, argsEscaped bool, r *h
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// UpdateOrganizationNeedParams is parameters of UpdateOrganizationNeed operation.
|
||||
type UpdateOrganizationNeedParams struct {
|
||||
// Identifier of an organization. Access comes only from an active membership of the session account in
|
||||
// this organization, checked by the server on every request; the identifier itself grants nothing. An
|
||||
// organization without such a membership and an unknown identifier both answer 404 not_found, so
|
||||
// organizations cannot be enumerated.
|
||||
OrgID uuid.UUID
|
||||
// Identifier of a need of the organization in the path. A need of another organization and an unknown
|
||||
// identifier both answer 404 not_found.
|
||||
NeedID uuid.UUID
|
||||
}
|
||||
|
||||
func unpackUpdateOrganizationNeedParams(packed middleware.Parameters) (params UpdateOrganizationNeedParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "need_id",
|
||||
In: "path",
|
||||
}
|
||||
params.NeedID = packed[key].(uuid.UUID)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeUpdateOrganizationNeedParams(args [2]string, argsEscaped bool, r *http.Request) (params UpdateOrganizationNeedParams, _ error) {
|
||||
// Decode path: org_id.
|
||||
if err := func() error {
|
||||
param := args[0]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[0])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "org_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.OrgID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode path: need_id.
|
||||
if err := func() error {
|
||||
param := args[1]
|
||||
if argsEscaped {
|
||||
unescaped, err := url.PathUnescape(args[1])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unescape path")
|
||||
}
|
||||
param = unescaped
|
||||
}
|
||||
if len(param) > 0 {
|
||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
||||
Param: "need_id",
|
||||
Value: param,
|
||||
Style: uri.PathStyleSimple,
|
||||
Explode: false,
|
||||
})
|
||||
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToUUID(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params.NeedID = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return validate.ErrFieldRequired
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "need_id",
|
||||
In: "path",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
@@ -172,6 +172,85 @@ func (s *Server) decodeCreateMyAssessmentAttemptRequest(r *http.Request) (
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) decodeCreateOrganizationNeedRequest(r *http.Request) (
|
||||
req *NeedCreate,
|
||||
rawBody []byte,
|
||||
close func() error,
|
||||
rerr error,
|
||||
) {
|
||||
var closers []func() error
|
||||
close = func() error {
|
||||
var merr error
|
||||
// Close in reverse order, to match defer behavior.
|
||||
for i := len(closers) - 1; i >= 0; i-- {
|
||||
c := closers[i]
|
||||
merr = errors.Join(merr, c())
|
||||
}
|
||||
return merr
|
||||
}
|
||||
defer func() {
|
||||
if rerr != nil {
|
||||
rerr = errors.Join(rerr, close())
|
||||
}
|
||||
}()
|
||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
return req, rawBody, close, errors.Wrap(err, "parse media type")
|
||||
}
|
||||
switch {
|
||||
case ct == "application/json":
|
||||
if r.ContentLength == 0 {
|
||||
return req, rawBody, close, validate.ErrBodyRequired
|
||||
}
|
||||
buf, err := io.ReadAll(r.Body)
|
||||
defer func() {
|
||||
_ = r.Body.Close()
|
||||
}()
|
||||
if err != nil {
|
||||
return req, rawBody, close, err
|
||||
}
|
||||
|
||||
// Reset the body to allow for downstream reading.
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
|
||||
if len(buf) == 0 {
|
||||
return req, rawBody, close, validate.ErrBodyRequired
|
||||
}
|
||||
|
||||
rawBody = append(rawBody, buf...)
|
||||
d := jx.DecodeBytes(buf)
|
||||
|
||||
var request NeedCreate
|
||||
if err := func() error {
|
||||
if err := request.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.Skip(); err != io.EOF {
|
||||
return errors.New("unexpected trailing data")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
err = &ogenerrors.DecodeBodyError{
|
||||
ContentType: ct,
|
||||
Body: buf,
|
||||
Err: err,
|
||||
}
|
||||
return req, rawBody, close, err
|
||||
}
|
||||
if err := func() error {
|
||||
if err := request.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return req, rawBody, close, errors.Wrap(err, "validate")
|
||||
}
|
||||
return &request, rawBody, close, nil
|
||||
default:
|
||||
return req, rawBody, close, validate.InvalidContentType(ct)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) decodeFinalizeMyAssessmentAttemptRequest(r *http.Request) (
|
||||
req *AssessmentFinalization,
|
||||
rawBody []byte,
|
||||
@@ -645,3 +724,82 @@ func (s *Server) decodeSubmitMyAssessmentAnswerRequest(r *http.Request) (
|
||||
return req, rawBody, close, validate.InvalidContentType(ct)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) decodeUpdateOrganizationNeedRequest(r *http.Request) (
|
||||
req *NeedUpdate,
|
||||
rawBody []byte,
|
||||
close func() error,
|
||||
rerr error,
|
||||
) {
|
||||
var closers []func() error
|
||||
close = func() error {
|
||||
var merr error
|
||||
// Close in reverse order, to match defer behavior.
|
||||
for i := len(closers) - 1; i >= 0; i-- {
|
||||
c := closers[i]
|
||||
merr = errors.Join(merr, c())
|
||||
}
|
||||
return merr
|
||||
}
|
||||
defer func() {
|
||||
if rerr != nil {
|
||||
rerr = errors.Join(rerr, close())
|
||||
}
|
||||
}()
|
||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||
if err != nil {
|
||||
return req, rawBody, close, errors.Wrap(err, "parse media type")
|
||||
}
|
||||
switch {
|
||||
case ct == "application/json":
|
||||
if r.ContentLength == 0 {
|
||||
return req, rawBody, close, validate.ErrBodyRequired
|
||||
}
|
||||
buf, err := io.ReadAll(r.Body)
|
||||
defer func() {
|
||||
_ = r.Body.Close()
|
||||
}()
|
||||
if err != nil {
|
||||
return req, rawBody, close, err
|
||||
}
|
||||
|
||||
// Reset the body to allow for downstream reading.
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
|
||||
if len(buf) == 0 {
|
||||
return req, rawBody, close, validate.ErrBodyRequired
|
||||
}
|
||||
|
||||
rawBody = append(rawBody, buf...)
|
||||
d := jx.DecodeBytes(buf)
|
||||
|
||||
var request NeedUpdate
|
||||
if err := func() error {
|
||||
if err := request.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.Skip(); err != io.EOF {
|
||||
return errors.New("unexpected trailing data")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
err = &ogenerrors.DecodeBodyError{
|
||||
ContentType: ct,
|
||||
Body: buf,
|
||||
Err: err,
|
||||
}
|
||||
return req, rawBody, close, err
|
||||
}
|
||||
if err := func() error {
|
||||
if err := request.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return req, rawBody, close, errors.Wrap(err, "validate")
|
||||
}
|
||||
return &request, rawBody, close, nil
|
||||
default:
|
||||
return req, rawBody, close, validate.InvalidContentType(ct)
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,145 @@ func encodeCreateMyAssessmentAttemptResponse(response CreateMyAssessmentAttemptR
|
||||
}
|
||||
}
|
||||
|
||||
func encodeCreateOrganizationNeedResponse(response CreateOrganizationNeedRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *NeedHeaders:
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Cache-Control" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Cache-Control",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
return e.EncodeValue(conv.StringToString(string(response.CacheControl)))
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Cache-Control header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(201)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedBadRequest:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(400)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedUnauthorized:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(401)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedForbidden:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(403)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedNotFound:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(404)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedConflict:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(409)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *CreateOrganizationNeedUnprocessableEntity:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(422)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *TooManyRequestsHeaders:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Retry-After")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Retry-After" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Retry-After",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := response.RetryAfter.Get(); ok {
|
||||
return e.EncodeValue(conv.Int32ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Retry-After header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(429)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.Errorf("unexpected response type: %T", response)
|
||||
}
|
||||
}
|
||||
|
||||
func encodeFinalizeMyAssessmentAttemptResponse(response FinalizeMyAssessmentAttemptRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *AssessmentAttemptHeaders:
|
||||
@@ -745,6 +884,89 @@ func encodeGetMyQuestionnaireResponse(response GetMyQuestionnaireRes, w http.Res
|
||||
}
|
||||
}
|
||||
|
||||
func encodeGetOrganizationNeedResponse(response GetOrganizationNeedRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *NeedHeaders:
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Cache-Control" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Cache-Control",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
return e.EncodeValue(conv.StringToString(string(response.CacheControl)))
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Cache-Control header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *GetOrganizationNeedBadRequest:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(400)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *GetOrganizationNeedUnauthorized:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(401)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *GetOrganizationNeedForbidden:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(403)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *GetOrganizationNeedNotFound:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(404)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.Errorf("unexpected response type: %T", response)
|
||||
}
|
||||
}
|
||||
|
||||
func encodeGetSpecializationCatalogResponse(response *SpecializationCatalog, w http.ResponseWriter, span trace.Span) error {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(200)
|
||||
@@ -758,6 +980,89 @@ func encodeGetSpecializationCatalogResponse(response *SpecializationCatalog, w h
|
||||
return nil
|
||||
}
|
||||
|
||||
func encodeListOrganizationNeedsResponse(response ListOrganizationNeedsRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *NeedListHeaders:
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Cache-Control" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Cache-Control",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
return e.EncodeValue(conv.StringToString(string(response.CacheControl)))
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Cache-Control header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *ListOrganizationNeedsBadRequest:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(400)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *ListOrganizationNeedsUnauthorized:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(401)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *ListOrganizationNeedsForbidden:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(403)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *ListOrganizationNeedsNotFound:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(404)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.Errorf("unexpected response type: %T", response)
|
||||
}
|
||||
}
|
||||
|
||||
func encodeLoginResponse(response LoginRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *SessionHeaders:
|
||||
@@ -1352,6 +1657,133 @@ func encodeSubmitMyAssessmentAnswerResponse(response SubmitMyAssessmentAnswerRes
|
||||
}
|
||||
}
|
||||
|
||||
func encodeUpdateOrganizationNeedResponse(response UpdateOrganizationNeedRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *NeedHeaders:
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Cache-Control" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Cache-Control",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
return e.EncodeValue(conv.StringToString(string(response.CacheControl)))
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Cache-Control header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *UpdateOrganizationNeedBadRequest:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(400)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *UpdateOrganizationNeedUnauthorized:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(401)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *UpdateOrganizationNeedForbidden:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(403)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *UpdateOrganizationNeedNotFound:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(404)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *UpdateOrganizationNeedPreconditionFailed:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(412)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *TooManyRequestsHeaders:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Retry-After")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Retry-After" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Retry-After",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := response.RetryAfter.Get(); ok {
|
||||
return e.EncodeValue(conv.Int32ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Retry-After header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(429)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
default:
|
||||
return errors.Errorf("unexpected response type: %T", response)
|
||||
}
|
||||
}
|
||||
|
||||
func encodeErrorResponse(response *ProblemStatusCode, w http.ResponseWriter, span trace.Span) error {
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
code := response.StatusCode
|
||||
|
||||
@@ -11,32 +11,38 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
rn23AllowedHeaders = map[string]string{
|
||||
rn28AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn1AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn21AllowedHeaders = map[string]string{
|
||||
rn26AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key",
|
||||
}
|
||||
rn20AllowedHeaders = map[string]string{
|
||||
rn25AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn11AllowedHeaders = map[string]string{
|
||||
rn14AllowedHeaders = map[string]string{
|
||||
"DELETE": "X-Csrf-Token",
|
||||
}
|
||||
rn3AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn24AllowedHeaders = map[string]string{
|
||||
rn29AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn9AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn21AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn6AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn18AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
rn23AllowedHeaders = map[string]string{
|
||||
"PATCH": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -70,7 +76,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.notFound(w, r)
|
||||
return
|
||||
}
|
||||
args := [1]string{}
|
||||
args := [2]string{}
|
||||
|
||||
// Static code generated router with unwrapped path search.
|
||||
switch {
|
||||
@@ -192,7 +198,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn23AllowedHeaders,
|
||||
allowedHeaders: rn28AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -269,7 +275,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn21AllowedHeaders,
|
||||
allowedHeaders: rn26AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -293,7 +299,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn20AllowedHeaders,
|
||||
allowedHeaders: rn25AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -320,7 +326,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "DELETE,GET",
|
||||
allowedHeaders: rn11AllowedHeaders,
|
||||
allowedHeaders: rn14AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -446,7 +452,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn24AllowedHeaders,
|
||||
allowedHeaders: rn29AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -473,7 +479,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn6AllowedHeaders,
|
||||
allowedHeaders: rn9AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -560,7 +566,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PUT",
|
||||
allowedHeaders: rn18AllowedHeaders,
|
||||
allowedHeaders: rn21AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -571,6 +577,103 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
case 'o': // Prefix: "organizations/"
|
||||
|
||||
if l := len("organizations/"); len(elem) >= l && elem[0:l] == "organizations/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "org_id"
|
||||
// Match until "/"
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx < 0 {
|
||||
idx = len(elem)
|
||||
}
|
||||
args[0] = elem[:idx]
|
||||
elem = elem[idx:]
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/needs"
|
||||
|
||||
if l := len("/needs"); len(elem) >= l && elem[0:l] == "/needs" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleListOrganizationNeedsRequest([1]string{
|
||||
args[0],
|
||||
}, elemIsEscaped, w, r)
|
||||
case "POST":
|
||||
s.handleCreateOrganizationNeedRequest([1]string{
|
||||
args[0],
|
||||
}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,POST",
|
||||
allowedHeaders: rn6AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "need_id"
|
||||
// Leaf parameter, slashes are prohibited
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx >= 0 {
|
||||
break
|
||||
}
|
||||
args[1] = elem
|
||||
elem = ""
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleGetOrganizationNeedRequest([2]string{
|
||||
args[0],
|
||||
args[1],
|
||||
}, elemIsEscaped, w, r)
|
||||
case "PATCH":
|
||||
s.handleUpdateOrganizationNeedRequest([2]string{
|
||||
args[0],
|
||||
args[1],
|
||||
}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PATCH",
|
||||
allowedHeaders: rn23AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "application/json",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "specializations"
|
||||
|
||||
if l := len("specializations"); len(elem) >= l && elem[0:l] == "specializations" {
|
||||
@@ -611,7 +714,7 @@ type Route struct {
|
||||
operationGroup string
|
||||
pathPattern string
|
||||
count int
|
||||
args [1]string
|
||||
args [2]string
|
||||
}
|
||||
|
||||
// Name returns ogen operation name.
|
||||
@@ -1180,6 +1283,107 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
||||
|
||||
}
|
||||
|
||||
case 'o': // Prefix: "organizations/"
|
||||
|
||||
if l := len("organizations/"); len(elem) >= l && elem[0:l] == "organizations/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "org_id"
|
||||
// Match until "/"
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx < 0 {
|
||||
idx = len(elem)
|
||||
}
|
||||
args[0] = elem[:idx]
|
||||
elem = elem[idx:]
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/needs"
|
||||
|
||||
if l := len("/needs"); len(elem) >= l && elem[0:l] == "/needs" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = ListOrganizationNeedsOperation
|
||||
r.summary = "List the needs of an organization."
|
||||
r.operationID = "ListOrganizationNeeds"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/organizations/{org_id}/needs"
|
||||
r.args = args
|
||||
r.count = 1
|
||||
return r, true
|
||||
case "POST":
|
||||
r.name = CreateOrganizationNeedOperation
|
||||
r.summary = "Create a need of an organization from a form, a text, or both."
|
||||
r.operationID = "CreateOrganizationNeed"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/organizations/{org_id}/needs"
|
||||
r.args = args
|
||||
r.count = 1
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "need_id"
|
||||
// Leaf parameter, slashes are prohibited
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx >= 0 {
|
||||
break
|
||||
}
|
||||
args[1] = elem
|
||||
elem = ""
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = GetOrganizationNeedOperation
|
||||
r.summary = "Read the current version of a need of an organization."
|
||||
r.operationID = "GetOrganizationNeed"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/organizations/{org_id}/needs/{need_id}"
|
||||
r.args = args
|
||||
r.count = 2
|
||||
return r, true
|
||||
case "PATCH":
|
||||
r.name = UpdateOrganizationNeedOperation
|
||||
r.summary = "Confirm, change, or delete requirements of a need."
|
||||
r.operationID = "UpdateOrganizationNeed"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/organizations/{org_id}/needs/{need_id}"
|
||||
r.args = args
|
||||
r.count = 2
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "specializations"
|
||||
|
||||
if l := len("specializations"); len(elem) >= l && elem[0:l] == "specializations" {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -57,6 +57,7 @@ func findAuthorization(h http.Header, prefix string) (string, bool) {
|
||||
// operationRolesSessionCookie is a private map storing roles per operation.
|
||||
var operationRolesSessionCookie = map[string][]string{
|
||||
CreateMyAssessmentAttemptOperation: []string{},
|
||||
CreateOrganizationNeedOperation: []string{},
|
||||
FinalizeMyAssessmentAttemptOperation: []string{},
|
||||
GetCurrentAccountOperation: []string{},
|
||||
GetCurrentSessionOperation: []string{},
|
||||
@@ -64,9 +65,12 @@ var operationRolesSessionCookie = map[string][]string{
|
||||
GetMyAssessmentAvailabilityOperation: []string{},
|
||||
GetMyAssessmentResultOperation: []string{},
|
||||
GetMyQuestionnaireOperation: []string{},
|
||||
GetOrganizationNeedOperation: []string{},
|
||||
ListOrganizationNeedsOperation: []string{},
|
||||
LogoutOperation: []string{},
|
||||
SaveMyQuestionnaireOperation: []string{},
|
||||
SubmitMyAssessmentAnswerOperation: []string{},
|
||||
UpdateOrganizationNeedOperation: []string{},
|
||||
}
|
||||
|
||||
// GetRolesForSessionCookie returns the required roles for the given operation.
|
||||
@@ -93,10 +97,12 @@ func GetRolesForSessionCookie(operation string) []string {
|
||||
// operationRolesSessionCsrf is a private map storing roles per operation.
|
||||
var operationRolesSessionCsrf = map[string][]string{
|
||||
CreateMyAssessmentAttemptOperation: []string{},
|
||||
CreateOrganizationNeedOperation: []string{},
|
||||
FinalizeMyAssessmentAttemptOperation: []string{},
|
||||
LogoutOperation: []string{},
|
||||
SaveMyQuestionnaireOperation: []string{},
|
||||
SubmitMyAssessmentAnswerOperation: []string{},
|
||||
UpdateOrganizationNeedOperation: []string{},
|
||||
}
|
||||
|
||||
// GetRolesForSessionCsrf returns the required roles for the given operation.
|
||||
|
||||
@@ -74,6 +74,59 @@ type Handler interface {
|
||||
//
|
||||
// POST /api/v1/me/assessment-attempts
|
||||
CreateMyAssessmentAttempt(ctx context.Context, req *AssessmentAttemptCreate, params CreateMyAssessmentAttemptParams) (CreateMyAssessmentAttemptRes, error)
|
||||
// CreateOrganizationNeed implements CreateOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
// token of that session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The organization
|
||||
// comes from the path and the server-side membership; the body has no organization, membership, or
|
||||
// role field. In the MVP only the owner of the organization may create a need; the other roles of PRD
|
||||
// FR07 are planned.
|
||||
//
|
||||
// A need does not require a vacancy: `vacancy_id` is optional and nullable. When it is given, it must
|
||||
// name a vacancy of the same organization; until vacancies exist in the contract, any vacancy
|
||||
// identifier answers 400 with the pointer `/vacancy_id`, the same for an unknown vacancy and one of
|
||||
// another organization.
|
||||
//
|
||||
// Only `title` is required. A field is sent as a decision `{value, status}` and a list item as
|
||||
// `{name or text, status}`; on creation the status must be `confirmed`, and the value becomes a
|
||||
// confirmed manual value. When `source_text` is given, the server extracts suggestions for the absent
|
||||
// fields with deterministic rules and a dictionary before it answers, so creation works while the ML
|
||||
// service is disabled; every suggestion has the status `extracted`, the origin extracted_from_text, a
|
||||
// quote where the extractor found one, and the extractor version, and it waits for a member to confirm
|
||||
// it. A field that the text does not state stays `unknown` with null value and source; the server
|
||||
// never guesses a grade, a format, or a salary. ML suggestions with quotes are planned as an
|
||||
// asynchronous addition that creates a new version and never overwrites a confirmed value.
|
||||
//
|
||||
// The need is saved even when critical fields are missing: the response is 201 with version 1, and
|
||||
// `readiness.missing_fields` names each critical field without a confirmed value with a specific
|
||||
// question. `recommendations` is computed by the server from the confirmed requirements only; the
|
||||
// request cannot set a recommendation, its score, or its components. Creating a need never contacts a
|
||||
// candidate or sends an invitation.
|
||||
//
|
||||
// Salary limit: setting a salary range counts against a limit shared by the whole organization, every
|
||||
// member and every need, on creation as on a change: at most three range settings a day (PRD FR13,
|
||||
// planned in TASK-211). Over the limit the server answers 429 with Retry-After and creates nothing.
|
||||
// After five settings within seven days the money component of the recommendations is `withheld` for
|
||||
// seven days. The limit keeps an organization from probing hidden candidate minimums with new needs
|
||||
// instead of edits; repeated range changes also feed the private risk signals of TASK-319.
|
||||
//
|
||||
// Idempotency: a retry with the same key and body within 24 hours replays the stored 201 and creates
|
||||
// nothing, so a lost response never creates a second need. A different body with the same key answers
|
||||
// 422 idempotency_key_reused. 400 is never stored, so a corrected retry is evaluated again.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for a candidate), membership (404 not_found) and role (403
|
||||
// forbidden), the Idempotency-Key (422, 409 idempotency_in_progress, replay), domain rules (400 with a
|
||||
// pointer: `/salary/value/salary_to` for a range whose lower bound is not below the upper one or whose
|
||||
// width is outside 10-40%, `/required_skills/1/name` for a repeated skill, `/grade/status` or
|
||||
// `/required_skills/0/status` for `extracted`, which a new need cannot have, or `/vacancy_id`), then
|
||||
// the salary limit (429). The schema already rejects unknown fields such as `rec_score`, `members`, or
|
||||
// `candidate_minimum`, a field sent as a bare value instead of `{value, status}`, a salary bound that
|
||||
// is not a positive multiple of 1000, and an unknown currency, period, or tax basis. The general rate
|
||||
// limit can answer 429 with Retry-After before any check. 429 is never stored.
|
||||
//
|
||||
// POST /api/v1/organizations/{org_id}/needs
|
||||
CreateOrganizationNeed(ctx context.Context, req *NeedCreate, params CreateOrganizationNeedParams) (CreateOrganizationNeedRes, error)
|
||||
// FinalizeMyAssessmentAttempt implements FinalizeMyAssessmentAttempt operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
@@ -234,6 +287,37 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/me/questionnaire
|
||||
GetMyQuestionnaire(ctx context.Context) (GetMyQuestionnaireRes, error)
|
||||
// GetOrganizationNeed implements GetOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`. The
|
||||
// organization and the role come from the server-side membership, never from the request. In the MVP
|
||||
// only the owner of the organization reads needs; the other roles of PRD FR07 are planned.
|
||||
//
|
||||
// Returns the current version of the need: `version`, the requirements with the confirmation state and
|
||||
// provenance of each field (`status`, and `source` with the origin, the quote, the version whose text
|
||||
// the quote belongs to, and the extractor version), the readiness with `missing_fields`, and the
|
||||
// category recommendations of the server. A field with status `unknown` has null value and source; an
|
||||
// `extracted` value is a suggestion that waits for confirmation and never feeds search or
|
||||
// recommendations.
|
||||
//
|
||||
// Versions: every committed change creates a new immutable `version`, and this operation always
|
||||
// returns the latest one. `requirements_version` is the version in which the confirmed requirements
|
||||
// were last changed; a change of the title, the vacancy link, the text, or suggestions only keeps it.
|
||||
// Search runs, selection snapshots, and invitations refer to a need by its identifier and
|
||||
// `requirements_version`, so they keep the requirements they used, and only a new
|
||||
// `requirements_version` calls for a new selection snapshot. Reading and comparing earlier versions
|
||||
// (PRD FR10) are planned as separate operations that return the same NeedRequirementSet for a given
|
||||
// version; they add no field here.
|
||||
//
|
||||
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
|
||||
// account answers 403 forbidden; an account without an active membership in the organization, an
|
||||
// unknown organization, an unknown need, and a need of another organization all answer 404 not_found,
|
||||
// so identifiers cannot be probed; a member whose role does not allow reading the need answers 403
|
||||
// forbidden. An `org_id` or `need_id` that is not a UUID answers 400 validation_failed with the path
|
||||
// pointer.
|
||||
//
|
||||
// GET /api/v1/organizations/{org_id}/needs/{need_id}
|
||||
GetOrganizationNeed(ctx context.Context, params GetOrganizationNeedParams) (GetOrganizationNeedRes, error)
|
||||
// GetSpecializationCatalog implements GetSpecializationCatalog operation.
|
||||
//
|
||||
// Public operation without a session. Returns the directions with their specializations, the
|
||||
@@ -254,6 +338,27 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/specializations
|
||||
GetSpecializationCatalog(ctx context.Context) (*SpecializationCatalog, error)
|
||||
// ListOrganizationNeeds implements ListOrganizationNeeds operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`. The
|
||||
// organization and the role come from the membership that the server holds for the session account,
|
||||
// never from the request. In the MVP only the owner of the organization works with needs; the other
|
||||
// roles of the PRD FR07 matrix (recruiter, hiring manager and technical expert for assigned needs) are
|
||||
// planned and change no field of this contract. The list holds only the needs that the role may read.
|
||||
//
|
||||
// Returns a page of need summaries, newest first by creation time with the identifier as the
|
||||
// tie-breaker, with cursor pagination. A summary has the current version, the target specialization
|
||||
// and grade with their confirmation state, and the readiness; GetOrganizationNeed returns the
|
||||
// requirements and the recommendations.
|
||||
//
|
||||
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
|
||||
// account answers 403 forbidden; an account without an active membership in the organization and an
|
||||
// unknown organization both answer 404 not_found, so organizations cannot be enumerated; a member
|
||||
// whose role does not allow reading needs answers 403 forbidden. A malformed `org_id`, `limit`, or
|
||||
// `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/organizations/{org_id}/needs
|
||||
ListOrganizationNeeds(ctx context.Context, params ListOrganizationNeedsParams) (ListOrganizationNeedsRes, error)
|
||||
// Login implements Login operation.
|
||||
//
|
||||
// Public operation that starts a server session. The server verifies the password with Argon2id; for
|
||||
@@ -441,6 +546,73 @@ type Handler interface {
|
||||
//
|
||||
// POST /api/v1/me/assessment-attempts/{attempt_id}/answers
|
||||
SubmitMyAssessmentAnswer(ctx context.Context, req *AssessmentAnswerSubmission, params SubmitMyAssessmentAnswerParams) (SubmitMyAssessmentAnswerRes, error)
|
||||
// UpdateOrganizationNeed implements UpdateOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
// token of that session in X-CSRF-Token, and an allowed Origin. The organization and the role come
|
||||
// from the server-side membership; the body has no organization, membership, or role field. In the MVP
|
||||
// only the owner of the organization changes needs; the technical expert, who may refine the
|
||||
// requirements of assigned needs under PRD FR07, is planned.
|
||||
//
|
||||
// Merge rules: the body is `application/json` with explicit field replacement, not JSON Merge Patch.
|
||||
// Each field present replaces that field as a whole and an absent field stays unchanged; a field
|
||||
// decision and each list are replaced entirely and never merged. This keeps every field one optional
|
||||
// value in the generated server and client, without nested partial updates.
|
||||
//
|
||||
// Each requirement field is sent as a decision `{value, status}` and each list item as
|
||||
// `{name or text, status}`, so confirmation is always explicit:
|
||||
//
|
||||
// - Confirm a suggestion: send its stored value with `confirmed`. It keeps its origin and quote.
|
||||
// - Keep a suggestion open: send its stored value with `extracted`, or leave the field out.
|
||||
// `extracted` with any other value, or for a field or item without a stored suggestion, answers 400
|
||||
// with the pointer of that `status`, for example `/grade/status` or `/required_skills/2/status`. A
|
||||
// client that sends back an unchanged form therefore never confirms a suggestion by accident.
|
||||
// - Change: send another value with `confirmed`. It becomes a confirmed manual value, and its quote
|
||||
// is dropped.
|
||||
// - Delete: send null for a nullable field, which makes it `unknown` (or unlinks `vacancy_id`), or
|
||||
// leave the item out of a skill or task list, which deletes it. An empty skill or task list deletes
|
||||
// every item; a list sent as null answers 400. A deleted requirement really changes the
|
||||
// requirements that search uses, not only an explanation, and a deleted suggestion is not proposed
|
||||
// again by a later extraction.
|
||||
// - Text: a different `source_text` extracts again. New suggestions replace only the `extracted`
|
||||
// values and items of the fields not named in the body; confirmed values are never overwritten, and
|
||||
// a suggested skill whose name is already in either skill list is skipped. Null removes the text
|
||||
// and keeps every value.
|
||||
//
|
||||
// Versions: every committed change creates version `expected_version + 1` as an immutable snapshot and
|
||||
// answers 200 with it. `requirements_version` becomes the new version only when a confirmed
|
||||
// requirement was confirmed, changed, or removed. `expected_version` is the `version` the client read;
|
||||
// when it is not current, the server answers 412 version_conflict and changes nothing, and the client
|
||||
// reads the need again and reapplies its unsaved edits. The version travels in the body rather than in
|
||||
// If-Match because the generated client cannot read the ETag response header yet, as for the
|
||||
// questionnaire. Concurrent changes therefore never overwrite each other silently.
|
||||
//
|
||||
// The operation needs no Idempotency-Key: a body that changes nothing when applied to the current
|
||||
// version, such as a retry of a change that already succeeded, keeps the version and answers 200 with
|
||||
// the current need even when `expected_version` is older. An incomplete need is a valid result;
|
||||
// `readiness.missing_fields` tells what remains.
|
||||
//
|
||||
// Salary limit: the recommendations aggregate candidates' minimums against the upper bound, so setting
|
||||
// or changing a confirmed salary range counts against a limit shared by the whole organization, every
|
||||
// member and every need, together with ranges set on creation: at most three a day (PRD FR13, planned
|
||||
// in TASK-211). Over the limit the server answers 429 with Retry-After and changes nothing. After five
|
||||
// settings within seven days the money component is `withheld` for seven days. Repeated range changes
|
||||
// also feed the private risk signals of TASK-319.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for a candidate), membership (404 not_found) and role (403
|
||||
// forbidden), the need (404 not_found), a body that changes nothing (200), the version (412), domain
|
||||
// rules (400 with a pointer such as `/salary/value/salary_to` for a range whose lower bound is not
|
||||
// below the upper one or whose width is outside 10-40%, `/desired_skills/0/name` for a skill that is
|
||||
// also in the required list, `/grade/status` or `/required_skills/2/status` for `extracted` with a
|
||||
// value that is not the stored suggestion, or `/vacancy_id`), then the salary change limit (429). The
|
||||
// schema rejects a missing or non-positive `expected_version`, unknown fields such as `rec_score`,
|
||||
// `members`, `candidate_minimum`, or `version`, a field sent as a bare value instead of
|
||||
// `{value, status}`, a list sent as null, a salary bound that is not a positive multiple of 1000, and
|
||||
// an unknown currency, period, or tax basis.
|
||||
//
|
||||
// PATCH /api/v1/organizations/{org_id}/needs/{need_id}
|
||||
UpdateOrganizationNeed(ctx context.Context, req *NeedUpdate, params UpdateOrganizationNeedParams) (UpdateOrganizationNeedRes, error)
|
||||
// NewError creates *ProblemStatusCode from error returned by handler.
|
||||
//
|
||||
// Used for common default response.
|
||||
|
||||
@@ -85,6 +85,62 @@ func (UnimplementedHandler) CreateMyAssessmentAttempt(ctx context.Context, req *
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// CreateOrganizationNeed implements CreateOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
// token of that session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The organization
|
||||
// comes from the path and the server-side membership; the body has no organization, membership, or
|
||||
// role field. In the MVP only the owner of the organization may create a need; the other roles of PRD
|
||||
// FR07 are planned.
|
||||
//
|
||||
// A need does not require a vacancy: `vacancy_id` is optional and nullable. When it is given, it must
|
||||
// name a vacancy of the same organization; until vacancies exist in the contract, any vacancy
|
||||
// identifier answers 400 with the pointer `/vacancy_id`, the same for an unknown vacancy and one of
|
||||
// another organization.
|
||||
//
|
||||
// Only `title` is required. A field is sent as a decision `{value, status}` and a list item as
|
||||
// `{name or text, status}`; on creation the status must be `confirmed`, and the value becomes a
|
||||
// confirmed manual value. When `source_text` is given, the server extracts suggestions for the absent
|
||||
// fields with deterministic rules and a dictionary before it answers, so creation works while the ML
|
||||
// service is disabled; every suggestion has the status `extracted`, the origin extracted_from_text, a
|
||||
// quote where the extractor found one, and the extractor version, and it waits for a member to confirm
|
||||
// it. A field that the text does not state stays `unknown` with null value and source; the server
|
||||
// never guesses a grade, a format, or a salary. ML suggestions with quotes are planned as an
|
||||
// asynchronous addition that creates a new version and never overwrites a confirmed value.
|
||||
//
|
||||
// The need is saved even when critical fields are missing: the response is 201 with version 1, and
|
||||
// `readiness.missing_fields` names each critical field without a confirmed value with a specific
|
||||
// question. `recommendations` is computed by the server from the confirmed requirements only; the
|
||||
// request cannot set a recommendation, its score, or its components. Creating a need never contacts a
|
||||
// candidate or sends an invitation.
|
||||
//
|
||||
// Salary limit: setting a salary range counts against a limit shared by the whole organization, every
|
||||
// member and every need, on creation as on a change: at most three range settings a day (PRD FR13,
|
||||
// planned in TASK-211). Over the limit the server answers 429 with Retry-After and creates nothing.
|
||||
// After five settings within seven days the money component of the recommendations is `withheld` for
|
||||
// seven days. The limit keeps an organization from probing hidden candidate minimums with new needs
|
||||
// instead of edits; repeated range changes also feed the private risk signals of TASK-319.
|
||||
//
|
||||
// Idempotency: a retry with the same key and body within 24 hours replays the stored 201 and creates
|
||||
// nothing, so a lost response never creates a second need. A different body with the same key answers
|
||||
// 422 idempotency_key_reused. 400 is never stored, so a corrected retry is evaluated again.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for a candidate), membership (404 not_found) and role (403
|
||||
// forbidden), the Idempotency-Key (422, 409 idempotency_in_progress, replay), domain rules (400 with a
|
||||
// pointer: `/salary/value/salary_to` for a range whose lower bound is not below the upper one or whose
|
||||
// width is outside 10-40%, `/required_skills/1/name` for a repeated skill, `/grade/status` or
|
||||
// `/required_skills/0/status` for `extracted`, which a new need cannot have, or `/vacancy_id`), then
|
||||
// the salary limit (429). The schema already rejects unknown fields such as `rec_score`, `members`, or
|
||||
// `candidate_minimum`, a field sent as a bare value instead of `{value, status}`, a salary bound that
|
||||
// is not a positive multiple of 1000, and an unknown currency, period, or tax basis. The general rate
|
||||
// limit can answer 429 with Retry-After before any check. 429 is never stored.
|
||||
//
|
||||
// POST /api/v1/organizations/{org_id}/needs
|
||||
func (UnimplementedHandler) CreateOrganizationNeed(ctx context.Context, req *NeedCreate, params CreateOrganizationNeedParams) (r CreateOrganizationNeedRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// FinalizeMyAssessmentAttempt implements FinalizeMyAssessmentAttempt operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
@@ -272,6 +328,40 @@ func (UnimplementedHandler) GetMyQuestionnaire(ctx context.Context) (r GetMyQues
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetOrganizationNeed implements GetOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`. The
|
||||
// organization and the role come from the server-side membership, never from the request. In the MVP
|
||||
// only the owner of the organization reads needs; the other roles of PRD FR07 are planned.
|
||||
//
|
||||
// Returns the current version of the need: `version`, the requirements with the confirmation state and
|
||||
// provenance of each field (`status`, and `source` with the origin, the quote, the version whose text
|
||||
// the quote belongs to, and the extractor version), the readiness with `missing_fields`, and the
|
||||
// category recommendations of the server. A field with status `unknown` has null value and source; an
|
||||
// `extracted` value is a suggestion that waits for confirmation and never feeds search or
|
||||
// recommendations.
|
||||
//
|
||||
// Versions: every committed change creates a new immutable `version`, and this operation always
|
||||
// returns the latest one. `requirements_version` is the version in which the confirmed requirements
|
||||
// were last changed; a change of the title, the vacancy link, the text, or suggestions only keeps it.
|
||||
// Search runs, selection snapshots, and invitations refer to a need by its identifier and
|
||||
// `requirements_version`, so they keep the requirements they used, and only a new
|
||||
// `requirements_version` calls for a new selection snapshot. Reading and comparing earlier versions
|
||||
// (PRD FR10) are planned as separate operations that return the same NeedRequirementSet for a given
|
||||
// version; they add no field here.
|
||||
//
|
||||
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
|
||||
// account answers 403 forbidden; an account without an active membership in the organization, an
|
||||
// unknown organization, an unknown need, and a need of another organization all answer 404 not_found,
|
||||
// so identifiers cannot be probed; a member whose role does not allow reading the need answers 403
|
||||
// forbidden. An `org_id` or `need_id` that is not a UUID answers 400 validation_failed with the path
|
||||
// pointer.
|
||||
//
|
||||
// GET /api/v1/organizations/{org_id}/needs/{need_id}
|
||||
func (UnimplementedHandler) GetOrganizationNeed(ctx context.Context, params GetOrganizationNeedParams) (r GetOrganizationNeedRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetSpecializationCatalog implements GetSpecializationCatalog operation.
|
||||
//
|
||||
// Public operation without a session. Returns the directions with their specializations, the
|
||||
@@ -295,6 +385,30 @@ func (UnimplementedHandler) GetSpecializationCatalog(ctx context.Context) (r *Sp
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListOrganizationNeeds implements ListOrganizationNeeds operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`. The
|
||||
// organization and the role come from the membership that the server holds for the session account,
|
||||
// never from the request. In the MVP only the owner of the organization works with needs; the other
|
||||
// roles of the PRD FR07 matrix (recruiter, hiring manager and technical expert for assigned needs) are
|
||||
// planned and change no field of this contract. The list holds only the needs that the role may read.
|
||||
//
|
||||
// Returns a page of need summaries, newest first by creation time with the identifier as the
|
||||
// tie-breaker, with cursor pagination. A summary has the current version, the target specialization
|
||||
// and grade with their confirmation state, and the readiness; GetOrganizationNeed returns the
|
||||
// requirements and the recommendations.
|
||||
//
|
||||
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
|
||||
// account answers 403 forbidden; an account without an active membership in the organization and an
|
||||
// unknown organization both answer 404 not_found, so organizations cannot be enumerated; a member
|
||||
// whose role does not allow reading needs answers 403 forbidden. A malformed `org_id`, `limit`, or
|
||||
// `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/organizations/{org_id}/needs
|
||||
func (UnimplementedHandler) ListOrganizationNeeds(ctx context.Context, params ListOrganizationNeedsParams) (r ListOrganizationNeedsRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// Login implements Login operation.
|
||||
//
|
||||
// Public operation that starts a server session. The server verifies the password with Argon2id; for
|
||||
@@ -500,6 +614,76 @@ func (UnimplementedHandler) SubmitMyAssessmentAnswer(ctx context.Context, req *A
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// UpdateOrganizationNeed implements UpdateOrganizationNeed operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
// token of that session in X-CSRF-Token, and an allowed Origin. The organization and the role come
|
||||
// from the server-side membership; the body has no organization, membership, or role field. In the MVP
|
||||
// only the owner of the organization changes needs; the technical expert, who may refine the
|
||||
// requirements of assigned needs under PRD FR07, is planned.
|
||||
//
|
||||
// Merge rules: the body is `application/json` with explicit field replacement, not JSON Merge Patch.
|
||||
// Each field present replaces that field as a whole and an absent field stays unchanged; a field
|
||||
// decision and each list are replaced entirely and never merged. This keeps every field one optional
|
||||
// value in the generated server and client, without nested partial updates.
|
||||
//
|
||||
// Each requirement field is sent as a decision `{value, status}` and each list item as
|
||||
// `{name or text, status}`, so confirmation is always explicit:
|
||||
//
|
||||
// - Confirm a suggestion: send its stored value with `confirmed`. It keeps its origin and quote.
|
||||
// - Keep a suggestion open: send its stored value with `extracted`, or leave the field out.
|
||||
// `extracted` with any other value, or for a field or item without a stored suggestion, answers 400
|
||||
// with the pointer of that `status`, for example `/grade/status` or `/required_skills/2/status`. A
|
||||
// client that sends back an unchanged form therefore never confirms a suggestion by accident.
|
||||
// - Change: send another value with `confirmed`. It becomes a confirmed manual value, and its quote
|
||||
// is dropped.
|
||||
// - Delete: send null for a nullable field, which makes it `unknown` (or unlinks `vacancy_id`), or
|
||||
// leave the item out of a skill or task list, which deletes it. An empty skill or task list deletes
|
||||
// every item; a list sent as null answers 400. A deleted requirement really changes the
|
||||
// requirements that search uses, not only an explanation, and a deleted suggestion is not proposed
|
||||
// again by a later extraction.
|
||||
// - Text: a different `source_text` extracts again. New suggestions replace only the `extracted`
|
||||
// values and items of the fields not named in the body; confirmed values are never overwritten, and
|
||||
// a suggested skill whose name is already in either skill list is skipped. Null removes the text
|
||||
// and keeps every value.
|
||||
//
|
||||
// Versions: every committed change creates version `expected_version + 1` as an immutable snapshot and
|
||||
// answers 200 with it. `requirements_version` becomes the new version only when a confirmed
|
||||
// requirement was confirmed, changed, or removed. `expected_version` is the `version` the client read;
|
||||
// when it is not current, the server answers 412 version_conflict and changes nothing, and the client
|
||||
// reads the need again and reapplies its unsaved edits. The version travels in the body rather than in
|
||||
// If-Match because the generated client cannot read the ETag response header yet, as for the
|
||||
// questionnaire. Concurrent changes therefore never overwrite each other silently.
|
||||
//
|
||||
// The operation needs no Idempotency-Key: a body that changes nothing when applied to the current
|
||||
// version, such as a retry of a change that already succeeded, keeps the version and answers 200 with
|
||||
// the current need even when `expected_version` is older. An incomplete need is a valid result;
|
||||
// `readiness.missing_fields` tells what remains.
|
||||
//
|
||||
// Salary limit: the recommendations aggregate candidates' minimums against the upper bound, so setting
|
||||
// or changing a confirmed salary range counts against a limit shared by the whole organization, every
|
||||
// member and every need, together with ranges set on creation: at most three a day (PRD FR13, planned
|
||||
// in TASK-211). Over the limit the server answers 429 with Retry-After and changes nothing. After five
|
||||
// settings within seven days the money component is `withheld` for seven days. Repeated range changes
|
||||
// also feed the private risk signals of TASK-319.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for a candidate), membership (404 not_found) and role (403
|
||||
// forbidden), the need (404 not_found), a body that changes nothing (200), the version (412), domain
|
||||
// rules (400 with a pointer such as `/salary/value/salary_to` for a range whose lower bound is not
|
||||
// below the upper one or whose width is outside 10-40%, `/desired_skills/0/name` for a skill that is
|
||||
// also in the required list, `/grade/status` or `/required_skills/2/status` for `extracted` with a
|
||||
// value that is not the stored suggestion, or `/vacancy_id`), then the salary change limit (429). The
|
||||
// schema rejects a missing or non-positive `expected_version`, unknown fields such as `rec_score`,
|
||||
// `members`, `candidate_minimum`, or `version`, a field sent as a bare value instead of
|
||||
// `{value, status}`, a list sent as null, a salary bound that is not a positive multiple of 1000, and
|
||||
// an unknown currency, period, or tax basis.
|
||||
//
|
||||
// PATCH /api/v1/organizations/{org_id}/needs/{need_id}
|
||||
func (UnimplementedHandler) UpdateOrganizationNeed(ctx context.Context, req *NeedUpdate, params UpdateOrganizationNeedParams) (r UpdateOrganizationNeedRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// NewError creates *ProblemStatusCode from error returned by handler.
|
||||
//
|
||||
// Used for common default response.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -756,6 +756,330 @@ func TestAssessmentAccessBeforeImplementation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Need request fixtures shared by the need tests.
|
||||
const (
|
||||
organizationNeedsPath = "/api/v1/organizations/01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e01/needs"
|
||||
organizationNeedPath = organizationNeedsPath + "/01928f7a-2b3c-7d4e-9f5a-6b7c8d9e0f12"
|
||||
netSalaryRange = `{"salary_from":120000,"salary_to":160000,"currency":"RUB","period":"month","tax_basis":"net"}`
|
||||
validNeedCreate = `{"title":"Backend","specialization":{"value":"backend","status":"confirmed"},` +
|
||||
`"grade":{"value":"junior","status":"confirmed"},"required_skills":[{"name":"Go","status":"confirmed"}],` +
|
||||
`"work_formats":{"value":["remote"],"status":"confirmed"},"salary":{"value":` + netSalaryRange + `,"status":"confirmed"}}`
|
||||
)
|
||||
|
||||
// needUpdateBody returns an UpdateOrganizationNeed body over version 1 with
|
||||
// the given extra fields, for example `"grade":null`.
|
||||
func needUpdateBody(fields string) string {
|
||||
return `{"expected_version":1,` + fields + `}`
|
||||
}
|
||||
|
||||
// needSalary returns a confirmed salary decision for the given range bounds
|
||||
// and tax basis in RUB per month.
|
||||
func needSalary(from, to, basis string) string {
|
||||
return `{"value":{"salary_from":` + from + `,"salary_to":` + to + `,"currency":"RUB","period":"month","tax_basis":"` + basis + `"},"status":"confirmed"}`
|
||||
}
|
||||
|
||||
// The schema alone must accept a need without a vacancy and reject what an
|
||||
// employer may never send: membership, a recommendation score, or a
|
||||
// candidate's minimum, a bare value without an explicit confirmation status,
|
||||
// a salary range without a valid RUB base, and a missing or invalid
|
||||
// expected_version. Security accepts the session here, so the request
|
||||
// reaches validation; a valid request then answers 501 until needs are
|
||||
// implemented. Cross-field salary rules (A < B, a width of 10-40%) and
|
||||
// `extracted` with another value pass the schema; the server rejects them.
|
||||
func TestNeedSchemaValidationPrecedesImplementation(t *testing.T) {
|
||||
session := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken}
|
||||
command := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken, "Idempotency-Key": testIdempotencyKey}
|
||||
create := func(body string) identityRequest {
|
||||
return identityRequest{method: http.MethodPost, path: organizationNeedsPath, body: body, headers: command}
|
||||
}
|
||||
update := func(fields string) identityRequest {
|
||||
return identityRequest{method: http.MethodPatch, path: organizationNeedPath, body: needUpdateBody(fields), headers: session}
|
||||
}
|
||||
withSalary := func(salary string) string {
|
||||
return strings.Replace(validNeedCreate, `{"value":`+netSalaryRange+`,"status":"confirmed"}`, salary, 1)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
request identityRequest
|
||||
location api.ProblemFieldLocation
|
||||
pointer string
|
||||
code string
|
||||
}{
|
||||
{
|
||||
name: "list",
|
||||
request: identityRequest{method: http.MethodGet, path: organizationNeedsPath + "?limit=20", headers: session},
|
||||
},
|
||||
{
|
||||
name: "list with a limit above the maximum",
|
||||
request: identityRequest{method: http.MethodGet, path: organizationNeedsPath + "?limit=101", headers: session},
|
||||
location: api.ProblemFieldLocationQuery, pointer: "/limit", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "list for an organization identifier that is not a UUID",
|
||||
request: identityRequest{method: http.MethodGet, path: "/api/v1/organizations/acme/needs", headers: session},
|
||||
location: api.ProblemFieldLocationPath, pointer: "/org_id", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "create a manual need without a vacancy",
|
||||
request: create(validNeedCreate),
|
||||
},
|
||||
{
|
||||
name: "create from a text only",
|
||||
request: create(`{"title":"Backend","source_text":"Ищем бэкенд-разработчика. Обязательно: Go."}`),
|
||||
},
|
||||
{
|
||||
name: "create with an explicit null vacancy and unknown fields",
|
||||
request: create(`{"title":"Backend","vacancy_id":null,"grade":null,"salary":null,"work_formats":null,"tasks":[]}`),
|
||||
},
|
||||
{
|
||||
// The cross-field salary rules are domain rules that the server
|
||||
// checks after the schema.
|
||||
name: "create with a reversed salary range",
|
||||
request: create(withSalary(needSalary("160000", "120000", "net"))),
|
||||
},
|
||||
{
|
||||
name: "create with equal salary bounds",
|
||||
request: create(withSalary(needSalary("150000", "150000", "net"))),
|
||||
},
|
||||
{
|
||||
name: "create with a salary range wider than 40%",
|
||||
request: create(withSalary(needSalary("100000", "200000", "net"))),
|
||||
},
|
||||
{
|
||||
name: "create without a title",
|
||||
request: create(`{"specialization":{"value":"backend","status":"confirmed"}}`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/title", code: "required",
|
||||
},
|
||||
{
|
||||
name: "create without an Idempotency-Key",
|
||||
request: identityRequest{method: http.MethodPost, path: organizationNeedsPath, body: validNeedCreate, headers: session},
|
||||
location: api.ProblemFieldLocationHeader, pointer: "/Idempotency-Key", code: "required",
|
||||
},
|
||||
{
|
||||
name: "salary bound of zero",
|
||||
request: create(withSalary(needSalary("0", "160000", "net"))),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/salary_from", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "salary bound that is not a multiple of 1000",
|
||||
request: create(withSalary(needSalary("120000", "160500", "net"))),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/salary_to", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "salary in another currency",
|
||||
request: create(withSalary(strings.Replace(needSalary("120000", "160000", "net"), "RUB", "USD", 1))),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/currency", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "salary with an unknown tax basis",
|
||||
request: create(withSalary(needSalary("120000", "160000", "after_tax"))),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/tax_basis", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "salary per hour",
|
||||
request: create(withSalary(strings.Replace(needSalary("1000", "2000", "net"), "month", "hour", 1))),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/period", code: "invalid",
|
||||
},
|
||||
{
|
||||
// The decoder does not record the path of a missing field in a
|
||||
// nested object, so the pointer is the whole body.
|
||||
name: "salary without a tax basis",
|
||||
request: create(withSalary(`{"value":{"salary_from":120000,"salary_to":160000,"currency":"RUB","period":"month"},"status":"confirmed"}`)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
// A bare range would confirm it implicitly; the status is explicit.
|
||||
name: "salary range without a decision",
|
||||
request: create(withSalary(netSalaryRange)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "grade as a bare value",
|
||||
request: create(strings.Replace(validNeedCreate, `{"value":"junior","status":"confirmed"}`, `"junior"`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "grade with an unknown status",
|
||||
request: create(strings.Replace(validNeedCreate, `{"value":"junior","status":"confirmed"}`, `{"value":"junior","status":"unknown"}`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/grade/status", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "recommendation score set by the employer",
|
||||
request: create(strings.Replace(validNeedCreate, `{"title"`, `{"rec_score":0.99,"title"`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "organization membership in the body",
|
||||
request: create(strings.Replace(validNeedCreate, `{"title"`, `{"members":[{"user_id":"01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e01","role":"owner"}],"title"`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "candidate minimum inside the salary range",
|
||||
request: create(withSalary(`{"value":{"salary_from":120000,"salary_to":160000,"currency":"RUB","period":"month","tax_basis":"net","candidate_minimum":130000},"status":"confirmed"}`)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "skill with an unknown status",
|
||||
request: create(strings.Replace(validNeedCreate, `{"name":"Go","status":"confirmed"}`, `{"name":"Go","status":"unknown"}`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/required_skills/0/status", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "empty list of work formats",
|
||||
request: create(strings.Replace(validNeedCreate, `["remote"]`, `[]`, 1)),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/work_formats/value", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "read",
|
||||
request: identityRequest{method: http.MethodGet, path: organizationNeedPath, headers: session},
|
||||
},
|
||||
{
|
||||
name: "read with a need identifier that is not a UUID",
|
||||
request: identityRequest{method: http.MethodGet, path: organizationNeedsPath + "/1", headers: session},
|
||||
location: api.ProblemFieldLocationPath, pointer: "/need_id", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "confirm suggestions, keep two open, and answer missing fields",
|
||||
request: update(`"specialization":{"value":"backend","status":"confirmed"},"grade":{"value":"middle","status":"confirmed"},` +
|
||||
`"required_skills":[{"name":"Go","status":"confirmed"},{"name":"Temporal","status":"confirmed"}],` +
|
||||
`"desired_skills":[{"name":"Kafka","status":"extracted"}],"domain":{"value":"платежи","status":"extracted"},` +
|
||||
`"salary":` + needSalary("250000", "320000", "gross")),
|
||||
},
|
||||
{
|
||||
name: "delete requirements",
|
||||
request: update(`"grade":null,"salary":null,"vacancy_id":null,"tasks":[]`),
|
||||
},
|
||||
{
|
||||
name: "update with a list sent as null",
|
||||
request: update(`"tasks":null`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update with a bare grade",
|
||||
request: update(`"grade":"middle"`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update without an expected version",
|
||||
request: identityRequest{method: http.MethodPatch, path: organizationNeedPath, body: `{"grade":null}`, headers: session},
|
||||
location: api.ProblemFieldLocationBody, pointer: "/expected_version", code: "required",
|
||||
},
|
||||
{
|
||||
name: "update with version zero",
|
||||
request: identityRequest{method: http.MethodPatch, path: organizationNeedPath, body: `{"expected_version":0,"grade":null}`, headers: session},
|
||||
location: api.ProblemFieldLocationBody, pointer: "/expected_version", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update with a version as text",
|
||||
request: identityRequest{method: http.MethodPatch, path: organizationNeedPath, body: `{"expected_version":"1","grade":null}`, headers: session},
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update that sets the version itself",
|
||||
request: update(`"version":7`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update that sets the requirements version",
|
||||
request: update(`"requirements_version":7`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update with recommendations",
|
||||
request: update(`"recommendations":{"status":"computed"}`),
|
||||
location: api.ProblemFieldLocationBody, pointer: "", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update with a salary in gross and net at once",
|
||||
request: update(`"salary":` + needSalary("120000", "160000", "net_or_gross")),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/tax_basis", code: "invalid",
|
||||
},
|
||||
{
|
||||
name: "update with a negative salary bound",
|
||||
request: update(`"salary":` + needSalary("-1000", "160000", "gross")),
|
||||
location: api.ProblemFieldLocationBody, pointer: "/salary/value/salary_from", code: "invalid",
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
logger := slog.New(slog.DiscardHandler)
|
||||
healthHandler := newTestHealthHandler(func(context.Context) error { return nil })
|
||||
router, err := NewRouter(healthHandler, v1.NewHandler(healthHandler, problem.NewResponder(logger)), &recordingSecurity{}, problem.NewResponder(logger), metrics.New(), logger)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRouter() error = %v", err)
|
||||
}
|
||||
response := serveIdentityRequest(t, router, test.request)
|
||||
|
||||
if test.code == "" {
|
||||
requireProblem(t, response, http.StatusNotImplemented, api.ProblemCodeNotImplemented)
|
||||
return
|
||||
}
|
||||
body := requireProblem(t, response, http.StatusBadRequest, api.ProblemCodeValidationFailed)
|
||||
want := api.ProblemFieldError{In: test.location, Pointer: test.pointer, Code: test.code}
|
||||
for _, field := range body.Errors {
|
||||
if field.In == want.In && field.Pointer == want.Pointer && field.Code == want.Code {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("errors = %+v, want an entry %+v", body.Errors, want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A non-nullable optional list decodes to a plain slice, so an
|
||||
// UpdateOrganizationNeed handler tells an absent list (unchanged) from an
|
||||
// empty one (delete every item) only by nil; null is not a list and fails.
|
||||
func TestNeedUpdateDecodingKeepsAbsentAndEmptyListsApart(t *testing.T) {
|
||||
var empty api.NeedUpdate
|
||||
if err := empty.UnmarshalJSON([]byte(`{"expected_version":1,"tasks":[]}`)); err != nil {
|
||||
t.Fatalf("decode an empty list: %v", err)
|
||||
}
|
||||
if empty.Tasks == nil || len(empty.Tasks) != 0 {
|
||||
t.Fatalf("tasks = %#v, want a non-nil empty slice", empty.Tasks)
|
||||
}
|
||||
|
||||
var absent api.NeedUpdate
|
||||
if err := absent.UnmarshalJSON([]byte(`{"expected_version":1}`)); err != nil {
|
||||
t.Fatalf("decode an absent list: %v", err)
|
||||
}
|
||||
if absent.Tasks != nil || absent.RequiredSkills != nil || absent.DesiredSkills != nil {
|
||||
t.Fatalf("lists = %#v %#v %#v, want nil for absent fields", absent.Tasks, absent.RequiredSkills, absent.DesiredSkills)
|
||||
}
|
||||
if absent.Grade.IsSet() || absent.Salary.IsSet() {
|
||||
t.Fatal("absent field decisions are set, want unset")
|
||||
}
|
||||
|
||||
var cleared api.NeedUpdate
|
||||
if err := cleared.UnmarshalJSON([]byte(`{"expected_version":1,"grade":null}`)); err != nil {
|
||||
t.Fatalf("decode a null field decision: %v", err)
|
||||
}
|
||||
if !cleared.Grade.IsSet() || !cleared.Grade.IsNull() {
|
||||
t.Fatal("grade sent as null is not a set null, want a removal")
|
||||
}
|
||||
|
||||
var null api.NeedUpdate
|
||||
if err := null.UnmarshalJSON([]byte(`{"expected_version":1,"tasks":null}`)); err == nil {
|
||||
t.Fatal("decode a list sent as null succeeded, want an error")
|
||||
}
|
||||
}
|
||||
|
||||
// Every need operation requires an employer session; DenyAllSecurity grants
|
||||
// none, with or without a cookie and a CSRF token.
|
||||
func TestNeedAccessBeforeImplementation(t *testing.T) {
|
||||
session := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken}
|
||||
command := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken, "Idempotency-Key": testIdempotencyKey}
|
||||
for _, test := range []identityRequest{
|
||||
{method: http.MethodGet, path: organizationNeedsPath},
|
||||
{method: http.MethodGet, path: organizationNeedsPath, headers: map[string]string{"Cookie": testSessionCookie}},
|
||||
{method: http.MethodPost, path: organizationNeedsPath, body: validNeedCreate, headers: command},
|
||||
{method: http.MethodGet, path: organizationNeedPath},
|
||||
{method: http.MethodPatch, path: organizationNeedPath, body: needUpdateBody(`"grade":{"value":"middle","status":"confirmed"}`), headers: session},
|
||||
} {
|
||||
t.Run(test.method+" "+test.path, func(t *testing.T) {
|
||||
router := newTestRouter(t, func(context.Context) error { return nil })
|
||||
requireProblem(t, serveIdentityRequest(t, router, test), http.StatusUnauthorized, api.ProblemCodeUnauthenticated)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicOperationInternalErrorIsLoggedButNotExposed(t *testing.T) {
|
||||
var logs bytes.Buffer
|
||||
logger := slog.New(slog.NewJSONHandler(&logs, nil))
|
||||
|
||||
Reference in new issue
Block a user