Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MyMentorProject/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions MyMentorProject/.idea/MyMentorProject.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions MyMentorProject/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

461 changes: 461 additions & 0 deletions MyMentorProject/.idea/dbnavigator.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions MyMentorProject/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions MyMentorProject/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions MyMentorProject/.idea/jpa-buddy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions MyMentorProject/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions MyMentorProject/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions MyMentorProject/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added MyMentorProject/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions MyMentorProject/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
58 changes: 58 additions & 0 deletions MyMentorProject/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.Deny</groupId>
<artifactId>MyMentorProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MyMentorProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>



<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.Deny.MyMentorProject.Controllers;

import com.Deny.MyMentorProject.Services.UserService;
import com.Deny.MyMentorProject.User.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserMainController {

@Autowired

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Autowired

UserService userService;

public UserMainController(UserService userService) {
this.userService = userService;
}

@GetMapping
public String helloMessage() {

return userService. helloMessage();
}

@GetMapping("/greetUser")
public String helloUser() {

return "hello " + userService.helloUser();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this feature was to be able to accept a name and greet that person. You should not hard-code Joe into your app. Have it work for any name the consumer passes to you.

}
@PostMapping("greetings" )
public String messageToReturn(@RequestBody String requestMessage ){
System.out.println("requestMessage = " + requestMessage);
return userService.messageToReTurn( requestMessage);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.Deny.MyMentorProject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyMentorProjectApplication {

public static void main(String[] args) {
SpringApplication.run(MyMentorProjectApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.Deny.MyMentorProject.Services;

import com.Deny.MyMentorProject.User.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

@Autowired
Denywiryk marked this conversation as resolved.
Show resolved Hide resolved
User user;


public UserService(User user) { this.user = user;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User is a model class that frequently changes so it should not be injected into this class. Instead you would want it to be an input to a method.

}


public String helloMessage() {
return "Hello My Friend !";}
Denywiryk marked this conversation as resolved.
Show resolved Hide resolved

public String helloUser() {
user.setName("Joe");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of setting the name to Joe, pass in the name in the method

return "hello " + user.getName();
}
public String messageToReTurn(String messagerequest) {

String reply = "";

if (messagerequest ==""){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature 3 should be a random greeting. You can create a list of the statements below and call a randomIndex using java.util.Random.

Hello {User}!
Hey {User}, nice to see you here!
{User} welcome back!
Have a splendid day {User}.

reply = "hello " + user.getName();
}
else if (messagerequest ==" happy Message") {
reply = "Hey " + user.getName() + " nice to see you here !!";
}
else if (messagerequest =="welcome me") {

reply = user.getName() +" welcome back !!";
} else if (messagerequest=="bye message") {
reply= "Have a splendid day "+user.getName();

}
System.out.println("messagerequest = " + messagerequest);
return reply;
}


}




Loading