Line data Source code
1 : // Package education は、学歴に関するユースケース(アプリケーションロジック)を提供します。
2 : // ドメイン層のエンティティやリポジトリを操作し、アプリケーション全体で再利用可能なビジネスフローを実装します。
3 : package education
4 :
5 : import (
6 : "context"
7 :
8 : "resume/internal/domain/entity"
9 : "resume/internal/shared/apperr"
10 : "resume/internal/shared/valerr"
11 : )
12 :
13 : // UpdateUserEducation は、指定されたユーザーIDに紐づく 学歴情報 を更新します。
14 : func (uc *Interactor) UpdateUserEducation(
15 : ctx context.Context,
16 : in UpdateInput,
17 0 : ) (UpdateOutput, error) {
18 0 : var updated *entity.UserEducation
19 0 :
20 0 : err := uc.tx.Do(ctx, func(txCtx context.Context) error {
21 0 :
22 0 : current, err := uc.ueRepo.FindByID(txCtx, in.EducationID)
23 0 : if err != nil {
24 0 : return err
25 0 : }
26 :
27 0 : if current == nil {
28 0 : ve := valerr.New()
29 0 : ve.Add(
30 0 : "domain.user_education.id",
31 0 : "validation.rules.invalid",
32 0 : map[string]any{
33 0 : "field": "domain.user_education.id",
34 0 : },
35 0 : )
36 0 : return apperr.New(
37 0 : apperr.CodeUnprocessable,
38 0 : "The request contains semantically invalid data.",
39 0 : ve.ToDetails(),
40 0 : )
41 0 : }
42 :
43 0 : if current.UserID != in.UserID {
44 0 : ve := valerr.New()
45 0 : ve.Add(
46 0 : "domain.user_education.id",
47 0 : "validation.rules.invalid",
48 0 : map[string]any{
49 0 : "field": "domain.user_education.id",
50 0 : },
51 0 : )
52 0 : return apperr.New(
53 0 : apperr.CodeUnprocessable,
54 0 : "The request contains semantically invalid data.",
55 0 : ve.ToDetails(),
56 0 : )
57 0 : }
58 :
59 0 : current.InstitutionName = in.InstitutionName
60 0 : current.FacultyName = in.FacultyName
61 0 : current.DepartmentName = in.DepartmentName
62 0 : current.DegreeTypeID = in.DegreeTypeID
63 0 : current.EducationStatusID = in.EducationStatusID
64 0 : current.EventDate = in.EventDate
65 0 : current.Description = in.Description
66 0 : current.IsPublic = in.IsPublic
67 0 :
68 0 : res, err := uc.ueRepo.Update(txCtx, current)
69 0 : if err != nil {
70 0 : return err
71 0 : }
72 0 : updated = res
73 0 : return nil
74 : })
75 0 : if err != nil {
76 0 : return UpdateOutput{}, err
77 0 : }
78 0 : return UpdateOutput{
79 0 : Education: updated,
80 0 : }, nil
81 : }
|