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

[FEAT] 마이페이지 조회 API #63

Merged
merged 2 commits into from
Jul 16, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package sopt.univoice.domain.mypage.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sopt.univoice.domain.mypage.dto.response.GetMypageReponseDto;
import sopt.univoice.domain.mypage.service.MypageService;
import sopt.univoice.domain.notice.dto.NoticeSaveDTO;
import sopt.univoice.infra.common.dto.SuccessMessage;
import sopt.univoice.infra.common.dto.SuccessStatusResponse;

import java.util.List;

@RestController
@RequestMapping("/api/v1/mypage")
@RequiredArgsConstructor
public class MypageController {

private final MypageService mypageService;

@GetMapping
public ResponseEntity<SuccessStatusResponse<GetMypageReponseDto>> getMypage() {
return ResponseEntity.status(HttpStatus.OK)
.body(SuccessStatusResponse.of(SuccessMessage.GET_MYPAGE_SUCCESS, mypageService.getMypage()));
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sopt.univoice.domain.mypage.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class GetMypageReponseDto {
private Long id;
private String name;
private String collegeDepartment;
private String department;
private String admissionNumber;
private String university;
private String universityLogoImage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package sopt.univoice.domain.mypage.repository;

public class MypageRepository {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sopt.univoice.domain.mypage.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import sopt.univoice.domain.auth.PrincipalHandler;
import sopt.univoice.domain.auth.repository.AuthRepository;
import sopt.univoice.domain.mypage.dto.response.GetMypageReponseDto;
import sopt.univoice.domain.user.entity.Member;

@Service
@RequiredArgsConstructor
public class MypageService {

private final AuthRepository authRepository;
private final PrincipalHandler principalHandler;

public GetMypageReponseDto getMypage() {
Long memberId = principalHandler.getUserIdFromPrincipal();

Member member = authRepository.findById(memberId)
.orElseThrow(() -> new RuntimeException("회원이 존재하지 않습니다."));

GetMypageReponseDto getMypage = new GetMypageReponseDto(
member.getId(),
member.getName(),
member.getCollegeDepartmentName(),
member.getDepartmentName(),
member.getAdmissionNumber() + "학번",
member.getUniversityName(),
member.getUniversityLogoImage()
);
return getMypage;
}
}
2 changes: 2 additions & 0 deletions src/main/java/sopt/univoice/domain/user/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Member extends BaseTimeEntity {

private String departmentName;

private String universityLogoImage;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "affiliation_id")
private Affiliation affiliation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public enum SuccessMessage {
GET_ALL_COLLEGE_NOTICE_SUCCESS(HttpStatus.OK.value(),"단과대학 학생회 공지 조회에 성공하였습니다."),
GET_ALL_DEPARTMENT_NOTICE_SUCCESS(HttpStatus.OK.value(),"학과 학생회 공지 조회에 성공하였습니다."),
GET_QUICK_NOTICE_SUCCESS(HttpStatus.OK.value(),"퀵스캔 공지 조회에 성공하였습니다."),
GET_Detail_NOTICE_SUCCESS(HttpStatus.OK.value(),"개별 공지 조회에 성공하였습니다.")
GET_Detail_NOTICE_SUCCESS(HttpStatus.OK.value(),"개별 공지 조회에 성공하였습니다."),
GET_MYPAGE_SUCCESS(HttpStatus.OK.value(),"마이페이지 조회에 성공하였습니다.")
;
private final int status;
private final String message;
Expand Down
Loading