Skip to content

Commit

Permalink
backend : rename genres to beats
Browse files Browse the repository at this point in the history
  • Loading branch information
Babali42 committed Jan 27, 2025
1 parent a3865cc commit a02c33e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import secondary.repositoryFactory.BeatRepositoryFactory
import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext

@Singleton class GenreController @Inject()(val controllerComponents: ControllerComponents, val factory: BeatRepositoryFactory)(implicit ec: ExecutionContext) extends BaseController {
@Singleton class BeatController @Inject()(val controllerComponents: ControllerComponents, val factory: BeatRepositoryFactory)(implicit ec: ExecutionContext) extends BaseController {

def getGenres: Action[AnyContent] = Action.async { _ =>
def getBeats: Action[AnyContent] = Action.async { _ =>
val connectionString = sys.env.getOrElse("DATABASE_CONNECTION_STRING", "mongodb://admin:pass@localhost:27017")
val repository = factory.createMongoRepository(connectionString, "drum-beat-database")

repository.getAllBeats.map { documents =>
implicit val beatWrites: OWrites[Beat] = Json.writes[Beat]
val beats = documents.map(x => Json.toJson(x))
Ok(Json.toJson(beats))
}.recover { case ex: Throwable => InternalServerError(s"Error fetching genres: ${ex.getMessage}")
}.recover { case ex: Throwable => InternalServerError(s"Error fetching beats: ${ex.getMessage}")
}
}
}
2 changes: 1 addition & 1 deletion backend/conf/routes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GET /genres/ primary.GenreController.getGenres()
GET /beats/ primary.BeatController.getBeats()
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import play.api.test._
import play.api.test.Helpers._
import secondary.repositoryFactory.{BeatRepositoryFactory, InMemoryBeatRepositoryFactory}

class GenreControllerSpec extends PlaySpec {
"GenreController" should {
"get the JSON genres" in {
class BeatControllerSpec extends PlaySpec {
"BeatController" should {
"get the JSON beats" in {
val app = new GuiceApplicationBuilder()
.overrides(bind(classOf[BeatRepositoryFactory]).to(classOf[InMemoryBeatRepositoryFactory]))
.build()

val genreRequest = FakeRequest(GET, "/genres/")
val genresResult = route(app, genreRequest).get
val request = FakeRequest(GET, "/beats/")
val result = route(app, request).get

status(genresResult) mustBe OK
contentType(genresResult) mustBe Some("application/json")
contentAsString(genresResult) must include("Techno")
status(result) mustBe OK
contentType(result) mustBe Some("application/json")
contentAsString(result) must include("Techno")
}
}
}

0 comments on commit a02c33e

Please sign in to comment.