This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
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
11 changed files
with
130 additions
and
64 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
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
31 changes: 17 additions & 14 deletions
31
src/main/java/com/sns/untitled/user/controller/UserController.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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
package com.sns.untitled.user.controller; | ||
|
||
import com.sns.untitled.user.dto.UserDto; | ||
import com.sns.untitled.user.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@Autowired | ||
public UserController(UserService userService){ | ||
this.userService = userService; | ||
@PostMapping("/login") | ||
public void login(@RequestParam String id, @RequestParam String password, HttpSession httpSession) { | ||
UserDto user = userService.login(id, password); | ||
httpSession.setAttribute("userInfo", user); | ||
} | ||
|
||
@PostMapping("/hello/{name}") | ||
public String hello(@PathVariable String name){ | ||
return userService.hello(name); | ||
@PostMapping("/logout") | ||
public void logout() { | ||
} | ||
|
||
@GetMapping("/login") | ||
public String login(){ | ||
return "test"; | ||
@GetMapping("/{id}") | ||
public UserDto getUserInfo(@PathVariable String id) { | ||
UserDto user = userService.getUserInfo(id); | ||
return user; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.sns.untitled.user.mapper; | ||
|
||
import com.sns.untitled.user.dto.UserDto; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
@Mapper | ||
public interface UserMapper { | ||
|
||
// void insertName(String name); | ||
UserDto findUserByIdAndPassword(@Param("id") String id, @Param("password") String password); | ||
|
||
UserDto findUserById(@Param("id") String id); | ||
|
||
} |
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,7 +1,11 @@ | ||
package com.sns.untitled.user.service; | ||
|
||
import com.sns.untitled.user.dto.UserDto; | ||
|
||
public interface UserService { | ||
|
||
public String hello(String name); | ||
UserDto login(String id, String password); | ||
|
||
UserDto getUserInfo(String id); | ||
|
||
} |
17 changes: 10 additions & 7 deletions
17
src/main/java/com/sns/untitled/user/service/impl/UserServiceImpl.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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.sns.untitled.user.service.impl; | ||
|
||
import com.sns.untitled.user.mapper.UserMapper; | ||
import com.sns.untitled.user.dto.UserDto; | ||
import com.sns.untitled.user.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserServiceImpl implements UserService { | ||
|
||
private final UserMapper userMapper; | ||
|
||
@Autowired | ||
public UserServiceImpl(UserMapper userMapper){ | ||
this.userMapper = userMapper; | ||
@Override | ||
public UserDto login(String id, String password) { | ||
UserDto userInfo = userMapper.findUserByIdAndPassword(id, password); | ||
return userInfo; | ||
} | ||
|
||
@Override | ||
public String hello(String name) { | ||
// userMapper.insertName(name); | ||
return "Hello " + name + " Success Insert"; | ||
public UserDto getUserInfo(String id) { | ||
UserDto userInfo = userMapper.findUserById(id); | ||
return userInfo; | ||
} | ||
} |
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
33 changes: 0 additions & 33 deletions
33
src/test/java/com/sns/untitled/user/controller/UserControllerTest.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/test/java/com/sns/untitled/user/service/impl/UserServiceImplTest.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,50 @@ | ||
package com.sns.untitled.user.service.impl; | ||
|
||
import com.sns.untitled.user.mapper.UserMapper; | ||
import com.sns.untitled.user.dto.UserDto; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class UserServiceImplTest { | ||
|
||
@InjectMocks | ||
UserServiceImpl userServiceImpl; | ||
|
||
@Mock | ||
UserMapper userMapper; | ||
|
||
public UserDto userDto() { | ||
UserDto user = new UserDto(); | ||
user.setUserId(1); | ||
user.setId("admin"); | ||
user.setPassword("1234"); | ||
user.setName("관리자"); | ||
user.setEmail("admin@gmail.com"); | ||
user.setProfileImageName("프로필사진1"); | ||
user.setProfileImagePath("이미지경로"); | ||
user.setProfileMessage("상태메세지"); | ||
return user; | ||
} | ||
|
||
@Test | ||
@DisplayName("로그인 성공") | ||
public void successLogin() throws Exception { | ||
//given | ||
UserDto userDto = userDto(); | ||
when(userMapper.findUserByIdAndPassword("admin", "1234")).thenReturn(userDto); | ||
|
||
//when | ||
UserDto result = userServiceImpl.login("admin", "1234"); | ||
|
||
//then | ||
assertEquals(result, userDto); | ||
} | ||
} |