-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from khoa-nd/master
Please pull the latest code
- Loading branch information
Showing
34 changed files
with
4,182 additions
and
17 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/techlooper/bootcamp/BootcampController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.techlooper.bootcamp; | ||
|
||
import com.google.common.io.Files; | ||
import com.techlooper.util.JsonUtils; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by phuonghqh on 1/29/15. | ||
*/ | ||
@Controller | ||
public class BootcampController { | ||
|
||
@ResponseBody | ||
@RequestMapping(value = "/bootcamp/users", method = RequestMethod.POST) | ||
public void save(@RequestBody BootcampUserInfo bootcampUserInfo, HttpServletResponse httpServletResponse) throws IOException { | ||
File jsonFile = new File("bootcamp-users.json"); | ||
StringBuilder jsonBuilder = new StringBuilder(); | ||
if (jsonFile.exists()) { | ||
Files.readLines(jsonFile, StandardCharsets.UTF_8).stream().forEach(jsonBuilder::append); | ||
} | ||
|
||
List<BootcampUserInfo> users = JsonUtils.toList(jsonBuilder.toString(), BootcampUserInfo.class).orElse(new ArrayList<>()); | ||
users.add(bootcampUserInfo); | ||
JsonUtils.getObjectMapper().writeValue(jsonFile, users); | ||
httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/techlooper/bootcamp/BootcampUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.techlooper.bootcamp; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
/** | ||
* Created by phuonghqh on 1/29/15. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class BootcampUserInfo { | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
private String currentJobTitle; | ||
|
||
private String emailAddress; | ||
|
||
private String phoneNumber; | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getCurrentJobTitle() { | ||
return currentJobTitle; | ||
} | ||
|
||
public void setCurrentJobTitle(String currentJobTitle) { | ||
this.currentJobTitle = currentJobTitle; | ||
} | ||
|
||
public String getEmailAddress() { | ||
return emailAddress; | ||
} | ||
|
||
public void setEmailAddress(String emailAddress) { | ||
this.emailAddress = emailAddress; | ||
} | ||
|
||
public String getPhoneNumber() { | ||
return phoneNumber; | ||
} | ||
|
||
public void setPhoneNumber(String phoneNumber) { | ||
this.phoneNumber = phoneNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.techlooper.util; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Created by NguyenDangKhoa on 1/29/15. | ||
*/ | ||
public class EmailValidator { | ||
|
||
private static final String EMAIL_PATTERN = | ||
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" | ||
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; | ||
|
||
private static Pattern pattern = Pattern.compile(EMAIL_PATTERN); | ||
private static Matcher matcher; | ||
|
||
public static boolean validate(final String email) { | ||
matcher = pattern.matcher(email); | ||
return matcher.matches(); | ||
} | ||
|
||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.