Skip to content

Topic 4 crud #55

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions ReadmeResistencia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Los tutores del Bootcamp de Resistencia son:

"Dario Santiago Vallejos" <[email protected]>
"Gabriel Zimmermann" <[email protected]>
"Mauro Daniel Perez" <[email protected]>
"Nicolas Pogulanik" <[email protected]>
"Justo Vargas" <[email protected]>

Site Manager

"Juan Delfino" <[email protected]>,

Champion

"Claudia Romero" <[email protected]>,
78 changes: 78 additions & 0 deletions exercise_1/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author roberta
*/
public class Circle { // save as "Circle.java"
// private instance variable, not accessible from outside this class

private double radius;
private String color;

// 1st constructor, which sets both radius and color to default
public Circle() {
radius = 1.0;
color = "red";
}

// 2nd constructor with given radius, but color default
public Circle(double r) {
radius = r;
color = "red";
}

//1) 3rd constructor with the given radius and color
/**
* public Circle(double r, String c) {
*
* radius = r; color = c;
*
* }
*/
// A public method for retrieving the radius
public double getRadius() {
return radius;
}

// A public method for computing the area of circle
public double getArea() {
return radius * radius * Math.PI;
}

//2) Getter for instance variable color
public String getColor() {
return color;
}

/**
* 4)Setter for instance variable radius public void setRadius(double r) {
* radius = r; }
*
* //4)// Setter for instance variable color public void setColor(String c){
* color = c; }
*/
//5) Using the special keyword "this"
public void setRadius(double radius) {
this.radius = radius;
}

public void setColor(String color) {
this.color = color;
}

//5) Using the special keyword "this"
public Circle(double radius, String color) {
this.color = color;
this.radius = radius;
}

public String toString() {
return "Circle: radius=" + radius + " color=" + color;
}

}
47 changes: 47 additions & 0 deletions exercise_1/TestCircle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author roberta
*/
public class TestCircle { // save as "TestCircle.java"

public static void main(String[] args) {
// Declare and allocate an instance of class Circle called c1
// with default radius and color
Circle c1 = new Circle();
// Use the dot operator to invoke methods of instance c1.
System.out.println("The circle has radius of "
+ c1.getRadius() + " and area of " + c1.getArea());

// Declare and allocate an instance of class circle called c2
// with the given radius and default color
Circle c2 = new Circle();
// Use the dot operator to invoke methods of instance c2.
System.out.println("The circle has radius of "
+ c2.getRadius() + " and area of " + c2.getArea());

// 3) System.out.println(c1.radius); No, I can't because it has private access in Circle
// c1.radius=5.0;

// 4)
Circle c3 = new Circle(); // construct an instance of Circle
c3.setRadius(5.0); // change radius
c3.setColor("green"); // change color

/**5) toString
Circle c6 = new Circle(5.0);
System.out.println(c1.toString());

Circle c5 = new Circle(1.2);
System.out.println(c5.toString()); // explicit call
System.out.println(c5); // println() calls toString() implicitly, same as above
System.out.println("Operator '+' invokes toString() too: " + c2); // '+' invokes toString() too */


}
}
51 changes: 51 additions & 0 deletions topic4-CRUD/userService/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.10.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>


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

<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
14 changes: 14 additions & 0 deletions topic4-CRUD/userService/src/main/java/hello/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hello;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@EnableAutoConfiguration
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
122 changes: 122 additions & 0 deletions topic4-CRUD/userService/src/main/java/hello/MySystemController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hello;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author roberta
*/
public class MySystemController {

private List<User> userList = new ArrayList<User>();
private static MySystemController system;

public static MySystemController getInstance() {
if (system == null) {
system = new MySystemController();

}
return system;
}

private MySystemController() {
}

/**
* Creates a new user,if the user already exists displays an exception
*
* @param userName
* @param email
* @param password
* @param realName
* @throws UserAlreadyExistsException
*/
public void createUser(String userName, String email, String password, String realName) throws UserAlreadyExistsException {

User user = new User(userName, email, password, realName);
if (!userList.contains(user)) {
userList.add(user);
} else {
throw new UserAlreadyExistsException("User already exists!");
}
}

/**
* Eliminate a user if exists and matches with the email inserted
*
* @param email
*
*/
public void deleteUser(String email) {
Integer indexOf = null;
for (User u : userList) {
if (u.getEmail().equals(email)) {
indexOf = userList.indexOf(u);
break;
}
}
if (indexOf != null) {
userList.remove(userList.get(indexOf));
}
}

/**
* Search the user by userName and return a list with the values.
*
* @param userName
* @return
*/
public List<User> readUser(String userName) {
List<User> resultList = new ArrayList<User>();
for (User u : userList) {
if (u.getUserName().contains(userName)) {
resultList.add(u);
}
}
return resultList;

}

/**
* Find a user by mail
*
* @param mail
* @return
*/
public User retrieveUser(String mail) {

for (User u : userList) {
if (u.getEmail().equals(mail)) {
return u;
}
}
return null;
}

/**
* Search for the email, and update userName | password | realName
*
* @param userName
* @param password
* @param email
* @param realName
*/
public void updateUser(String userName, String password, String email, String realName) {

for (User u : userList) {
if (u.getEmail().equals(email)) {
u.setPassword(password);
u.setRealName(realName);
u.setUserName(userName);
break;
}
}
}

}
15 changes: 15 additions & 0 deletions topic4-CRUD/userService/src/main/java/hello/Photo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package hello;

/**
*
* @author roberta
*/
public class Photo {

}
Loading