feat: implemented own profile getter;
experiment: using custom automapper function to map profile to profileDto; refactor: adjusted ProfileService to use pointer return types with models
This commit is contained in:
@@ -234,5 +234,5 @@ func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, dto.UrlDto{Url: link})
|
c.JSON(http.StatusOK, dto.UrlDto{Url: *link})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,20 @@ package services
|
|||||||
import (
|
import (
|
||||||
"easywish/internal/database"
|
"easywish/internal/database"
|
||||||
"easywish/internal/dto"
|
"easywish/internal/dto"
|
||||||
|
errs "easywish/internal/errors"
|
||||||
|
mapspecial "easywish/internal/utils/mapSpecial"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProfileService interface {
|
type ProfileService interface {
|
||||||
GetProfileByUsername(cinfo dto.ClientInfo, username string) (dto.ProfileDto, error)
|
GetProfileByUsername(cinfo dto.ClientInfo, username string) (*dto.ProfileDto, error)
|
||||||
GetMyProfile(cinfo dto.ClientInfo) (dto.ProfileDto, error)
|
GetMyProfile(cinfo dto.ClientInfo) (*dto.ProfileDto, error)
|
||||||
UpdateProfile(cinfo dto.ClientInfo, newProfile dto.ProfileDto) (bool, error)
|
UpdateProfile(cinfo dto.ClientInfo, newProfile dto.ProfileDto) (bool, error)
|
||||||
GetProfileSettings(cinfo dto.ClientInfo) (dto.ProfileSettingsDto, error)
|
GetProfileSettings(cinfo dto.ClientInfo) (*dto.ProfileSettingsDto, error)
|
||||||
UpdateProfileSettings(cinfo dto.ClientInfo, newProfileSettings dto.ProfileSettingsDto) (bool, error)
|
UpdateProfileSettings(cinfo dto.ClientInfo, newProfileSettings dto.ProfileSettingsDto) (bool, error)
|
||||||
UploadAvatar(cinfo dto.ClientInfo, filePath string) (string, error)
|
UploadAvatar(cinfo dto.ClientInfo, filePath string) (*string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type profileServiceImpl struct {
|
type profileServiceImpl struct {
|
||||||
@@ -44,15 +46,28 @@ func NewProfileService(_log *zap.Logger, _dbctx database.DbContext, _redis *redi
|
|||||||
return &profileServiceImpl{log: _log, dbctx: _dbctx, redis: _redis}
|
return &profileServiceImpl{log: _log, dbctx: _dbctx, redis: _redis}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *profileServiceImpl) GetMyProfile(cinfo dto.ClientInfo) (dto.ProfileDto, error) {
|
// XXX: untested
|
||||||
|
func (p *profileServiceImpl) GetMyProfile(cinfo dto.ClientInfo) (*dto.ProfileDto, error) {
|
||||||
|
db := database.NewDbHelper(p.dbctx);
|
||||||
|
|
||||||
|
profile, err := db.Queries.GetProfileByUsername(db.CTX, cinfo.Username); if err != nil {
|
||||||
|
p.log.Error(
|
||||||
|
"Failed to find user profile by username",
|
||||||
|
zap.Error(err))
|
||||||
|
return nil, errs.ErrServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
var profileDto dto.ProfileDto
|
||||||
|
mapspecial.MapProfileDto(profile, profileDto)
|
||||||
|
|
||||||
|
return &profileDto, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *profileServiceImpl) GetProfileByUsername(cinfo dto.ClientInfo, username string) (*dto.ProfileDto, error) {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *profileServiceImpl) GetProfileByUsername(cinfo dto.ClientInfo, username string) (dto.ProfileDto, error) {
|
func (p *profileServiceImpl) GetProfileSettings(cinfo dto.ClientInfo) (*dto.ProfileSettingsDto, error) {
|
||||||
panic("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *profileServiceImpl) GetProfileSettings(cinfo dto.ClientInfo) (dto.ProfileSettingsDto, error) {
|
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +79,6 @@ func (p *profileServiceImpl) UpdateProfileSettings(cinfo dto.ClientInfo, newProf
|
|||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *profileServiceImpl) UploadAvatar(cinfo dto.ClientInfo, filePath string) (string, error) {
|
func (p *profileServiceImpl) UploadAvatar(cinfo dto.ClientInfo, filePath string) (*string, error) {
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/rafiulgits/go-automapper"
|
"github.com/rafiulgits/go-automapper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Map(dbModel database.Profile, dtoModel dto.ProfileDto) {
|
func MapProfileDto(dbModel database.Profile, dtoModel dto.ProfileDto) {
|
||||||
automapper.Map(dbModel, &dbModel, func(src *database.Profile, dst *dto.ProfileDto) {
|
automapper.Map(dbModel, &dbModel, func(src *database.Profile, dst *dto.ProfileDto) {
|
||||||
dst.Birthday = int64(dbModel.Birthday.Time.UnixMilli())
|
dst.Birthday = int64(dbModel.Birthday.Time.UnixMilli())
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user