feat: Enhance dependency injection and service integration
- Updated main.go to initialize email service and include it in the dependency injection container. - Refactored handlers to utilize context in service method calls, improving consistency and error handling. - Introduced new service options for upload, security, and captcha services, enhancing modularity and testability. - Removed unused repository implementations to streamline the codebase. This commit continues the effort to improve the architecture by ensuring all services are properly injected and utilized across the application.
This commit is contained in:
@@ -46,12 +46,12 @@ func (h *ProfileHandler) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
maxProfiles := h.container.UserService.GetMaxProfilesPerUser()
|
||||
if err := h.container.ProfileService.CheckLimit(userID, maxProfiles); err != nil {
|
||||
if err := h.container.ProfileService.CheckLimit(c.Request.Context(), userID, maxProfiles); err != nil {
|
||||
RespondBadRequest(c, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
profile, err := h.container.ProfileService.Create(userID, req.Name)
|
||||
profile, err := h.container.ProfileService.Create(c.Request.Context(), userID, req.Name)
|
||||
if err != nil {
|
||||
h.logger.Error("创建档案失败",
|
||||
zap.Int64("user_id", userID),
|
||||
@@ -80,7 +80,7 @@ func (h *ProfileHandler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err := h.container.ProfileService.GetByUserID(userID)
|
||||
profiles, err := h.container.ProfileService.GetByUserID(c.Request.Context(), userID)
|
||||
if err != nil {
|
||||
h.logger.Error("获取档案列表失败",
|
||||
zap.Int64("user_id", userID),
|
||||
@@ -110,7 +110,7 @@ func (h *ProfileHandler) Get(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
profile, err := h.container.ProfileService.GetByUUID(uuid)
|
||||
profile, err := h.container.ProfileService.GetByUUID(c.Request.Context(), uuid)
|
||||
if err != nil {
|
||||
h.logger.Error("获取档案失败",
|
||||
zap.String("uuid", uuid),
|
||||
@@ -158,7 +158,7 @@ func (h *ProfileHandler) Update(c *gin.Context) {
|
||||
namePtr = &req.Name
|
||||
}
|
||||
|
||||
profile, err := h.container.ProfileService.Update(uuid, userID, namePtr, req.SkinID, req.CapeID)
|
||||
profile, err := h.container.ProfileService.Update(c.Request.Context(), uuid, userID, namePtr, req.SkinID, req.CapeID)
|
||||
if err != nil {
|
||||
h.logger.Error("更新档案失败",
|
||||
zap.String("uuid", uuid),
|
||||
@@ -195,7 +195,7 @@ func (h *ProfileHandler) Delete(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.container.ProfileService.Delete(uuid, userID); err != nil {
|
||||
if err := h.container.ProfileService.Delete(c.Request.Context(), uuid, userID); err != nil {
|
||||
h.logger.Error("删除档案失败",
|
||||
zap.String("uuid", uuid),
|
||||
zap.Int64("user_id", userID),
|
||||
@@ -231,7 +231,7 @@ func (h *ProfileHandler) SetActive(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.container.ProfileService.SetActive(uuid, userID); err != nil {
|
||||
if err := h.container.ProfileService.SetActive(c.Request.Context(), uuid, userID); err != nil {
|
||||
h.logger.Error("设置活跃档案失败",
|
||||
zap.String("uuid", uuid),
|
||||
zap.Int64("user_id", userID),
|
||||
|
||||
Reference in New Issue
Block a user