-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
1,073 additions
and
778 deletions.
There are no files selected for viewing
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,15 @@ | ||
package client; | ||
|
||
import spring.ioc.annotation.ComponentScan; | ||
import spring.ioc.annotation.Configuration; | ||
import spring.mvc.web.TomcatStarter; | ||
|
||
@Configuration | ||
@ComponentScan(value = {"client"}) | ||
public class Application { | ||
public static void main(String[] args) { | ||
final TomcatStarter tomcatStarter = new TomcatStarter(); | ||
tomcatStarter.start(); | ||
tomcatStarter.await(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,48 +1,46 @@ | ||
package client.controller; | ||
|
||
import client.controller.dto.CreatUserDto; | ||
import client.model.User; | ||
import client.domain.User; | ||
import client.service.UserService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import spring.mvc.annotation.Controller; | ||
import spring.mvc.annotation.RequestMapping; | ||
import spring.mvc.controller.AbstractController; | ||
import spring.mvc.handler.mapping.RequestMethod; | ||
import spring.mvc.web.handler.mapping.RequestMethod; | ||
import spring.mvc.view.ModelAndView; | ||
|
||
import java.util.List; | ||
|
||
@Controller | ||
public class UserController extends AbstractController { | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
public UserController(final UserService userService) { | ||
this.userService = userService; | ||
} | ||
|
||
@RequestMapping("/users") | ||
@RequestMapping(value = "/users/create", method = RequestMethod.POST) | ||
public ModelAndView create(HttpServletRequest request, HttpServletResponse response) { | ||
CreatUserDto requestDto = CreatUserDto.of(request); | ||
User user = userService.createUser(requestDto); | ||
|
||
ModelAndView modelAndView = new ModelAndView(); | ||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
|
||
@RequestMapping(value = "/users", method = RequestMethod.GET) | ||
public ModelAndView getUsers(HttpServletRequest request, HttpServletResponse response) { | ||
int wannaSize = Integer.parseInt(request.getParameter("size")); | ||
List<User> users = userService.getUsersWithSize(wannaSize); | ||
|
||
ModelAndView modelAndView = jsonView(); | ||
for(int i = 0; i < wannaSize; i++) { | ||
ModelAndView modelAndView = new ModelAndView(); | ||
for (int i = 0; i < users.size(); i++) { | ||
User user = users.get(i); | ||
modelAndView.addObject("user"+ i, user); | ||
} | ||
|
||
return modelAndView; | ||
} | ||
|
||
@RequestMapping(value = "/users/create", method = RequestMethod.POST) | ||
public ModelAndView create(HttpServletRequest request, HttpServletResponse response) { | ||
CreatUserDto requestDto = CreatUserDto.of(request); | ||
User user = userService.createUser(requestDto); | ||
|
||
ModelAndView modelAndView = jsonView(); | ||
modelAndView.addObject("user", user); | ||
return modelAndView; | ||
} | ||
} |
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,29 @@ | ||
package client.domain; | ||
|
||
import client.controller.dto.CreatUserDto; | ||
|
||
public class User { | ||
private long userId; | ||
private String name; | ||
private String password; | ||
private String email; | ||
|
||
public User(long userId, String name, String password, String email) { | ||
this.userId = userId; | ||
this.name = name; | ||
this.password = password; | ||
this.email = email; | ||
} | ||
|
||
public void updateUserId(long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public static User from(final CreatUserDto dto) { | ||
return new User(0, dto.name(), dto.password(), dto.email()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/client/domain/repsotiroy/UserRepository.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,32 @@ | ||
package client.domain.repsotiroy; | ||
|
||
import client.controller.dto.CreatUserDto; | ||
import client.domain.User; | ||
import spring.ioc.annotation.Repository; | ||
import java.util.*; | ||
|
||
@Repository | ||
public class UserRepository { | ||
|
||
private final Map<Long, User> temporaryDatabase = new HashMap<>(); | ||
private Long SEQUENCE = 0L; | ||
|
||
public User save(User user) { | ||
long id = SEQUENCE++; | ||
user.updateUserId(id); | ||
temporaryDatabase.put(id, user); | ||
return user; | ||
} | ||
|
||
public List<User> getUsersWithLimit(int wannaSize) { | ||
while(temporaryDatabase.size() < wannaSize) { | ||
fixUser(); | ||
} | ||
return new ArrayList<>(temporaryDatabase.values()); | ||
} | ||
|
||
private void fixUser() { | ||
CreatUserDto dto = new CreatUserDto("김명준", "비밀번호", "[email protected]"); | ||
save(User.from(dto)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.