2025-09-19 04:08:42 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"narasi-ahli-be/app/database/entity"
|
|
|
|
|
"narasi-ahli-be/utils/paginator"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type EducationHistoryQueryRequest struct {
|
2025-09-21 17:06:06 +00:00
|
|
|
UserID uint `json:"userId" validate:"required"`
|
2025-09-19 04:08:42 +00:00
|
|
|
SchoolName *string `json:"schoolName"`
|
|
|
|
|
Major *string `json:"major"`
|
|
|
|
|
EducationLevel *string `json:"educationLevel"`
|
|
|
|
|
GraduationYear *int `json:"graduationYear"`
|
|
|
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EducationHistoryCreateRequest struct {
|
|
|
|
|
SchoolName string `json:"schoolName" validate:"required,min=2,max=255"`
|
|
|
|
|
Major string `json:"major" validate:"required,min=2,max=255"`
|
|
|
|
|
EducationLevel string `json:"educationLevel" validate:"required,min=2,max=100"`
|
|
|
|
|
GraduationYear int `json:"graduationYear" validate:"required,min=1950,max=2030"`
|
|
|
|
|
CertificateImage string `json:"certificateImage,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 17:06:06 +00:00
|
|
|
func (req EducationHistoryCreateRequest) ToEntity(userId uint) *entity.EducationHistory {
|
2025-09-19 04:08:42 +00:00
|
|
|
certificateImage := &req.CertificateImage
|
|
|
|
|
if req.CertificateImage == "" {
|
|
|
|
|
certificateImage = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &entity.EducationHistory{
|
2025-09-21 17:06:06 +00:00
|
|
|
UserID: userId,
|
2025-09-19 04:08:42 +00:00
|
|
|
SchoolName: req.SchoolName,
|
|
|
|
|
Major: req.Major,
|
|
|
|
|
EducationLevel: req.EducationLevel,
|
|
|
|
|
GraduationYear: req.GraduationYear,
|
|
|
|
|
CertificateImage: certificateImage,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EducationHistoryUpdateRequest struct {
|
|
|
|
|
SchoolName string `json:"schoolName" validate:"required,min=2,max=255"`
|
|
|
|
|
Major string `json:"major" validate:"required,min=2,max=255"`
|
|
|
|
|
EducationLevel string `json:"educationLevel" validate:"required,min=2,max=100"`
|
|
|
|
|
GraduationYear int `json:"graduationYear" validate:"required,min=1950,max=2030"`
|
|
|
|
|
CertificateImage string `json:"certificateImage,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 17:06:06 +00:00
|
|
|
func (req EducationHistoryUpdateRequest) ToEntity(userId uint) *entity.EducationHistory {
|
2025-09-19 04:08:42 +00:00
|
|
|
certificateImage := &req.CertificateImage
|
|
|
|
|
if req.CertificateImage == "" {
|
|
|
|
|
certificateImage = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &entity.EducationHistory{
|
2025-09-21 17:06:06 +00:00
|
|
|
UserID: userId,
|
2025-09-19 04:08:42 +00:00
|
|
|
SchoolName: req.SchoolName,
|
|
|
|
|
Major: req.Major,
|
|
|
|
|
EducationLevel: req.EducationLevel,
|
|
|
|
|
GraduationYear: req.GraduationYear,
|
|
|
|
|
CertificateImage: certificateImage,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EducationHistoryQueryRequestContext struct {
|
2025-09-21 17:06:06 +00:00
|
|
|
UserID string `json:"userId"`
|
2025-09-19 04:08:42 +00:00
|
|
|
SchoolName string `json:"schoolName"`
|
|
|
|
|
Major string `json:"major"`
|
|
|
|
|
EducationLevel string `json:"educationLevel"`
|
|
|
|
|
GraduationYear string `json:"graduationYear"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req EducationHistoryQueryRequestContext) ToParamRequest() EducationHistoryQueryRequest {
|
|
|
|
|
var request EducationHistoryQueryRequest
|
|
|
|
|
|
2025-09-21 17:06:06 +00:00
|
|
|
if userId := req.UserID; userId != "" {
|
|
|
|
|
userIdUint, err := strconv.ParseUint(userId, 10, 0)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.UserID = uint(userIdUint)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-19 04:08:42 +00:00
|
|
|
if schoolName := req.SchoolName; schoolName != "" {
|
|
|
|
|
request.SchoolName = &schoolName
|
|
|
|
|
}
|
|
|
|
|
if major := req.Major; major != "" {
|
|
|
|
|
request.Major = &major
|
|
|
|
|
}
|
|
|
|
|
if educationLevel := req.EducationLevel; educationLevel != "" {
|
|
|
|
|
request.EducationLevel = &educationLevel
|
|
|
|
|
}
|
|
|
|
|
if graduationYearStr := req.GraduationYear; graduationYearStr != "" {
|
|
|
|
|
graduationYear, err := strconv.Atoi(graduationYearStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.GraduationYear = &graduationYear
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return request
|
|
|
|
|
}
|