diff --git a/0-0-intro/0-0-1-welcome-to-java-web-exercises/README.MD b/0-0-intro/0-0-1-welcome-to-java-web-exercises/README.MD
deleted file mode 100644
index 4aecf01..0000000
--- a/0-0-intro/0-0-1-welcome-to-java-web-exercises/README.MD
+++ /dev/null
@@ -1,17 +0,0 @@
-#
Welcome to Java Web Exercises
-
-This is a welcome test project to check if everything works okay on your computer
-
-### You should have installed on your local machine ❗️
-* [JDK 17+](hhttps://jdk.java.net/17/)
-* [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
-
-### How to start ❓
-
-* Just **clone the repository** to your computer
-* Open project in your IDE and **configure JDK 17** for the project
-* Open terminal and **run a command** `./mvnw clean package` (UNIX) or `mvnw.cmd clean package` (Windows)
-* Open class `WelcomeToJavaWebCourseApp` and **run** `main()`
-* [Click here](http://localhost:8080/welcome) 🔗
-
-### You'll see if it works 😉
diff --git a/0-0-intro/0-0-1-welcome-to-java-web-exercises/pom.xml b/0-0-intro/0-0-1-welcome-to-java-web-exercises/pom.xml
deleted file mode 100644
index 7f9b236..0000000
--- a/0-0-intro/0-0-1-welcome-to-java-web-exercises/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
Welcome to Java Web Exercises
-
-- * change the URL to http://localhost:8080/welcome?name=YourName -
-- * todo: mark this class as config - * todo: enable component scanning for all packages in "com.bobocode" - * todo: ignore all web related config and beans (ignore @{@link Controller}, ignore {@link EnableWebMvc}) using exclude filter */ +@Configuration +@ComponentScan(basePackages = "com.bobocode", + excludeFilters = { + @ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class), + @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class), + }) public class RootConfig { } diff --git a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebAppInitializer.java b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebAppInitializer.java index ee23400..e4c4b8a 100644 --- a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebAppInitializer.java +++ b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebAppInitializer.java @@ -1,6 +1,5 @@ package com.bobocode.config; -import com.bobocode.util.ExerciseNotCompletedException; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; /** @@ -9,16 +8,16 @@ public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class>[] getRootConfigClasses() { - throw new ExerciseNotCompletedException(); //todo: use {@link RootConfig} as root application config class + return new Class[]{RootConfig.class}; } @Override protected Class>[] getServletConfigClasses() { - throw new ExerciseNotCompletedException(); //todo: use {@link WebConfig} as ServletConfig class + return new Class[]{WebConfig.class}; } @Override protected String[] getServletMappings() { - throw new ExerciseNotCompletedException(); //todo: provide default servlet mapping ("/") + return new String[]{"/"}; } } diff --git a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebConfig.java b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebConfig.java index 66d3a84..dff4f92 100644 --- a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebConfig.java +++ b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/config/WebConfig.java @@ -9,10 +9,9 @@ * each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined * in the root ApplicationContext. *
- * todo: mark this class as Spring config class - * todo: enable web mvc using annotation - * todo: enable component scanning for package "web" */ - +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "com.bobocode.web") public class WebConfig { } diff --git a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/web/controller/WelcomeController.java b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/web/controller/WelcomeController.java index 77392cc..9da6e2b 100644 --- a/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/web/controller/WelcomeController.java +++ b/3-0-spring-framework/3-1-1-dispatcher-servlet-initializer/src/main/java/com/bobocode/web/controller/WelcomeController.java @@ -1,16 +1,20 @@ package com.bobocode.web.controller; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + /** * Welcome controller that consists of one method that handles get request to "/welcome" and respond with a message. *
- * todo: mark this class as Spring controller - * todo: configure HTTP GET mapping "/welcome" for method {@link WelcomeController#welcome()} - * todo: tell Spring that {@link WelcomeController#welcome()} method provides response body without view */ - +@Controller public class WelcomeController { + @GetMapping("/welcome") + @ResponseBody public String welcome() { - return "Welcome to Spring MVC!"; + + return "welcome"; } } diff --git a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/RootConfig.java b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/RootConfig.java index c5d1a6d..923ba57 100644 --- a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/RootConfig.java +++ b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/RootConfig.java @@ -1,14 +1,20 @@ package com.bobocode.config; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.config.annotation.EnableWebMvc; /** * This class provides application root (non-web) configuration. *
- * todo: 1. Mark this class as config - * todo: 2. Enable component scanning for all packages in "com.bobocode" using annotation property "basePackages" - * todo: 3. Exclude web related config and beans (ignore @{@link Controller}, ignore {@link EnableWebMvc}) */ +@Configuration +@ComponentScan(basePackages = "com.bobocode", + excludeFilters = { + @ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class), + @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class), + }) public class RootConfig { } diff --git a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/WebConfig.java b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/WebConfig.java index 1197302..546ce63 100644 --- a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/WebConfig.java +++ b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/WebConfig.java @@ -1,11 +1,15 @@ package com.bobocode.config; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + /** * This class provides web (servlet) related configuration. *
- * todo: 1. Mark this class as Spring config class - * todo: 2. Enable web mvc using annotation - * todo: 3. Enable component scanning for package "web" using annotation value */ +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "com.bobocode.web") public class WebConfig { } diff --git a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/dao/impl/InMemoryAccountDao.java b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/dao/impl/InMemoryAccountDao.java index 5620d5b..f531ce7 100644 --- a/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/dao/impl/InMemoryAccountDao.java +++ b/3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/dao/impl/InMemoryAccountDao.java @@ -3,6 +3,7 @@ import com.bobocode.dao.AccountDao; import com.bobocode.exception.EntityNotFountException; import com.bobocode.model.Account; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; @@ -12,8 +13,8 @@ /** * {@link AccountDao} implementation that is based on {@link java.util.HashMap}. *
- * todo: 1. Configure a component with name "accountDao"
*/
+@Component("accountDao")
public class InMemoryAccountDao implements AccountDao {
private Map
- * todo: 1. Configure rest controller that handles requests with url "/accounts"
- * todo: 2. Inject {@link AccountDao} implementation
- * todo: 3. Implement method that handles GET request and returns a list of accounts
- * todo: 4. Implement method that handles GET request with id as path variable and returns account by id
- * todo: 5. Implement method that handles POST request, receives account as request body, saves account and returns it
- * todo: Configure HTTP response status code 201 - CREATED
- * todo: 6. Implement method that handles PUT request with id as path variable and receives account as request body.
- * todo: It check if account id and path variable are the same and throws {@link IllegalStateException} otherwise.
- * todo: Then it saves received account. Configure HTTP response status code 204 - NO CONTENT
- * todo: 7. Implement method that handles DELETE request with id as path variable removes an account by id
- * todo: Configure HTTP response status code 204 - NO CONTENT
*/
+@RestController
+@RequestMapping("/accounts")
+@RequiredArgsConstructor
public class AccountRestController {
+ private final AccountDao accountDao;
+
+ @GetMapping
+ public List