Skip to content

Commit

Permalink
feat: 토큰으로 멘토 자기소개 조회 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
qzzloz authored Dec 20, 2024
1 parent f7f6d5a commit 409fa12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.List;

import com.soongsil.CoffeeChat.dto.*;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,11 +16,6 @@
import org.springframework.web.bind.annotation.RestController;

import com.soongsil.CoffeeChat.controller.handler.ApiResponseGenerator;
import com.soongsil.CoffeeChat.dto.MentorGetListResponseDto;
import com.soongsil.CoffeeChat.dto.MentorGetUpdateDetailDto;
import com.soongsil.CoffeeChat.dto.MentorIntroductionUpdateRequestDto;
import com.soongsil.CoffeeChat.dto.MentorIntroductionUpdateResponseDto;
import com.soongsil.CoffeeChat.dto.MentorUpdateRequestDto;
import com.soongsil.CoffeeChat.dto.Oauth.CustomOAuth2User;
import com.soongsil.CoffeeChat.enums.ClubEnum;
import com.soongsil.CoffeeChat.enums.PartEnum;
Expand Down Expand Up @@ -79,7 +75,7 @@ public ResponseEntity<ApiResponseGenerator<MentorGetUpdateDetailDto>> getMentorI
@PatchMapping("/introductions")
@Operation(summary = "멘토 자기소개 입력")
@ApiResponse(responseCode = "200", description = "자기소개의 수정된 버전을 반환")
public ResponseEntity<ApiResponseGenerator<MentorIntroductionUpdateResponseDto>> updateMentoIntroduction(
public ResponseEntity<ApiResponseGenerator<MentorIntroductionGetUpdateResponseDto>> updateMentoIntroduction(
Authentication authentication,
@RequestBody MentorIntroductionUpdateRequestDto dto
) throws Exception {
Expand All @@ -90,6 +86,21 @@ public ResponseEntity<ApiResponseGenerator<MentorIntroductionUpdateResponseDto>>
);
}

@GetMapping("/introductions")
@Operation(summary = "토큰으로 멘토 자기소개 항목 4개 조회")
@ApiResponse(responseCode = "200", description = "토큰으로 멘토 본인의 자기소개 조회")
public ResponseEntity<ApiResponseGenerator<MentorIntroductionGetUpdateResponseDto>> getMentorIntroduction(
Authentication authentication
) throws Exception{
return ResponseEntity.ok().body(
ApiResponseGenerator.onSuccessOK(
mentorService.getMentorIntroduction(
getUserNameByAuthentication(authentication)
)
)
);
}

@GetMapping("/part")
@Operation(summary = "파트별 멘토 리스트 가져오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Builder
@Getter
public class MentorIntroductionUpdateResponseDto {
public class MentorIntroductionGetUpdateResponseDto {

@JsonProperty("introduction_title")
@NonNull
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/soongsil/CoffeeChat/service/MentorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

import java.util.List;

import com.soongsil.CoffeeChat.dto.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soongsil.CoffeeChat.controller.exception.CustomException;
import com.soongsil.CoffeeChat.dto.MentorGetListResponseDto;
import com.soongsil.CoffeeChat.dto.MentorGetUpdateDetailDto;
import com.soongsil.CoffeeChat.dto.MentorIntroductionUpdateRequestDto;
import com.soongsil.CoffeeChat.dto.MentorIntroductionUpdateResponseDto;
import com.soongsil.CoffeeChat.dto.MentorUpdateRequestDto;
import com.soongsil.CoffeeChat.entity.Introduction;
import com.soongsil.CoffeeChat.entity.Mentor;
import com.soongsil.CoffeeChat.entity.User;
Expand Down Expand Up @@ -87,7 +83,7 @@ public MentorGetUpdateDetailDto updateMentorInfo(String username, MentorUpdateRe
}

@Transactional
public MentorIntroductionUpdateResponseDto updateMentorIntroduction(
public MentorIntroductionGetUpdateResponseDto updateMentorIntroduction(
String userName,
MentorIntroductionUpdateRequestDto dto) {
User findUser = userRepository.findByUsername(userName).orElseThrow(
Expand All @@ -106,11 +102,22 @@ public MentorIntroductionUpdateResponseDto updateMentorIntroduction(

findMentorIntroduction.updateIntroduction(dto);

return MentorIntroductionUpdateResponseDto.builder()
return MentorIntroductionGetUpdateResponseDto.builder()
.title(findMentorIntroduction.getTitle())
.description(findMentorIntroduction.getDescription())
.answer1(findMentorIntroduction.getAnswer1())
.answer2(findMentorIntroduction.getAnswer2())
.build();
}

public MentorIntroductionGetUpdateResponseDto getMentorIntroduction(String username){
User findUser = userRepository.findByUsername(username).orElseThrow();
Introduction introduction = findUser.getMentor().getIntroduction();
return MentorIntroductionGetUpdateResponseDto.builder()
.answer1(introduction.getAnswer1())
.answer2(introduction.getAnswer2())
.title(introduction.getTitle())
.description(introduction.getDescription())
.build();
}
}

0 comments on commit 409fa12

Please sign in to comment.