This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
application.properties 설정파일 추가 #4
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e76cf3
Add application.properties for Database, MyBatis, Lombok, Web index page
HwangWonGyu 58af41b
Add user controller, service, mapper, dto for CRUD
HwangWonGyu 3209ab2
Remove all comment of property for readability
HwangWonGyu 660d7bc
Merge branch 'feature/user-crud' into develop
HwangWonGyu 5f3d350
Encrypt database account information
HwangWonGyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/hwangwongyu/news/config/DateTimeConfig.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,63 @@ | ||
package com.hwangwongyu.news.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.format.Formatter; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Locale; | ||
|
||
@Configuration | ||
public class DateTimeConfig { | ||
|
||
@Bean | ||
public Formatter<LocalDate> localDateFormatter() { | ||
return new Formatter<LocalDate>() { | ||
@Override | ||
public LocalDate parse(String text, Locale locale) { | ||
return LocalDate.parse(text, DateTimeFormatter.ofPattern("yyyyMMdd", locale)); | ||
} | ||
|
||
@Override | ||
public String print(LocalDate object, Locale locale) { | ||
return DateTimeFormatter.ISO_DATE.format(object); | ||
} | ||
}; | ||
} | ||
|
||
|
||
@Bean | ||
public Formatter<LocalDateTime> localDateTimeFormatter() { | ||
return new Formatter<LocalDateTime>() { | ||
@Override | ||
public LocalDateTime parse(String text, Locale locale) { | ||
return LocalDateTime.parse(text, DateTimeFormatter.ofPattern("yyyyMMddHHmmss", locale)); | ||
} | ||
|
||
@Override | ||
public String print(LocalDateTime object, Locale locale) { | ||
return DateTimeFormatter.ISO_DATE_TIME.format(object); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public Formatter<LocalTime> DateFormatter() { | ||
return new Formatter<LocalTime>() { | ||
@Override | ||
public LocalTime parse(String text, Locale locale) throws ParseException { | ||
return LocalTime.parse(text, DateTimeFormatter.ofPattern("HHmmss", locale)); | ||
} | ||
|
||
@Override | ||
public String print(LocalTime object, Locale locale) { | ||
return new SimpleDateFormat("HH:mm:ss").format(object); | ||
} | ||
}; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/hwangwongyu/news/config/StringToConverter.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,22 @@ | ||
package com.hwangwongyu.news.config; | ||
|
||
import com.hwangwongyu.news.user.UserDTO; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.convert.converter.Converter; | ||
|
||
@Configuration | ||
public class StringToConverter { | ||
|
||
@Bean | ||
public Converter<String, UserDTO.Sex> stringToSexConverter() { | ||
return new Converter<String, UserDTO.Sex>() | ||
{ | ||
@Override | ||
public UserDTO.Sex convert(String source) { | ||
return UserDTO.Sex.valueOf(source.toUpperCase()); | ||
} | ||
}; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/hwangwongyu/news/encrypt/JasyptConfig.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,21 @@ | ||
package com.hwangwongyu.news.encrypt; | ||
|
||
import org.jasypt.encryption.StringEncryptor; | ||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; | ||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class JasyptConfig { | ||
|
||
@Bean("jasyptStringEncryptor") | ||
public StringEncryptor stringEncryptor() { | ||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); | ||
SimpleStringPBEConfig config = new SimpleStringPBEConfig(); | ||
config.setPassword("wgh"); | ||
config.setPoolSize(1); | ||
encryptor.setConfig(config); | ||
return encryptor; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/hwangwongyu/news/user/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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.hwangwongyu.news.user; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
public UserController(UserService userService) | ||
{ | ||
this.userService = userService; | ||
} | ||
|
||
@Value("${spring.webservice.index}") | ||
private String indexURL; | ||
|
||
|
||
@GetMapping("/allusers") | ||
public List<UserDTO> allUsers() { | ||
return userService.allUsers(); | ||
} | ||
|
||
@PostMapping("/user") | ||
public String addUser(UserDTO user) | ||
{ | ||
userService.addUser(user); | ||
return "redirect:" + indexURL; | ||
} | ||
|
||
@PutMapping("/user") | ||
public String updateUser(UserDTO user) { | ||
userService.updateUser(user); | ||
return "redirect:" + indexURL; | ||
} | ||
|
||
@DeleteMapping("/user") | ||
public String deleteUser(String loginId) | ||
{ | ||
userService.deleteUser(loginId); | ||
return "redirect:" + indexURL; | ||
} | ||
|
||
@GetMapping("/user/{id}") | ||
public UserDTO findUserById(@PathVariable long id) | ||
{ | ||
UserDTO user = userService.findUserById(id); | ||
if(user != null) | ||
return user; | ||
else | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
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.hwangwongyu.news.user; | ||
|
||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Setter | ||
@Getter | ||
@ToString | ||
@NoArgsConstructor | ||
public class UserDTO { | ||
|
||
@Getter | ||
@ToString | ||
public enum Sex { | ||
MALE, | ||
FEMALE | ||
} | ||
|
||
String loginId; | ||
String name; | ||
LocalDate birthDate; | ||
Sex sex; | ||
String password; | ||
String nickname; | ||
String phoneNumber; | ||
|
||
@Builder | ||
private UserDTO(String loginId, String name, LocalDate birthDate, Sex sex, String password, String nickname, String phoneNumber) { | ||
this.loginId = loginId; | ||
this.name = name; | ||
this.birthDate = birthDate; | ||
this.sex = sex; | ||
this.password = password; | ||
this.nickname = nickname; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.hwangwongyu.news.user; | ||
|
||
import org.apache.ibatis.annotations.*; | ||
|
||
import java.util.List; | ||
|
||
@Mapper | ||
public interface UserMapper { | ||
|
||
List<UserDTO> allUsers(); | ||
|
||
Integer addUser(UserDTO user); | ||
|
||
Integer updateUser(UserDTO user); | ||
|
||
Integer deleteUser(String loginId); | ||
|
||
UserDTO findUserById(long 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.hwangwongyu.news.user; | ||
|
||
import java.util.List; | ||
|
||
public interface UserService { | ||
|
||
List<UserDTO> allUsers(); | ||
|
||
Integer addUser(UserDTO user); | ||
|
||
Integer updateUser(UserDTO user); | ||
|
||
Integer deleteUser(String loginId); | ||
|
||
UserDTO findUserById(long id); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/hwangwongyu/news/user/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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.hwangwongyu.news.user; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class UserServiceImpl implements UserService { | ||
|
||
private final UserMapper userMapper; | ||
|
||
UserServiceImpl(UserMapper userMapper) | ||
{ | ||
this.userMapper = userMapper; | ||
} | ||
|
||
@Override | ||
public List<UserDTO> allUsers() { | ||
return userMapper.allUsers(); | ||
} | ||
|
||
@Override | ||
public Integer addUser(UserDTO user) | ||
{ | ||
return userMapper.addUser(user); | ||
} | ||
|
||
@Override | ||
public Integer updateUser(UserDTO user) { | ||
return userMapper.updateUser(user); | ||
} | ||
|
||
@Override | ||
public Integer deleteUser(String loginId) { | ||
return userMapper.deleteUser(loginId); | ||
} | ||
|
||
@Override | ||
public UserDTO findUserById(long id) { | ||
return userMapper.findUserById(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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
##Database | ||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/news?serverTimezone=UTC | ||
spring.datasource.username=ENC(pqDIZXI0lbgUqqM7Wi20yQ==) | ||
spring.datasource.password=ENC(QbpvVIGq2C2+Mls7PcWnJx5DpratEzGx) | ||
|
||
##MyBatis | ||
mybatis.type-aliases-package=com.hwangwongyu.news.user | ||
mybatis.mapper-locations=classpath:mappers/*.xml | ||
|
||
##Lombok | ||
lombok.allArgsConstructor.flagUsage=error | ||
lombok.experimental.flagUsage=error | ||
|
||
##Web Index | ||
spring.webservice.index= / | ||
|
||
##Jasypt | ||
jasypt.encryptor.bean=jasyptStringEncryptor | ||
jasypt.encryptor.algorithm=PBEWithMD5AndDES | ||
jasypt.encryptor.property.prefix=ENC( | ||
jasypt.encryptor.property.suffix=) | ||
jasypt.encryptor.poolSize=1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# @AllArgsConstructor 사용 지양~
이런 주석은 굳이 필요할까?..?
팀단위 개발시에 가독성만 해칠거같은데 한번 생각해봐.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
application.properties에는 '프로퍼티', git commit log에는 '프로퍼티에 대한 설명' 이라는 역할을 나눠서
각각 책임에 맞는 정보를 저장해서 가독성 높일 수 있다고 생각해봤다
문제 되는 주석 제거하고 commit log로 옮겨볼게
괜찮은 생각이야?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거는 오히려 관심사 분리가 아니고
같은 관심사인데 다른 class로 분리하는 느낌이라 한곳에서 다 관리하는게 좋아보여!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
응~ 주석 복구하고
주석 내용, 관리방법 재검토해서 반영할게