Coder Social home page Coder Social logo

jonasknobloch / nhie Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 1.0 216 KB

No-bullshit "Never Have I Ever" implementation for the web.

Home Page: https://boozee.app

License: MIT License

Go 52.64% HTML 14.20% JavaScript 17.82% CSS 14.41% Dockerfile 0.93%
api game go js vanilla-js

nhie's People

Contributors

jonasknobloch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

qbnm

nhie's Issues

Simplify random endpoint routing

if r := strings.Split(ctx.Request.URL.String(), "/random"); len(r) == 2 { // && r[1] == ""
    s, err = getRandomStatement(g)
} else {
    s, err = getStatementByID(g)
}

statement.go

Just use g.C.Params.ByName("id") == "random" instead.

Simplify translated statement response

Before

{
  "ID": "223005ec-1251-4dab-bc82-4f4ff759b525",
  "statement": "Never have I ever been to a drive-in movie.",
  "category": "offensive",
  "translations": {
    "de": "Ich war noch nie in einem Autokino.",
    "es": "Nunca he estado en un autocine.",
  }
}

After

{
  "ID": "223005ec-1251-4dab-bc82-4f4ff759b525",
  "statement": "Ich war noch nie in einem Autokino.",
  "category": "delicate"
}

No reason for multiple translation -> keep it simple. Keeping the FetchTranslations method for now.

Absturz der API Website

Hallo, ich hoffe, es ist okay, dass ich eure/deine API in einem Software Development Projekt zur Entwicklung einer pwa nutze.
Ich habe die api auch schon eingebunden, allerdings ist die Website seit heute nicht mehr erreichbar. Ist es geplant die api wieder online zu stellen oder ist diese dauerhaft nicht mehr verfügbar?

mfG

Christopher

Introduce game functionality

A game guarantees unique statements. Finished games get cleaned up.

Endpoints

  • POST /games starts a new game and returns game_id
  • GET /games/:game_id/statements/random new random statement
  • GET /games/:game_id/statements game history (no duplicates)
  • GET /games/:game_id/statements/:statement_id redirects to /statements/:statement_id

Improve braindead error returns

func getStatementByID(g app.Gin) (*statement.Statement, error) {
	// g.C.Params.ByName("id") returns an empty string if no matching key is found
	id, err := uuid.Parse(g.C.Params.ByName("id"))

	if err != nil {
		g.ErrorResponse(problem.Default(http.StatusBadRequest))
		return nil, nil
	}

	return statement.GetByID(id)
}

Problem
Returning nil, nil to indicate that an error is handled (e.g. response is set) is probably a bad idea.

Possible Solution(s)
Custom error to indicated the response is set / the error is handled?
Just return error and set response in endpoint handler?

Translation with parameters

Nice project

wondering if you are planning to model parameters so that a string with parameters can be translated.

Deepl seems to support it

Improve random category query mocking

query := `SELECT * FROM "statements" WHERE "statements"."category" = $1 AND "statements"."deleted_at" IS NULL LIMIT 1`

The current query works because the test database contains only one row and GORM omits OFFSET 0. Not testing the behaviour with more than one row seems like a bad idea.

Remove cache serialization

Introduced it to store the whole translatepb.TranslateTextResponse. This is overkill since we can simply extract the translated string and cache it directly.

Accept language value en

The request https://api.nhie.io/v1/statements/random?language=en currently will return

{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "English is currently not supported."
}

this is fucking stupid
PLs FiX :/

KnObO wHatcH BeHaiN

Guarantee unique statements

  • Cache served statements
  • Retrieve random statement
  • Check if random statement was already served
  • Retrieve new random statement if necessary

Add logger

  • Get rid of error middleware
  • Use log package
  • Evaluate sentry (or alternatives) for error tracking

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.