go-guess/backend/internal/web/mapper/mapper.go

189 lines
6.9 KiB
Go
Raw Permalink Normal View History

2026-09-19 20:31:14 +02:00
package mapper
import (
"fmt"
servicemodel "github.com/danyel/go-guess/backend/internal/service/model"
webmodel "github.com/danyel/go-guess/backend/internal/web/model"
)
func JobToService(value webmodel.JobRequest) servicemodel.JobPosting {
return servicemodel.JobPosting{
Title: value.Title, Description: value.Description, Seniority: value.Seniority,
Position: value.Position, DurationMinutes: value.DurationMinutes,
Labels: traitsToService(value.Labels), RequiredSkills: traitsToService(value.RequiredSkills),
AdditionalSkills: traitsToService(value.AdditionalSkills),
}
}
func QuestionToService(value webmodel.QuestionRequest) servicemodel.Question {
return servicemodel.Question{
Text: value.Text, Type: value.Type, Options: value.Options,
2026-09-19 20:56:27 +02:00
CodeSnippet: value.CodeSnippet, ReferenceAnswer: value.ReferenceAnswer,
2026-09-19 20:31:14 +02:00
}
}
func JobToWeb(value servicemodel.JobPosting) webmodel.JobResponse {
questions := make([]webmodel.QuestionResponse, len(value.Questions))
for i, question := range value.Questions {
questions[i] = QuestionToWeb(question)
}
return webmodel.JobResponse{
ID: value.ID, Title: value.Title, Description: value.Description,
Seniority: value.Seniority, Position: value.Position, Status: value.Status,
DurationMinutes: value.DurationMinutes,
Labels: traitsToWeb(value.Labels), RequiredSkills: traitsToWeb(value.RequiredSkills),
AdditionalSkills: traitsToWeb(value.AdditionalSkills), Questions: questions,
CreatedAt: value.CreatedAt,
}
}
func QuestionToWeb(value servicemodel.Question) webmodel.QuestionResponse {
return webmodel.QuestionResponse{
ID: value.ID, Text: value.Text, Type: value.Type, Options: value.Options,
2026-09-19 20:56:27 +02:00
CodeSnippet: value.CodeSnippet, ReferenceAnswer: value.ReferenceAnswer,
Deprecated: value.Deprecated,
2026-09-19 20:31:14 +02:00
}
}
func ParticipantToWeb(value servicemodel.Participant) webmodel.ParticipantResponse {
result := webmodel.ParticipantResponse{
ID: value.ID, FirstName: value.FirstName, LastName: value.LastName,
Email: value.Email, ContactInfo: value.ContactInfo, CVFilename: value.CVFilename,
Traits: traitsToWeb(value.Traits), CreatedAt: value.CreatedAt,
}
if value.Birthday != nil {
birthday := value.Birthday.Format("2006-01-02")
result.Birthday = &birthday
}
if len(value.Photo) > 0 {
result.PhotoURL = fmt.Sprintf("/api/participants/%d/photo", value.ID)
}
if len(value.CV) > 0 {
result.CVURL = fmt.Sprintf("/api/participants/%d/cv", value.ID)
}
return result
}
func CandidateToWeb(value servicemodel.CandidateMatch) webmodel.CandidateResponse {
matched := value.Matched
if matched == nil {
matched = []string{}
}
missing := value.Missing
if missing == nil {
missing = []string{}
}
2026-09-19 20:31:14 +02:00
return webmodel.CandidateResponse{
Participant: ParticipantToWeb(value.Participant), Score: value.Score,
Matched: matched, Missing: missing,
2026-09-19 20:31:14 +02:00
}
}
func InvitationToWeb(value servicemodel.Invitation, frontendURL string) webmodel.InvitationResponse {
return webmodel.InvitationResponse{
ID: value.ID, JobID: value.JobID, ParticipantID: value.ParticipantID,
ParticipantName: value.ParticipantName, ParticipantEmail: value.ParticipantEmail,
Token: value.Token, Status: value.Status,
Outcome: value.Outcome,
2026-09-19 20:56:27 +02:00
ParticipantURL: frontendURL + "/participant/" + value.Token,
2026-09-19 20:31:14 +02:00
AcceptedAt: value.AcceptedAt, CompletedAt: value.CompletedAt, CreatedAt: value.CreatedAt,
}
}
func UserToWeb(value servicemodel.User) webmodel.User {
return webmodel.User{
ID: value.ID, Email: value.Email, DisplayName: value.DisplayName, Role: value.Role,
feat: avatar, account menu, and single sign-on from Go Loose Signing in now starts at the sign-in screen and one button that hands the browser to Go Loose, which returns to the welcome page. Nothing redirects to the identity provider on its own any more: that fired on every anonymous visit and read as a redirect loop rather than as a choice to sign in. The password form remains only where the API reports that Go Loose login is not configured for the host, because otherwise the application is unreachable on a bare localhost. A person's picture is carried through from the Go Loose identity and rendered in the account menu and on the profile page, with their initials as the fallback. Two things make that fallback necessary rather than decorative: Go Loose retires a picture key when a picture is replaced, so a link cached in a browser can be dead, and most people have not uploaded one. The URL is deliberately not persisted locally, since a stored key would keep failing after the picture changed. The account menu is a disclosure rather than a hover menu: a real button with aria-expanded, Escape and outside clicks closing it, and focus returning to the trigger. It is not an ARIA menu, because its actions are a link and a button and menuitem roles would strip the link semantics from one of them for no gain. The account URL of the Go Loose identity is resolved on each sign-in and is read from the live identity provider every time, which is also what makes it correct after a picture change. Depends on the Go Loose revision that serves avatar_url through /connect/userinfo, so the picture URL reaches this application at all.
2026-10-05 21:50:06 +02:00
AvatarURL: value.AvatarURL,
}
}
func ScheduledInterviewToWeb(
value servicemodel.ScheduledInterview, frontendURL string,
) webmodel.ScheduledInterviewResponse {
attendees := make([]webmodel.InterviewAttendeeResponse, len(value.Attendees))
for i, attendee := range value.Attendees {
attendees[i] = InterviewAttendeeToWeb(attendee)
}
notes := make([]webmodel.InterviewNoteResponse, len(value.Notes))
for i, note := range value.Notes {
notes[i] = InterviewNoteToWeb(note)
}
return webmodel.ScheduledInterviewResponse{
ID: value.ID, JobID: value.JobID, JobTitle: value.Job.Title,
ParticipantID: value.ParticipantID,
ParticipantName: value.Participant.FirstName + " " + value.Participant.LastName,
StartsAt: value.StartsAt, Location: value.Location, CandidateToken: value.CandidateToken,
CandidateURL: frontendURL + "/participant/meeting/" + value.CandidateToken,
SharedDocument: value.SharedDocument, Status: value.Status,
Attendees: attendees, Notes: notes,
CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt,
}
}
func ParticipantMeetingToWeb(value servicemodel.ScheduledInterview) webmodel.ParticipantMeetingResponse {
return webmodel.ParticipantMeetingResponse{
ID: value.ID, JobID: value.JobID, JobTitle: value.Job.Title,
ParticipantName: value.Participant.FirstName + " " + value.Participant.LastName,
StartsAt: value.StartsAt, Location: value.Location,
SharedDocument: value.SharedDocument, Status: value.Status,
}
}
func InterviewAttendeeToWeb(value servicemodel.InterviewAttendee) webmodel.InterviewAttendeeResponse {
return webmodel.InterviewAttendeeResponse{
UserID: value.UserID, DisplayName: value.User.DisplayName,
Email: value.User.Email, Status: value.Status,
}
}
func InterviewNoteToWeb(value servicemodel.InterviewNote) webmodel.InterviewNoteResponse {
return webmodel.InterviewNoteResponse{
ID: value.ID, AuthorUserID: value.AuthorID, AuthorName: value.Author.DisplayName,
Body: value.Body, CreatedAt: value.CreatedAt,
}
}
2026-09-19 20:31:14 +02:00
func InterviewToWeb(value servicemodel.Interview, frontendURL string) webmodel.InterviewResponse {
questions := make([]webmodel.InterviewQuestionResponse, len(value.Job.Questions))
for i, question := range value.Job.Questions {
questions[i] = webmodel.InterviewQuestionResponse{
2026-09-19 20:56:27 +02:00
ID: question.ID, Text: question.Text, Type: question.Type,
Options: question.Options, CodeSnippet: question.CodeSnippet,
2026-09-19 20:31:14 +02:00
}
}
return webmodel.InterviewResponse{
Invitation: InvitationToWeb(value.Invitation, frontendURL),
Job: webmodel.InterviewJobResponse{
ID: value.Job.ID, Title: value.Job.Title, Description: value.Job.Description,
Position: value.Job.Position, Seniority: value.Job.Seniority,
DurationMinutes: value.Job.DurationMinutes, Questions: questions,
},
Answers: value.Answers,
}
}
2026-09-19 20:56:27 +02:00
func InvitationReviewToWeb(value servicemodel.Interview, frontendURL string) webmodel.InvitationReviewResponse {
return webmodel.InvitationReviewResponse{
Invitation: InvitationToWeb(value.Invitation, frontendURL),
Job: JobToWeb(value.Job),
Answers: value.Answers,
}
}
2026-09-19 20:31:14 +02:00
func traitsToService(values []string) []servicemodel.Trait {
result := make([]servicemodel.Trait, len(values))
for i, value := range values {
result[i] = servicemodel.Trait{Name: value}
}
return result
}
func traitsToWeb(values []servicemodel.Trait) []string {
result := make([]string, len(values))
for i, value := range values {
result[i] = value.Name
}
return result
}