Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE][:wrench: FIX]: 코드 컨벤션 관련 수정 [#112 참조] #113

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ repositories {
}

dependencies {
// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation 'com.google.code.findbugs:jsr305:3.0.2'
// warning error 해결 방안 https://simple-ing.tistory.com/48 참조
// https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
// java 11 버전 이상은 에러 발생하기 때문에 추가
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '4.0.0'
Expand Down
6 changes: 3 additions & 3 deletions src/main/frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Home() {
<Box>
<DynamicSection
main
title='UPGRADE YOUR DAY'
title='당신의 이야기를 들려주세요 😊'
titleSize='l'
img='https://cdn.pixabay.com/photo/2020/05/24/11/14/sea-5213746_1280.jpg'
slot={
Expand All @@ -107,7 +107,7 @@ function Home() {
)}
</Typography>
</Box>
{!cookies.token && (
{/* {!cookies.token && (
<Button
component={Link}
to='/auth/signup'
Expand All @@ -117,7 +117,7 @@ function Home() {
회원 가입
</Button>
)}
<Typography variant='body2'>당신의 이야기를 들려주세요.</Typography>
<Typography variant='body2'>당신의 이야기를 들려주세요.</Typography> */}
</Stack>
}
/>
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/narang/web/config/SecurityConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import javax.servlet.Filter;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@SuppressWarnings({"WebSecurityConfigurerAdapter"})
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder encoder() {
Expand All @@ -44,15 +43,6 @@ public CustomAuthenticationProcessingFilter customAuthenticationProcessingFilter
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
// .antMatchers("/favicon.ico",
// "/api/user/**",
// "/api/diaries",
// "/api/diary/**",
// "/api/likes",
// "/api/like/**",
// "/api/emotions",
// "/api/emotion/**",
// "/api/products");
}

@Override
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/narang/web/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
Expand All @@ -39,9 +41,22 @@ public class Comment {
@Field
private String _class;

public Comment replace(Comment compare) {
this.content = compare.getContent();
this.mention = compare.getMention();
public Comment replaceIfNotNull(Comment compare) {
List<java.lang.reflect.Field> fields = Arrays.asList(this.getClass().getDeclaredFields());
fields.forEach(field -> {
try {
field.setAccessible(true);
Object compareField = field.get(compare);
Object thisField = field.get(this);
if (field.getName() == "userAuth") {
field.set(this, "USER");
} else {
field.set(this, compareField != null ? compareField : thisField);
}
} catch (IllegalAccessException e) {
System.out.println("The value is null [" + field.getName() + "]");
}
});
return this;
}
}
22 changes: 18 additions & 4 deletions src/main/java/com/narang/web/entity/Diary.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
Expand Down Expand Up @@ -43,10 +45,22 @@ public class Diary {
@Field
private String _class;

public Diary replace(Diary compare) {
this.title = compare.getTitle();
this.content = compare.getContent();
this.isShare = compare.getIsShare();
public Diary replaceIfNotNull(Diary compare) {
List<java.lang.reflect.Field> fields = Arrays.asList(this.getClass().getDeclaredFields());
fields.forEach(field -> {
try {
field.setAccessible(true);
Object compareField = field.get(compare);
Object thisField = field.get(this);
if (field.getName() == "userAuth") {
field.set(this, "USER");
} else {
field.set(this, compareField != null ? compareField : thisField);
}
} catch (IllegalAccessException e) {
System.out.println("The value is null [" + field.getName() + "]");
}
});
return this;
}
}
23 changes: 21 additions & 2 deletions src/main/java/com/narang/web/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Collection;
import java.util.Date;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Stream;

@Data
@NoArgsConstructor
Expand Down Expand Up @@ -87,4 +88,22 @@ public boolean isEnabled() {
return true;
}

public User replaceIfNotNull(User compare) {
List<java.lang.reflect.Field> fields = Arrays.asList(this.getClass().getDeclaredFields());
fields.forEach(field -> {
try {
field.setAccessible(true);
Object compareField = field.get(compare);
Object thisField = field.get(this);
if (field.getName() == "userAuth") {
field.set(this, "USER");
} else {
field.set(this, compareField != null ? compareField : thisField);
}
} catch (IllegalAccessException e) {
System.out.println("The value is null [" + field.getName() + "]");
}
});
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
public interface CommentRepositoryCustom {
public List<Comment> findByDid(String did);

public Boolean updateToPart(Comment comment);
public Boolean update(Comment comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public List<Comment> findByDid(String did) {
}

@Override
public Boolean updateToPart(Comment comment) {
public Boolean update(Comment comment) {
Comment foundComment = commentTemplate.findById(comment.getId(), Comment.class);
foundComment.replace(comment);
foundComment.replaceIfNotNull(comment);
commentTemplate.save(foundComment, "comment");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.narang.web.entity.Diary;

public interface DiaryRepositoryCustom {
public Boolean updateToPart(Diary diary);
public Boolean update(Diary diary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class DiaryRepositoryCustomImpl implements DiaryRepositoryCustom {
}

@Override
public Boolean updateToPart(Diary diary) {
public Boolean update(Diary diary) {
Diary foundDiary = diaryTemplate.findById(diary.getId(), Diary.class);
foundDiary.replace(diary);
foundDiary.replaceIfNotNull(diary);
diaryTemplate.save(foundDiary, "diary");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface EmotionRepositoryCustom {

public Optional<Emotion> findByDid(String did);

public Boolean updateToPart(Emotion emotion);

public Boolean deleteByDid(String did);

public Boolean deleteByUid(String uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ public Optional<Emotion> findByDid(String did) {
return Optional.of(foundEmotion);
}

@Override
public Boolean updateToPart(Emotion emotion) {
Criteria cr = new Criteria("did").is(emotion.getDid());
Query q = new Query(cr);
emotionTemplate.remove(q, "emotion");
emotionTemplate.insert(emotion, "emotion");
return true;
}

@Override
public Boolean deleteByDid(String did) {
Criteria cr = new Criteria("did").is(did);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.narang.web.repository;

import com.narang.web.entity.Comment;
import com.narang.web.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -10,4 +11,6 @@ public interface UserRepositoryCustom {
public Optional<User> findByNickName(String nickName);

public Optional<User> findByEmail(String email);

public Boolean update(User user);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.narang.web.repository;

import com.narang.web.entity.Comment;
import com.narang.web.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -11,14 +12,14 @@

public class UserRepositoryCustomImpl implements UserRepositoryCustom {
@Autowired
MongoTemplate mongo;
MongoTemplate userTemplate;

@Override
public Optional<User> findByNickName(String nickName) {
Criteria cr = new Criteria("nickName");
cr.is(nickName);
Query q = new Query(cr);
return Optional.of(mongo.findOne(q, User.class));
return Optional.of(userTemplate.findOne(q, User.class));
}

@Override
Expand All @@ -27,6 +28,13 @@ public Optional<User> findByEmail(String email) {
cr.is(email);
Query q = new Query(cr);

return Optional.of(mongo.findOne(q, User.class));
return Optional.of(userTemplate.findOne(q, User.class));
}

public Boolean update(User user) {
User foundUser = userTemplate.findById(user.getId(), User.class);
foundUser.replaceIfNotNull(user);
userTemplate.save(foundUser, "user");
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public String insert(Comment comment) {

@PutMapping("/comment")
public Boolean update(Comment comment) {
commentService.updateToPart(comment);
return true;
return commentService.update(comment);
}

@DeleteMapping("/comment/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public String insert(Diary diary) {

@PutMapping("/diary")
public Boolean update(Diary diary) {
diaryService.update(diary);
return true;
return diaryService.update(diary);
}

@DeleteMapping("/diary/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String findAll() throws JsonProcessingException {
@GetMapping("/user/{id}")
public String findById(@PathVariable("id") String id) throws JsonProcessingException {
System.out.println(id);
System.out.println(userService.findById(id));
User foundUser = userService.findById(id);
return mapper(userService.findById(id));
}

Expand Down Expand Up @@ -105,8 +105,7 @@ public Map<String, Object> fileupload(MultipartFile multipartFile, String id, St

@PutMapping("/user")
public Boolean update(User user) {
userService.update(user);
return true;
return userService.update(user);
}

@DeleteMapping("/user/{id}")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/narang/web/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public String insert(Comment comment) {
return newComment.getId();
}

public Boolean updateToPart(Comment comment) {
return commentRepository.updateToPart(comment);
public Boolean update(Comment comment) {
return commentRepository.update(comment);
}

public Boolean deleteById(String id) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/narang/web/service/DiaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String insert(Diary diary) {
}

public Boolean update(Diary diary){
return diaryRepository.updateToPart(diary);
return diaryRepository.update(diary);
}

public Boolean deleteById(String id) {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/narang/web/service/EmotionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public String insert(Emotion emotion) {
return newEmotion.getId();
}

public Boolean update(Emotion emotion) {
emotionRepository.updateToPart(emotion);
return true;
}

public Boolean delete(String id){
emotionRepository.deleteById(id);
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/narang/web/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public Boolean checkPassword(String password, String id) {
}
}

public User update(User user) {
return userRepository.save(user);
public Boolean update(User user) {
return userRepository.update(user);
}

public Boolean deleteById(String id) {
Expand Down