Skip to content

Commit

Permalink
Stworzono kontroler do produktów
Browse files Browse the repository at this point in the history
  • Loading branch information
rabarbar15 authored Apr 22, 2024
1 parent b2dd70f commit 1f05bf7
Show file tree
Hide file tree
Showing 85 changed files with 279 additions and 0 deletions.
24 changes: 24 additions & 0 deletions zad2 - Scala/Products project/app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controllers

import javax.inject._
import play.api._
import play.api.mvc._

/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class HomeController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {

/**
* Create an Action to render an HTML page.
*
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package controllers

import javax.inject._
import play.api.mvc._
import play.api.libs.json._

@Singleton
class ProductController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {

def getAllProducts: Action[AnyContent] = Action {
Ok("List of all products")
}

def getProductById(id: Long): Action[AnyContent] = Action {
Ok(s"Product with ID $id")
}

def createProduct: Action[JsValue] = Action(parse.json) { request =>
Ok("Product created")
}

def updateProduct(id: Long): Action[JsValue] = Action(parse.json) { request =>
Ok(s"Product with ID $id updated")
}

def deleteProduct(id: Long): Action[AnyContent] = Action {
Ok(s"Product with ID $id deleted")

}
}
5 changes: 5 additions & 0 deletions zad2 - Scala/Products project/app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@()

@main("Welcome to Play") {
<h1>Welcome to Play!</h1>
}
25 changes: 25 additions & 0 deletions zad2 - Scala/Products project/app/views/main.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@*
* This template is called from the `index` template. This template
* handles the rendering of the page header and body tags. It takes
* two arguments, a `String` for the title of the page and an `Html`
* object to insert into the body of the page.
*@
@(title: String)(content: Html)

<!DOCTYPE html>
<html lang="en">
<head>
@* Here's where we render the page title `String`. *@
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">

</head>
<body>
@* And here's where we render the `Html` object containing
* the page content. *@
@content

<script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions zad2 - Scala/Products project/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name := """hello"""
organization := "kamil"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.13.13"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "7.0.0" % Test

// Adds additional packages into Twirl
//TwirlKeys.templateImports += "kamil.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "kamil.binders._"
11 changes: 11 additions & 0 deletions zad2 - Scala/Products project/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._

object hello extends PlayModule with SingleModule {

def scalaVersion = "2.13.13"
def playVersion = "3.0.2"
def twirlVersion = "2.0.1"

object test extends PlayTests
}
1 change: 1 addition & 0 deletions zad2 - Scala/Products project/conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# https://www.playframework.com/documentation/latest/Configuration
50 changes: 50 additions & 0 deletions zad2 - Scala/Products project/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->

<!DOCTYPE configuration>

<configuration>
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
<import class="ch.qos.logback.classic.AsyncAppender"/>
<import class="ch.qos.logback.core.FileAppender"/>
<import class="ch.qos.logback.core.ConsoleAppender"/>

<appender name="FILE" class="FileAppender">
<file>${application.home:-.}/logs/application.log</file>
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ConsoleAppender">
<!--
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
See https://logback.qos.ch/manual/layouts.html#coloring
-->
<!-- <withJansi>true</withJansi> -->
<encoder class="PatternLayoutEncoder">
<charset>UTF-8</charset>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
</encoder>
</appender>

<appender name="ASYNCFILE" class="AsyncAppender">
<appender-ref ref="FILE"/>
</appender>

<appender name="ASYNCSTDOUT" class="AsyncAppender">
<appender-ref ref="STDOUT"/>
</appender>

<logger name="play" level="INFO"/>
<logger name="application" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="ASYNCFILE"/>
<appender-ref ref="ASYNCSTDOUT"/>
</root>

</configuration>
1 change: 1 addition & 0 deletions zad2 - Scala/Products project/conf/messages
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# https://www.playframework.com/documentation/latest/ScalaI18N
16 changes: 16 additions & 0 deletions zad2 - Scala/Products project/conf/routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Routes
# This file defines all application routes (Higher priority routes first)
# https://www.playframework.com/documentation/latest/ScalaRouting
# ~~~~

# An example controller showing a sample home page
GET / controllers.HomeController.index()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

GET /products controllers.ProductController.getAllProducts()
GET /products/:id controllers.ProductController.getProductById(id: Int)
POST /products controllers.ProductController.createProduct()
PUT /products/:id controllers.ProductController.updateProduct(id: Int)
DELETE /products/:id controllers.ProductController.deleteProduct(id: Int)
1 change: 1 addition & 0 deletions zad2 - Scala/Products project/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.8
2 changes: 2 additions & 0 deletions zad2 - Scala/Products project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.2")
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.16.2")
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.internal.DslEntry
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[{},{}],{}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
766366337

Large diffs are not rendered by default.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1196677430
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"{\"organization\":\"org.scala-lang\",\"name\":\"scala-library\",\"revision\":\"2.12.18\",\"configurations\":\"provided\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{},\"crossVersion\":{\"type\":\"Disabled\"}}":{"value":{"$fields":["path","range"],"path":"/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/plugins.sbt","range":{"$fields":["start","end"],"start":2,"end":3}},"type":"RangePosition"},"{\"organization\":\"org.playframework\",\"name\":\"sbt-plugin\",\"revision\":\"3.0.2\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{\"e:sbtVersion\":\"1.0\",\"e:scalaVersion\":\"2.12\"},\"crossVersion\":{\"type\":\"Disabled\"}}":{"value":{"$fields":["path","range"],"path":"/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/plugins.sbt","range":{"$fields":["start","end"],"start":2,"end":3}},"type":"RangePosition"},"{\"organization\":\"org.foundweekends.giter8\",\"name\":\"sbt-giter8-scaffold\",\"revision\":\"0.16.2\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{\"e:sbtVersion\":\"1.0\",\"e:scalaVersion\":\"2.12\"},\"crossVersion\":{\"type\":\"Disabled\"}}":{"value":{"$fields":["path","range"],"path":"/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/plugins.sbt","range":{"$fields":["start","end"],"start":2,"end":3}},"type":"RangePosition"}}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[debug] not up to date. inChanged = true, force = false
[debug] Updating ProjectRef(uri("file:/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/"), "hello-build")...
[info] Updating 
[info] Resolved dependencies
[info] Fetching artifacts of 
[info] Fetched artifacts of 
[debug] Done updating ProjectRef(uri("file:/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/"), "hello-build")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["sbt.Task[scala.collection.Seq[java.nio.file.Path]]",["/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/zinc/inc_compile_2.12.zip"]]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[debug] [zinc] IncrementalCompile -----------
[debug] IncrementalCompile.incrementalCompile
[debug] previous = Stamps for: 0 products, 0 sources, 0 libraries
[debug] current source = Set()
[debug] > initialChanges = InitialChanges(Changes(added = Set(), removed = Set(), changed = Set(), unmodified = ...),Set(),Set(),API Changes: Set())
[debug] Full compilation, no sources in previous analysis.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[debug] Copy resource mappings: 
[debug]  

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[debug] Created transactional ClassFileManager with tempDir = /Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes.bak
[debug] About to delete class files:
[debug] We backup class files:
[debug] Created transactional ClassFileManager with tempDir = /Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes.bak
[debug] Removing the temporary directory used for backing up class files: /Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/kamilpiskorz/Desktop/college/ebiznes/zad2/hello/project/target/scala-2.12/sbt-1.0/classes

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package controllers

import org.scalatestplus.play._
import org.scalatestplus.play.guice._
import play.api.test._
import play.api.test.Helpers._

/**
* Add your spec here.
* You can mock out a whole application including requests, plugins etc.
*
* For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
*/
class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {

"HomeController GET" should {

"render the index page from a new instance of controller" in {
val controller = new HomeController(stubControllerComponents())
val home = controller.index().apply(FakeRequest(GET, "/"))

status(home) mustBe OK
contentType(home) mustBe Some("text/html")
contentAsString(home) must include ("Welcome to Play")
}

"render the index page from the application" in {
val controller = inject[HomeController]
val home = controller.index().apply(FakeRequest(GET, "/"))

status(home) mustBe OK
contentType(home) mustBe Some("text/html")
contentAsString(home) must include ("Welcome to Play")
}

"render the index page from the router" in {
val request = FakeRequest(GET, "/")
val home = route(app, request).get

status(home) mustBe OK
contentType(home) mustBe Some("text/html")
contentAsString(home) must include ("Welcome to Play")
}
}
}

0 comments on commit 1f05bf7

Please sign in to comment.