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:
@@ -20,18 +20,20 @@ package services
|
||||
import (
|
||||
"easywish/internal/database"
|
||||
"easywish/internal/dto"
|
||||
errs "easywish/internal/errors"
|
||||
mapspecial "easywish/internal/utils/mapSpecial"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ProfileService interface {
|
||||
GetProfileByUsername(cinfo dto.ClientInfo, username string) (dto.ProfileDto, error)
|
||||
GetMyProfile(cinfo dto.ClientInfo) (dto.ProfileDto, error)
|
||||
GetProfileByUsername(cinfo dto.ClientInfo, username string) (*dto.ProfileDto, error)
|
||||
GetMyProfile(cinfo dto.ClientInfo) (*dto.ProfileDto, 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)
|
||||
UploadAvatar(cinfo dto.ClientInfo, filePath string) (string, error)
|
||||
UploadAvatar(cinfo dto.ClientInfo, filePath string) (*string, error)
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
func (p *profileServiceImpl) GetProfileByUsername(cinfo dto.ClientInfo, username string) (dto.ProfileDto, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (p *profileServiceImpl) GetProfileSettings(cinfo dto.ClientInfo) (dto.ProfileSettingsDto, error) {
|
||||
func (p *profileServiceImpl) GetProfileSettings(cinfo dto.ClientInfo) (*dto.ProfileSettingsDto, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
@@ -64,6 +79,6 @@ func (p *profileServiceImpl) UpdateProfileSettings(cinfo dto.ClientInfo, newProf
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user