Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
damedelion committed Dec 17, 2024
1 parent dddc02a commit 1ffd32a
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 42 deletions.
4 changes: 2 additions & 2 deletions internal/utils/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func JSONError(response http.ResponseWriter, statusCode int, message string) {
response.WriteHeader(statusCode)

errorResponse := NewErrorResponse(message)
//if err := json.NewEncoder(response).Encode(errorResponse); err != nil {
rawBytes, err := easyjson.Marshal(errorResponse)
if err != nil {
http.Error(response, "failed to encode error message", http.StatusInternalServerError)
}
response.Write(rawBytes)
_, _ = response.Write(rawBytes)

}

//easyjson:json
Expand Down
48 changes: 42 additions & 6 deletions microservices/album/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ func (handlers *albumHandlers) SearchAlbum(response http.ResponseWriter, request
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// ViewAlbum godoc
Expand Down Expand Up @@ -97,8 +103,14 @@ func (handlers *albumHandlers) ViewAlbum(response http.ResponseWriter, request *
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetAll godoc
Expand Down Expand Up @@ -128,8 +140,14 @@ func (handlers *albumHandlers) GetAll(response http.ResponseWriter, request *htt
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetAllByArtistID godoc
Expand Down Expand Up @@ -169,8 +187,14 @@ func (handlers *albumHandlers) GetAllByArtistID(response http.ResponseWriter, re
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

func (handlers *albumHandlers) AddFavoriteAlbum(response http.ResponseWriter, request *http.Request) {
Expand Down Expand Up @@ -257,8 +281,14 @@ func (handlers *albumHandlers) IsFavoriteAlbum(response http.ResponseWriter, req
utils.JSONError(response, http.StatusInternalServerError, fmt.Sprintf("Failed to encode: %v", err))
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

func (handlers *albumHandlers) GetFavoriteAlbums(response http.ResponseWriter, request *http.Request) {
Expand Down Expand Up @@ -287,6 +317,12 @@ func (handlers *albumHandlers) GetFavoriteAlbums(response http.ResponseWriter, r
utils.JSONError(response, http.StatusInternalServerError, fmt.Sprintf("Failed to encode albums: %v", err))
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}
40 changes: 35 additions & 5 deletions microservices/artist/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ func (handlers *artistHandlers) SearchArtist(response http.ResponseWriter, reque
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// ViewArtist godoc
Expand Down Expand Up @@ -97,8 +103,14 @@ func (handlers *artistHandlers) ViewArtist(response http.ResponseWriter, request
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetAll godoc
Expand Down Expand Up @@ -127,8 +139,14 @@ func (handlers *artistHandlers) GetAll(response http.ResponseWriter, request *ht
utils.JSONError(response, http.StatusInternalServerError, fmt.Sprintf("Failed to encode artists: %v", err))
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// AddFavoriteArtist godoc
Expand Down Expand Up @@ -242,8 +260,14 @@ func (handlers *artistHandlers) IsFavoriteArtist(response http.ResponseWriter, r
utils.JSONError(response, http.StatusInternalServerError, fmt.Sprintf("Failed to encode: %v", err))
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetFavoriteArtists godoc
Expand Down Expand Up @@ -279,6 +303,12 @@ func (handlers *artistHandlers) GetFavoriteArtists(response http.ResponseWriter,
utils.JSONError(response, http.StatusInternalServerError, fmt.Sprintf("Failed to encode artists: %v", err))
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}
24 changes: 21 additions & 3 deletions microservices/csat/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ func (handlers *csatHandlers) SubmitAnswer(response http.ResponseWriter, request
utils.JSONError(response, http.StatusInternalServerError, "failed to return updated user details")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

func (handlers *csatHandlers) GetQuestionsByTopic(response http.ResponseWriter, request *http.Request) {
Expand Down Expand Up @@ -104,8 +110,14 @@ func (handlers *csatHandlers) GetQuestionsByTopic(response http.ResponseWriter,
utils.JSONError(response, http.StatusInternalServerError, "failed to return updated user details")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

func (handlers *csatHandlers) GetStatistics(response http.ResponseWriter, request *http.Request) {
Expand All @@ -124,6 +136,12 @@ func (handlers *csatHandlers) GetStatistics(response http.ResponseWriter, reques
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}
24 changes: 21 additions & 3 deletions microservices/genre/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ func (handlers *genreHandlers) GetAll(response http.ResponseWriter, request *htt
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetAllByArtistID godoc
Expand Down Expand Up @@ -90,8 +96,14 @@ func (handlers *genreHandlers) GetAllByArtistID(response http.ResponseWriter, re
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}

// GetAllByTrackID godoc
Expand Down Expand Up @@ -131,6 +143,12 @@ func (handlers *genreHandlers) GetAllByTrackID(response http.ResponseWriter, req
utils.JSONError(response, http.StatusInternalServerError, "Encode fail")
return
}
response.Write(rawBytes)

response.WriteHeader(http.StatusOK)
_, err = response.Write(rawBytes)
if err != nil {
handlers.logger.Error(fmt.Sprintf("Failed to write response: %v", err), requestID)
utils.JSONError(response, http.StatusInternalServerError, "Write response fail")
return
}
}
Loading

0 comments on commit 1ffd32a

Please sign in to comment.