-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
倪诗梦
authored and
倪诗梦
committed
Sep 1, 2024
1 parent
6929075
commit e28873e
Showing
7 changed files
with
473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2023 ecodeclub | ||
Check failure on line 1 in internal/resume/internal/domain/experience.go GitHub Actions / lint
|
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package domain | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ecodeclub/webook/internal/resume/internal/web" | ||
) | ||
|
||
// Experience 代表工作经历 | ||
type Experience struct { | ||
// 主键 | ||
Id int64 | ||
// 用户的 ID | ||
Uid int64 | ||
// 开始时间 | ||
Start time.Time | ||
// 结束时间,如果 End 是零值,代表当前还没离职 | ||
End time.Time | ||
|
||
Title string // 职位 | ||
CompanyName string // 公司 | ||
Location string // 地点 | ||
// JSON 串存起来就可以 | ||
Responsibilities []Responsibility // 主要职责 | ||
Accomplishments []Accomplishment // 主要成就 | ||
Skills []string // 主要技能 | ||
} | ||
|
||
type Responsibility struct { | ||
// Type 是类型,比如说核心研发、团队管理 | ||
// 用 string 来作为枚举 | ||
Type string | ||
Content string | ||
} | ||
|
||
type Accomplishment struct { | ||
// Type 是类型,比如说性能优化,获奖啥的 | ||
Type string | ||
Content string | ||
} | ||
|
||
// CurrentEmployed 是否当前正在职 | ||
func (e Experience) CurrentEmployed() bool { | ||
return e.End.IsZero() | ||
} | ||
|
||
func newResponsibility(responsibilities web.Responsibility) Responsibility { | ||
return Responsibility{ | ||
Type: responsibilities.Type, | ||
Content: responsibilities.Content, | ||
} | ||
} | ||
|
||
func newAccomplishments(responsibilities web.Accomplishment) Accomplishment { | ||
return Accomplishment{ | ||
Type: responsibilities.Type, | ||
Content: responsibilities.Content, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dao | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/ego-component/egorm" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/clause" | ||
) | ||
|
||
type ExperienceDAO interface { | ||
Upsert(ctx context.Context, experience Experience) (int64, error) | ||
Delete(ctx context.Context, uid int64, id int64) error | ||
Find(ctx context.Context, uid int64) ([]Experience, error) | ||
} | ||
|
||
type experienceDAO struct { | ||
db *egorm.Component | ||
} | ||
|
||
func NewExperienceDAO(db *egorm.Component) ExperienceDAO { | ||
return &experienceDAO{ | ||
db: db, | ||
} | ||
} | ||
|
||
func (e *experienceDAO) Upsert(ctx context.Context, experience Experience) (int64, error) { | ||
now := time.Now().UnixMilli() | ||
experience.Utime = now | ||
experience.Ctime = now | ||
err := e.db.WithContext(ctx).Model(&Experience{}). | ||
Clauses(clause.OnConflict{ | ||
Columns: []clause.Column{{Name: "uid"}}, | ||
DoUpdates: clause.AssignmentColumns([]string{"start_time", "end_time", "title", "company_name", "location", "responsibilities", "accomplishments", "skills", "utime"}), | ||
}).Create(&experience).Error | ||
return experience.ID, err | ||
} | ||
|
||
func (e *experienceDAO) Delete(ctx context.Context, uid int64, id int64) error { | ||
|
||
return e.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | ||
res := tx.WithContext(ctx).Model(&Experience{}).Where("id = ? and uid = ?", id, uid).Delete(&Experience{}) | ||
if res.Error != nil { | ||
return res.Error | ||
} | ||
if res.RowsAffected <= 0 { | ||
return errors.New("删除失败") | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
func (e *experienceDAO) Find(ctx context.Context, uid int64) ([]Experience, error) { | ||
var experiences []Experience | ||
err := e.db.WithContext(ctx).Where("uid = ?", uid).Order("StartTime desc").Find(&experiences).Error | ||
return experiences, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package repository | ||
Check failure on line 1 in internal/resume/internal/repository/experience.go GitHub Actions / lint
|
||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/ecodeclub/webook/internal/resume/internal/domain" | ||
"github.com/ecodeclub/webook/internal/resume/internal/repository/dao" | ||
) | ||
|
||
type Experience interface { | ||
SaveExperience(ctx context.Context, experience domain.Experience) (int64, error) | ||
QueryAllExperiences(ctx context.Context, uid int64) ([]domain.Experience, error) | ||
DeleteExperience(ctx context.Context, uid int64, id int64) error | ||
} | ||
|
||
type experience struct { | ||
expdao dao.ExperienceDAO | ||
} | ||
|
||
func (e *experience) SaveExperience(ctx context.Context, experience domain.Experience) (int64, error) { | ||
return e.expdao.Upsert(ctx, e.toExperienceEntity(experience)) | ||
} | ||
|
||
func (e *experience) QueryAllExperiences(ctx context.Context, uid int64) ([]domain.Experience, error) { | ||
elist, err := e.expdao.Find(ctx, uid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ans := make([]domain.Experience, 0, len(elist)) | ||
for _, exp := range elist { | ||
ans = append(ans, e.toExperienceDomain(exp)) | ||
} | ||
return ans, nil | ||
} | ||
|
||
func (e *experience) DeleteExperience(ctx context.Context, uid int64, id int64) error { | ||
return e.expdao.Delete(ctx, uid, id) | ||
} | ||
|
||
func (e *experience) toExperienceEntity(experience domain.Experience) dao.Experience { | ||
responsibilitiesJsonData, err := json.Marshal(experience.Responsibilities) | ||
if err != nil { | ||
responsibilitiesJsonData = nil | ||
} | ||
accomplishmentsJsonData, err := json.Marshal(experience.Accomplishments) | ||
if err != nil { | ||
accomplishmentsJsonData = nil | ||
} | ||
skillsJsonData, err := json.Marshal(experience.Skills) | ||
if err != nil { | ||
skillsJsonData = nil | ||
} | ||
|
||
return dao.Experience{ | ||
ID: experience.Id, | ||
StartTime: experience.Start, | ||
EndTime: experience.End, | ||
Title: experience.Title, | ||
CompanyName: experience.CompanyName, | ||
Location: experience.Location, | ||
Responsibilities: string(responsibilitiesJsonData), | ||
Accomplishments: string(accomplishmentsJsonData), | ||
Skills: string(skillsJsonData), | ||
} | ||
} | ||
|
||
func (e *experience) toExperienceDomain(experience dao.Experience) domain.Experience { | ||
var responsibilities []domain.Responsibility | ||
err := json.Unmarshal([]byte(experience.Responsibilities), &responsibilities) | ||
if err != nil { | ||
responsibilities = nil | ||
} | ||
|
||
var accomplishments []domain.Accomplishment | ||
err = json.Unmarshal([]byte(experience.Accomplishments), &accomplishments) | ||
if err != nil { | ||
accomplishments = nil | ||
} | ||
|
||
var skills []string | ||
err = json.Unmarshal([]byte(experience.Skills), &skills) | ||
if err != nil { | ||
skills = nil | ||
} | ||
|
||
return domain.Experience{ | ||
Id: experience.ID, | ||
Start: experience.StartTime, | ||
End: experience.EndTime, | ||
Title: experience.Title, | ||
CompanyName: experience.CompanyName, | ||
Location: experience.Location, | ||
Responsibilities: responsibilities, | ||
Accomplishments: accomplishments, | ||
Skills: skills, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ecodeclub/webook/internal/resume/internal/domain" | ||
Check failure on line 6 in internal/resume/internal/service/experience.go GitHub Actions / lint
|
||
"github.com/ecodeclub/webook/internal/resume/internal/repository" | ||
Check failure on line 7 in internal/resume/internal/service/experience.go GitHub Actions / lint
|
||
) | ||
|
||
type ExperienceService interface { | ||
SaveExperience(ctx context.Context, experience domain.Experience) (int64, error) | ||
List(ctx context.Context, uid int64) ([]domain.Experience, error) | ||
Delete(ctx context.Context, uid int64, id int64) error | ||
} | ||
|
||
type experienceService struct { | ||
experience repository.Experience | ||
} | ||
|
||
//func NewExperienceService(experience repository.Experience) ExperienceService { | ||
// return &experienceService{ | ||
// experience: experience, | ||
// } | ||
//} | ||
|
||
func (e *experienceService) SaveExperience(ctx context.Context, experience domain.Experience) (int64, error) { | ||
return e.experience.SaveExperience(ctx, experience) | ||
} | ||
|
||
func (e *experienceService) List(ctx context.Context, uid int64) ([]domain.Experience, error) { | ||
return e.experience.QueryAllExperiences(ctx, uid) | ||
} | ||
|
||
func (e *experienceService) Delete(ctx context.Context, uid int64, id int64) error { | ||
return e.experience.DeleteExperience(ctx, uid, id) | ||
} |
Oops, something went wrong.