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

Feature/2 branch → weekly #78

Merged
merged 30 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
816bdf6
fix : testcode 수정
choboss00 Nov 7, 2023
90bc459
fix : user 테스트 코드 수정
choboss00 Nov 7, 2023
946fdeb
feat : swagger jwt 설정 및 이상한 필드 제거
choboss00 Nov 7, 2023
13680be
refactor : mentorpost url 수정
choboss00 Nov 7, 2023
c7e3a6f
refactor : ACTIVE 상태만 나오게끔 변경
choboss00 Nov 7, 2023
0d9de10
refactor : 쿼리 파라미터로 id 값을 받게끔 수정
choboss00 Nov 7, 2023
d70c91e
refactor : mentorpost, contact response 변경
choboss00 Nov 7, 2023
b2cf481
refactor : request 수정
choboss00 Nov 7, 2023
26053c9
refactor : contacts 쿼리 파라미터 id 필드값 수정
choboss00 Nov 7, 2023
1b95b4c
refactor : done response 수정
choboss00 Nov 7, 2023
fc05011
test : 코드수정에 따른 테스트코드 수정
choboss00 Nov 7, 2023
facc74e
fix : findVideo by Id credential delete
sjmjys954646 Nov 8, 2023
b033c34
Merge pull request #75 from choboss00/feature/3-branch-mentoring
sjmjys954646 Nov 8, 2023
868b946
fix : authentification
sjmjys954646 Nov 8, 2023
7c13e24
Merge branch 'feature/2-branch-watching' of https://github.com/sjmjys…
sjmjys954646 Nov 8, 2023
07fbc23
Merge branch 'dev' of https://github.com/Step3-kakao-tech-campus/Team…
sjmjys954646 Nov 8, 2023
080157f
Merge branch 'feature/3-branch-mentoring' of https://github.com/Step3…
sjmjys954646 Nov 8, 2023
7d8a78d
refactor : service refactoring
sjmjys954646 Nov 8, 2023
5d8d769
feat : page on main
sjmjys954646 Nov 8, 2023
c5d2697
feat : testcode, pagination:
sjmjys954646 Nov 8, 2023
66d1f01
fix : teardown
sjmjys954646 Nov 8, 2023
8019783
feat : testcode and fix bug
sjmjys954646 Nov 8, 2023
20347c5
feat : categorytestcode
sjmjys954646 Nov 8, 2023
52e3ed7
fix : exception to @Size
sjmjys954646 Nov 9, 2023
2408a30
fix : isMentor
sjmjys954646 Nov 9, 2023
449a971
test : test fail post Video
sjmjys954646 Nov 9, 2023
063fdfc
feat : validation mentorpost
sjmjys954646 Nov 9, 2023
f7764f9
test : testcode add mentorPOst
sjmjys954646 Nov 9, 2023
57fd5c1
fix : title size 100
sjmjys954646 Nov 9, 2023
1fc6cdd
Merge pull request #76 from sjmjys954646/feature/2-branch-watching
comom87 Nov 9, 2023
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
28 changes: 25 additions & 3 deletions src/main/java/com/example/demo/config/swagger/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.example.demo.config.swagger;

import com.example.demo.config.auth.CustomUserDetails;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

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

@Configuration
public class SwaggerConfig {
private static final String SERVICE_NAME = "Garden";
Expand All @@ -21,13 +25,31 @@ public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(CustomUserDetails.class)
.apiInfo(apiInfo())
.securityContexts(Arrays.asList(securityContext()))
.securitySchemes(Arrays.asList(apiKey()))
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.paths(PathSelectors.regex("/.*"))
.build();
}

private ApiKey apiKey() {
return new ApiKey("JWT", "Authorization", "header");
}

private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}

private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(SERVICE_NAME)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/mentoring/MentorPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MentorPost extends BaseTime {
@ManyToOne(fetch = FetchType.LAZY)
private User writer;

@Column(nullable = false)
@Column(length = 100, nullable = false)
private String title;

@Column(length = 300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,46 @@

public interface MentorPostJPARepostiory extends JpaRepository<MentorPost, Integer> {

@Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'ACTIVE'")
@Query("select m from MentorPost m " +
"where m.writer.id = :writer " +
"and m.state = 'ACTIVE'")
List<MentorPost> findAllByWriter(@Param("writer") int writer);

@Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'DONE'")
@Query("select m from MentorPost m " +
"where m.writer.id = :writer " +
"and m.state = 'DONE'")
List<MentorPost> findAllByWriterDone(@Param("writer") int writer);

@Query("select m from MentorPost m where m.title like :keyword")
@Query("select m from MentorPost m where m.title like :keyword " +
"and m.state = 'ACTIVE'")
Page<MentorPost> findAllByTitleKeyword(@Param("keyword") String keyword, Pageable pageable);

@Query("select m from MentorPost m where m.writer.firstName like :keyword or m.writer.firstName like :keyword")
@Query("select m from MentorPost m " +
"where m.writer.firstName " +
"like :keyword or m.writer.firstName like :keyword " +
"and m.state = 'ACTIVE'")
Page<MentorPost> findAllByWriterKeyword(@Param("keyword") String keyword, Pageable pageable);

@Query("select m from MentorPost m inner join UserInterest ui ON m.writer.id = ui.user.id where ui.interest.category like :keyword")
@Query("select m from MentorPost m " +
"inner join UserInterest ui ON m.writer.id = ui.user.id " +
"where ui.interest.category like :keyword " +
"and m.state = 'ACTIVE'")
Page<MentorPost> findAllByInterestKeyword(@Param("keyword") String keyword, Pageable pageable);

@Query("select m from MentorPost m " +
"where m.state = 'ACTIVE'")
Page<MentorPost> findAll(Pageable pageable);

Optional<MentorPost> findById(int id);

@Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'ACTIVE'")
@Query("select count(*) from MentorPost m " +
"where m.writer.id = :userId " +
"and m.state = 'ACTIVE'")
int countContactByMentorId(int userId);

@Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'DONE'")
@Query("select count(*) from MentorPost m " +
"where m.writer.id = :userId " +
"and m.state = 'DONE'")
int countDoneByMentorId(int userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

public class MentorPostRequest {

@Getter
@Setter
public static class CreateDTO {
public static class CreateMentorPostDTO {
@NotNull
@Size(max = 100, message = "100자를 초과하면 안됩니다.")
private String title;

@Size(max = 300, message = "300자를 초과하면 안됩니다.")
private String content;
}

Expand Down
72 changes: 43 additions & 29 deletions src/main/java/com/example/demo/mentoring/MentorPostResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public static class MentorPostAllDTO {
private int postId;
private String title;
private String content;
private MentorPostStateEnum mentorPostStateEnum;
private MentorPostStateEnum postState;
private WriterDTO writerDTO;

public MentorPostAllDTO(MentorPost mentorPost, List<UserInterest> userInterests) {
this.postId = mentorPost.getId();
this.title = mentorPost.getTitle();
this.content = mentorPost.getContent();
this.mentorPostStateEnum = mentorPost.getState();
this.postState = mentorPost.getState();
WriterDTO writerDTO = new MentorPostAllDTO.WriterDTO(mentorPost.getWriter(), userInterests);
this.writerDTO = writerDTO;
}
Expand Down Expand Up @@ -79,31 +79,32 @@ public static class MentorPostDTO {
private int postId;
private String title;
private String content;
private MentorPostStateEnum postState;
private WriterDTO writerDTO;
private MentorPostStateEnum mentorPostStateEnum;
private List<MenteeDTO> menteeDTOList;
private List<ConnectionDTO> connections;

public MentorPostDTO(MentorPost mentorPost, List<UserInterest> mentorFavorites, List<NotConnectedRegisterUser> mentees, List<UserInterest> menteeInterest) {
this.postId = mentorPost.getId();
this.title = mentorPost.getTitle();
this.content = mentorPost.getContent();
this.mentorPostStateEnum = mentorPost.getState();
this.postState = mentorPost.getState();
MentorPostDTO.WriterDTO writerDTO = new MentorPostDTO.WriterDTO(mentorPost.getWriter(), mentorFavorites);
this.writerDTO = writerDTO;
List<MentorPostDTO.MenteeDTO> menteeDTOList = mentees.stream()
List<ConnectionDTO> connectionDTOList = mentees.stream()
.map(mentee -> {
List<UserInterest> eachMenteeFavorite = menteeInterest.stream().filter(
userInterest -> mentee.getMenteeUser().getId() == userInterest.getUser().getId()
).collect(Collectors.toList());

MentorPostDTO.MenteeDTO menteeDTO = new MentorPostDTO.MenteeDTO(mentee, eachMenteeFavorite);
return menteeDTO;
ConnectionDTO connectionDTO = new ConnectionDTO(mentee, eachMenteeFavorite);
return connectionDTO;
})
.collect(Collectors.toList());
this.menteeDTOList = menteeDTOList;
this.connections = connectionDTOList;
}

@Getter @Setter
@Getter
@Setter
public static class WriterDTO {
private int mentorId;
private String profileImage;
Expand All @@ -124,28 +125,41 @@ public WriterDTO(User user, List<UserInterest> userInterests) {
}
}

@Getter @Setter
public static class MenteeDTO{
private int menteeId;
private String profileImage;
private String name;
private String country;
private Role role;
private LocalDate birthDate;
@Getter
@Setter
public static class ConnectionDTO {
private int connectionId;
private ContactStateEnum state;
private List<String> interests;
private MenteeDTO mentee;

public MenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List<UserInterest> userInterests) {
this.menteeId = notConnectedRegisterUser.getId();
this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage();
this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName();
this.country = notConnectedRegisterUser.getMenteeUser().getCountry();
this.role = notConnectedRegisterUser.getMenteeUser().getRole();
this.birthDate = notConnectedRegisterUser.getMenteeUser().getBirthDate();
public ConnectionDTO(NotConnectedRegisterUser notConnectedRegisterUser, List<UserInterest> userInterests) {
this.connectionId = notConnectedRegisterUser.getId();
this.state = notConnectedRegisterUser.getState();
this.interests = userInterests.stream()
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
this.mentee = new MenteeDTO(notConnectedRegisterUser.getMenteeUser(), userInterests);
}

@Getter
@Setter
public static class MenteeDTO {
private int menteeId;
private String profileImage;
private String name;
private String country;
private Role role;
private LocalDate birthDate;
private List<String> interests;

public MenteeDTO(User menteeUser, List<UserInterest> userInterests) {
this.menteeId = menteeUser.getId();
this.profileImage = menteeUser.getProfileImage();
this.name = menteeUser.getFirstName() + " " + menteeUser.getLastName();
this.country = menteeUser.getCountry();
this.role = menteeUser.getRole();
this.birthDate = menteeUser.getBirthDate();
this.interests = userInterests.stream()
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
public class MentorPostRestController {
private final MentorPostService mentorPostService;

@PostMapping(value = "/mentorings/post")
@PostMapping(value = "/mentorings")
@Operation(summary = "mentorpost 생성")
public ResponseEntity<?> createMentorPost(@RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<?> createMentorPost(@RequestBody @Valid MentorPostRequest.CreateMentorPostDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.createMentorPost(requestDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

@GetMapping("/mentorings/post")
@GetMapping("/mentorings")
@Operation(summary = "mentorpost 가져오기", description = "category, search로 필터링, pagination 적용")
public ResponseEntity<?> getMentorPost(
@RequestParam(value = "category", defaultValue = "NULL") String category,
Expand All @@ -36,28 +36,28 @@ public ResponseEntity<?> getMentorPost(
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTOs));
}

@GetMapping("/mentorings/post/{id}")
@GetMapping("/mentorings/{id}")
@Operation(summary = "mentorpost 개별 페이지 불러오기")
public ResponseEntity<?> getMentorPostId(@PathVariable int id) {
MentorPostResponse.MentorPostDTO responseDTO = mentorPostService.findMentorPost(id);
return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO));
}

@PutMapping(value = "/mentorings/post/{id}")
@PutMapping(value = "/mentorings/{id}")
@Operation(summary = "mentorpost 수정 요청")
public ResponseEntity<?> updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<?> updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateMentorPostDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.updateMentorPost(requestDTO, id, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent());
}

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

@PatchMapping(value = "/mentorings/post/{id}/done")
@PatchMapping(value = "/mentorings/{id}/done")
@Operation(summary = "mentorpost 만료 요청")
public ResponseEntity<?> changeMentorPostStatus(@PathVariable int id,@RequestBody @Valid MentorPostRequest.StateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.changeMentorPostStatus(requestDTO, id, userDetails.getUser());
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/com/example/demo/mentoring/MentorPostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,10 @@ public class MentorPostService {

//mentorPost생성
@Transactional
public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) {
if ( writer.getRole() == Role.MENTEE ) {
throw new Exception401("해당 사용자는 멘티입니다.");
}

//글자수 확인
if(createDTO.getContent().length() > 300){
throw new Exception404("글자수가 300자를 넘어갑니다.");
}
public void createMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorPostDTO, User writer) {
isMentor(writer);

MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent());
MentorPost mentorPost = new MentorPost( writer, createMentorPostDTO.getTitle(), createMentorPostDTO.getContent());

try {
mentorPostJPARepository.save(mentorPost);
Expand Down Expand Up @@ -87,26 +80,20 @@ public MentorPostResponse.MentorPostDTO findMentorPost(int id){
return mentorPostDTO;
}
@Transactional
public void updateMentorPost(MentorPostRequest.CreateDTO createDTO, int id, User writer) {
public void updateMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorPostDTO, int id, User writer) {
isMentor(writer);

MentorPost mentorPost = mentorPostJPARepository.findById(id).
orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다."));

//글자수 확인
if(createDTO.getContent().length() > 300){
throw new Exception404("글자수가 300자를 넘어갑니다.");
}

try {
mentorPost.update(createDTO.getTitle(), createDTO.getContent());
mentorPost.update(createMentorPostDTO.getTitle(), createMentorPostDTO.getContent());
} catch (Exception e) {
throw new Exception500("unknown server error");
}
}

public void deleteMentorPost(int id, User writer) {

isMentor(writer);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static class ContactRefuseDTO {
@Getter @Setter @NoArgsConstructor
public static class RefuseMenteeDTO {
@NotNull
private int menteeId;
public RefuseMenteeDTO(int menteeId) {
this.menteeId = menteeId;
private int connectionId;
public RefuseMenteeDTO(int connectionId) {
this.connectionId = connectionId;
}
}
}
Expand All @@ -39,9 +39,9 @@ public static class ContactAcceptDTO {
@Getter @Setter @NoArgsConstructor
public static class AcceptMenteeDTO {
@NotNull
private int menteeId;
public AcceptMenteeDTO(int menteeId) {
this.menteeId = menteeId;
private int connectionId;
public AcceptMenteeDTO(int connectionId) {
this.connectionId = connectionId;
}
}
}
Expand Down
Loading
Loading