Skip to content

Commit 50019a7

Browse files
committed
feat: add user model, repository and controller
1 parent 280f78e commit 50019a7

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.luwis.application;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
6+
7+
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
8+
public class Application {
9+
10+
public static void main(String[] args) {
11+
SpringApplication.run(Application.class, args);
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.luwis.application.user;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.graphql.data.method.annotation.Argument;
5+
import org.springframework.graphql.data.method.annotation.MutationMapping;
6+
import org.springframework.stereotype.Controller;
7+
8+
@Controller
9+
public class UserController {
10+
11+
@Autowired
12+
private UserRepository userRepository;
13+
14+
@MutationMapping
15+
public UserModel userSignup(@Argument String username, @Argument String email, @Argument String password) {
16+
UserModel newUser = new UserModel(username, email, password);
17+
return userRepository.save(newUser);
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.luwis.application.user;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
8+
@Entity
9+
public class UserModel {
10+
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.AUTO)
13+
private Long id;
14+
private String username;
15+
private String email;
16+
private String password;
17+
18+
protected UserModel() {}
19+
20+
public UserModel(String username, String email, String password) {
21+
this.username = username;
22+
this.email = email;
23+
this.password = password;
24+
}
25+
26+
@Override
27+
public String toString() {
28+
return String.format("UserModel[id=%d, username='%s', email='%s', password='%s']", id, username, email, password);
29+
}
30+
31+
public Long getId() {
32+
return id;
33+
}
34+
35+
public String getUsername() {
36+
return username;
37+
}
38+
39+
public String getEmail() {
40+
return email;
41+
}
42+
43+
public String getPassword() {
44+
return password;
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.luwis.application.user;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
import org.springframework.stereotype.Repository;
5+
6+
@Repository
7+
public interface UserRepository extends CrudRepository<UserModel, Long> {
8+
9+
}

0 commit comments

Comments
 (0)