Skip to content

Commit

Permalink
Merge pull request #66 from cosmos-1885/feature/1-branch-account
Browse files Browse the repository at this point in the history
Refactor: Feedback 반영
  • Loading branch information
choboss00 authored Nov 6, 2023
2 parents 33f2ae1 + c996cd2 commit efbd65b
Show file tree
Hide file tree
Showing 32 changed files with 837 additions and 472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.demo.config.utils.ApiResponseBuilder;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
Expand All @@ -11,12 +12,7 @@ public class Exception400 extends RuntimeException {

public Exception400(Map<String, String> errors, String message) {
super(message);
this.errors = errors;
}

public Exception400(String message) {
super(message);
errors = null;
this.errors = (errors != null) ? errors : null;
}

public ApiResponseBuilder.ApiResponse<?> body(){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/interest/Interest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "interests")
public class Interest {
public class Interest extends BaseTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.example.demo.mentoring.contact.ContactStateEnum;
import com.example.demo.mentoring.contact.NotConnectedRegisterUser;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ResponseEntity<?> getMentorPost(
category = MentorPostCategoryEnum.NULL;

List<MentorPostResponse.MentorPostAllDTO> responseDTOs = mentorPostService.findAllMentorPost(category, keyword, page);
return ResponseEntity.ok(ApiUtils.success(responseDTOs));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTOs));
}

@GetMapping("/mentorings/post/{id}")
Expand All @@ -45,19 +45,19 @@ public ResponseEntity<?> getMentorPostId(@PathVariable int id) {
@PutMapping(value = "/mentorings/post/{id}")
public ResponseEntity<?> updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.updateMentorPost(requestDTO, id, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@DeleteMapping(value = "/mentorings/post/{id}")
public ResponseEntity<?> deleteMentorPost(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.deleteMentorPost(id, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@PatchMapping(value = "/mentorings/post/{id}/done")
public ResponseEntity<?> changeMentorPostStatus(@PathVariable int id,@RequestBody @Valid MentorPostRequest.StateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.changeMentorPostStatus(requestDTO, id, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.example.demo.config.errors.exception.Exception404;
import com.example.demo.mentoring.contact.ContactJPARepository;
import com.example.demo.mentoring.contact.NotConnectedRegisterUser;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.demo.mentoring.contact;

import com.example.demo.mentoring.MentorPost;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example.demo.mentoring.contact;

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiUtils;
import com.example.demo.mentoring.done.DoneService;
import com.example.demo.user.Role;
import com.example.demo.config.utils.ApiResponseBuilder;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -25,10 +23,10 @@ public class ContactRestController {
public ResponseEntity<?> findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) {
if ( userDetails.getUser().getRole() == Role.MENTEE ) {
List<ContactResponse.ContactDashBoardMenteeDTO> responseDTO = contactService.findAllByMentee(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}
List<ContactResponse.ContactDashboardMentorDTO> responseDTO = contactService.findAllByMentor(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}


Expand All @@ -42,43 +40,43 @@ public ResponseEntity<?> postCounts(@AuthenticationPrincipal CustomUserDetails u

if ( role == Role.MENTEE ) {
ContactResponse.PostCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

ContactResponse.PostCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

@PostMapping(value = "/contacts/accept")
@Operation(summary = "멘토링 신청 수락", description = "멘토링 신청을 수락한다.")
public ResponseEntity<?> acceptContact(@RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 수락 API 로직 만들기
contactService.acceptContact(contactAcceptDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@PatchMapping(value = "/contacts/refuse")
@Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.")
public ResponseEntity<?> refuseContact(@RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 거절 API 로직 만들기
contactService.refuseContact(contactRefuseDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@PostMapping(value = "/contacts")
@Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.")
public ResponseEntity<?> createContact(@RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 API 로직 만들기
contactService.createContact(contactCreateDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@DeleteMapping(value = "/contacts")
@Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.")
public ResponseEntity<?> deleteContact(@RequestHeader("contactId") List<Integer> contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 취소 API 로직 만들기
contactService.deleteContact(contactId, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.example.demo.mentoring.MentorPostJPARepostiory;
import com.example.demo.mentoring.done.ConnectedUser;
import com.example.demo.mentoring.done.DoneJPARepository;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.demo.mentoring.done;

import com.example.demo.mentoring.MentorPost;
import com.example.demo.mentoring.contact.ContactResponse;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.example.demo.mentoring.done;

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiUtils;
import com.example.demo.user.Role;
import com.example.demo.config.utils.ApiResponseBuilder;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -23,9 +22,9 @@ public class DoneRestController {
public ResponseEntity<?> findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) {
if (userDetails.getUser().getRole().equals(Role.MENTEE)) {
List<DoneResponse.DoneDashBoardDTO> responseDTO = doneService.findByMentee(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}
List<DoneResponse.DoneDashBoardDTO> responseDTO = doneService.findByMentor(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}
}
7 changes: 0 additions & 7 deletions src/main/java/com/example/demo/refreshToken/TokenService.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package com.example.demo.refreshToken;

import com.example.demo.config.errors.exception.Exception400;
import com.example.demo.config.errors.exception.Exception401;
import com.example.demo.config.jwt.JWTTokenProvider;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Transactional
@RequiredArgsConstructor
@Service
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/example/demo/user/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum Role {
ADMIN("Admin"),
MENTOR("Mentor"),
MENTEE("Mentee");
ADMIN("ADMIN", "ADMIN"),
MENTOR("MENTOR", "MENTOR"),
MENTEE("MENTEE", "MENTEE");

private final String desc;
private final String value;

private final String role;
private static final Map<String, Role> description = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(Role::getValue, Function.identity())));

@JsonCreator
public static Role parsing(String value) {
for (Role role: Role.values()) {
if (role.getRole().equals(value)) {
return role;
}
}
return null;
public static Role findOf(String findValue) {
return description.get(findValue);
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/example/demo/user/RoleConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.demo.user;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.persistence.AttributeConverter;

@RequiredArgsConstructor
@Component
public class RoleConverter implements AttributeConverter<Role, String> {
@Override
public String convertToDatabaseColumn(Role attribute) {
return attribute.getValue();
}

@Override
public Role convertToEntityAttribute(String dbData) {
return Role.findOf(dbData);
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/example/demo/user/UserService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.demo.user;

import com.example.demo.config.errors.exception.Exception400;
import com.example.demo.config.errors.exception.Exception404;
import com.example.demo.interest.Interest;
import com.example.demo.interest.InterestJPARepository;
import com.example.demo.config.errors.exception.Exception400;
import com.example.demo.config.jwt.JWTTokenProvider;
import com.example.demo.refreshToken.RefreshToken;
import com.example.demo.refreshToken.RefreshTokenJPARepository;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class UserService {
public void emailCheck(UserRequest.EmailCheckDTO requestDTO) {
Optional<User> optionalUser = userJPARepository.findByEmail(requestDTO.getEmail());
if (optionalUser.isPresent()) {
throw new Exception400("동일한 이메일이 존재합니다.");
throw new Exception400(null, "동일한 이메일이 존재합니다.");
}
}

Expand All @@ -56,7 +56,7 @@ public void signup(UserRequest.SignUpDTO requestDTO) {
List<String> categoryList = requestDTO.getCategoryList();
for (String category : categoryList) {
Interest interest = interestJPARepository.findByCategory(category)
.orElseThrow(() -> new Exception400("해당 관심사가 존재하지 않습니다."));
.orElseThrow(() -> new Exception400(null, "해당 관심사가 존재하지 않습니다."));
UserInterest userInterest = UserInterest.builder().user(user).interest(interest).build();
userInterestList.add(userInterest);
}
Expand All @@ -66,10 +66,10 @@ public void signup(UserRequest.SignUpDTO requestDTO) {
@Transactional
public UserResponse.LoginDTO login(UserRequest.LoginDTO requestDTO) {
User user = userJPARepository.findByEmail(requestDTO.getEmail())
.orElseThrow(() -> new Exception400("잘못된 이메일입니다."));
.orElseThrow(() -> new Exception400(null, "잘못된 이메일입니다."));

if (!passwordEncoder.matches(requestDTO.getPassword(), user.getPassword())) {
throw new Exception400("잘못된 비밀번호입니다.");
throw new Exception400(null, "잘못된 비밀번호입니다.");
}

TokenResponse.TokenDTO token = JWTTokenProvider.createToken(user);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/example/demo/video/Subtitle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "subtitle_tb")
@Where(clause = "deleted_at IS NULL")
@SQLDelete(sql = "UPDATE subtitles SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?")
@Table(name = "subtitles")
public class Subtitle extends BaseTime {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/example/demo/video/SubtitleJPARepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.demo.video;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface SubtitleJPARepository extends JpaRepository<Subtitle, Integer> {
@Query("select m from Subtitle m where m.video.id = :video")
List<Subtitle> findSubtitleByVideoId(@Param("video") int video);
}
Loading

0 comments on commit efbd65b

Please sign in to comment.