feat: Swagger API 문서 추가 + 보스레이드/플레이어 레벨 시스템
- swaggo/swag 기반 전체 API 엔드포인트 Swagger 어노테이션 (59개) - /swagger/ 경로에 Swagger UI 제공 - 보스레이드 데디서버 관리 (등록, 하트비트, 슬롯 리셋) - 플레이어 레벨/경험치 시스템 및 스탯 성장 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -165,6 +165,43 @@ func (s *Service) SaveGameDataByUsername(username string, data *GameDataRequest)
|
||||
return s.SaveGameData(userID, data)
|
||||
}
|
||||
|
||||
// GrantExperience adds experience to a player and handles level ups + stat recalculation.
|
||||
func (s *Service) GrantExperience(userID uint, exp int) (*LevelUpResult, error) {
|
||||
profile, err := s.repo.FindByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("프로필이 존재하지 않습니다")
|
||||
}
|
||||
|
||||
result := ApplyExperience(profile.Level, profile.Experience, exp)
|
||||
|
||||
updates := map[string]interface{}{
|
||||
"level": result.NewLevel,
|
||||
"experience": result.Experience,
|
||||
"max_hp": result.MaxHP,
|
||||
"max_mp": result.MaxMP,
|
||||
"attack_power": result.AttackPower,
|
||||
}
|
||||
|
||||
if err := s.repo.UpdateStats(userID, updates); err != nil {
|
||||
return nil, fmt.Errorf("레벨업 저장 실패: %w", err)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GrantExperienceByUsername grants experience to a player by username.
|
||||
func (s *Service) GrantExperienceByUsername(username string, exp int) error {
|
||||
if s.userResolver == nil {
|
||||
return fmt.Errorf("userResolver가 설정되지 않았습니다")
|
||||
}
|
||||
userID, err := s.userResolver(username)
|
||||
if err != nil {
|
||||
return fmt.Errorf("존재하지 않는 유저입니다")
|
||||
}
|
||||
_, err = s.GrantExperience(userID, exp)
|
||||
return err
|
||||
}
|
||||
|
||||
// GameDataRequest 게임 데이터 저장 요청 (nil 필드는 변경하지 않음).
|
||||
type GameDataRequest struct {
|
||||
Level *int `json:"level,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user