casey-chow/tigertrade

View on GitHub
server/models/listings.go

Summary

Maintainability
B
4 hrs
Test Coverage

Function buildListingQuery has 58 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func buildListingQuery(query *ListingQuery) sq.SelectBuilder {
    stmt := psql.
        Select(
            "listings.key_id",
            "listings.creation_date",
Severity: Minor
Found in server/models/listings.go - About 1 hr to fix

    Function ReadListings has 5 return statements (exceeds 4 allowed).
    Open

    func ReadListings(db *sql.DB, query *ListingQuery) ([]*Listing, int, error) {
        if query.UserID == 0 && (query.OnlyStarred || query.OnlyMine) {
            return nil, http.StatusUnauthorized, errors.New("unauthenticated user attempted to view profile data")
        }
    
    
    Severity: Major
    Found in server/models/listings.go - About 35 mins to fix

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      func DeleteListing(db *sql.DB, id string, userID int) (int, error) {
          // Delete listing
          stmt := psql.Delete("listings").
              Where(sq.Eq{
                  "listings.key_id":  id,
      Severity: Major
      Found in server/models/listings.go and 3 other locations - About 40 mins to fix
      server/models/listings.go on lines 464..474
      server/models/savedsearches.go on lines 218..229
      server/models/seeks.go on lines 289..300

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      func removeStar(db *sql.DB, listingID string, userID int) (int, error) {
          stmt := psql.Delete("starred_listings").
              Where(sq.Eq{
                  "listing_id": listingID,
                  "user_id":    userID,
      Severity: Major
      Found in server/models/listings.go and 3 other locations - About 40 mins to fix
      server/models/listings.go on lines 421..431
      server/models/savedsearches.go on lines 218..229
      server/models/seeks.go on lines 289..300

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              err := rows.Scan(
                  &l.KeyID,
                  &l.CreationDate,
                  &l.LastModificationDate,
                  &l.Title,
      Severity: Minor
      Found in server/models/listings.go and 1 other location - About 40 mins to fix
      server/models/listings.go on lines 303..318

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 110.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          err = rows.Scan(
              &listing.KeyID,
              &listing.CreationDate,
              &listing.LastModificationDate,
              &listing.Title,
      Severity: Minor
      Found in server/models/listings.go and 1 other location - About 40 mins to fix
      server/models/listings.go on lines 165..180

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 110.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status