-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathMain.java
More file actions
68 lines (60 loc) · 2.28 KB
/
Main.java
File metadata and controls
68 lines (60 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.amigoscode;
import com.amigoscode.customer.Customer;
import com.amigoscode.customer.CustomerRepository;
import com.amigoscode.customer.Gender;
import com.amigoscode.s3.S3Buckets;
import com.amigoscode.s3.S3Service;
import com.github.javafaker.Faker;
import com.github.javafaker.Name;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.Random;
import java.util.UUID;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
@Bean
CommandLineRunner runner(
CustomerRepository customerRepository,
PasswordEncoder passwordEncoder) {
return args -> {
createRandomCustomer(customerRepository, passwordEncoder);
// testBucketUploadAndDownload(s3Service, s3Buckets);
};
}
private static void testBucketUploadAndDownload(S3Service s3Service, S3Buckets s3Buckets) {
s3Service.putObject(
s3Buckets.getCustomer(),
"foo",
"Hello World!".getBytes()
);
byte[] obj = s3Service.getObject(
s3Buckets.getCustomer(),
"foo"
);
System.out.println("Hooray " + new String(obj));
}
private static void createRandomCustomer(CustomerRepository customerRepository, PasswordEncoder passwordEncoder) {
var faker = new Faker();
Random random = new Random();
Name name = faker.name();
String firstName = name.firstName();
String lastName = name.lastName();
int age = random.nextInt(16, 99);
Gender gender = age % 2 == 0 ? Gender.MALE : Gender.FEMALE;
String email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@amigoscode.com";
Customer customer = new Customer(
firstName + " " + lastName,
email,
passwordEncoder.encode("password"),
age,
gender);
customerRepository.save(customer);
System.out.println(email);
}
}