Skip to content

Commit

Permalink
#3 feat : 마이페이지 -> 닉네임, 나의재치현황(나의재치 수, 관심목록 수) get
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Mar 28, 2023
1 parent aa1a4f4 commit 08f27cc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/zatch/zatchserver/ResponseMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ResponseMessage {
public static final String UPDATE_USER = "회원 정보 수정 성공";
public static final String DELETE_USER = "회원 탈퇴 성공";
public static final String USER_TOWN_SUCCESS = "회원 동네 설정 성공";
public static final String MY_PROFILE_SUCCESS = "내 프로필 불러오기 성공";
public static final String MYPAGE_SUCCESS = "마이페이지 불러오기 성공";
public static final String USER_NICKNAME_EDIT_SUCCESS ="회원 닉네임 수정 성공";
public static final String INTERNAL_SERVER_ERROR = "서버 내부 에러";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ResponseEntity patchNickname(@PathVariable("userId") Long userId
public ResponseEntity getProfile(@PathVariable("userId") Long userId) {
try {
String userNickname = userService.profile(userId);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.MYPAGE_SUCCESS, new GetProfileResDto(userNickname)), HttpStatus.OK);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.MY_PROFILE_SUCCESS, new GetProfileResDto(userNickname)), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Profile"), HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand All @@ -113,4 +113,16 @@ public ResponseEntity postTown(@PathVariable("userId") Long userId, @RequestBody
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error User Town"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@GetMapping("/{userId}/mypage")
@ApiOperation(value = "회원 프로필", notes = "회원 프로필 API")
public ResponseEntity getMypage(@PathVariable("userId") Long userId) {
try {
String user_id = userService.mypage(userId);
System.out.println(user_id);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.MYPAGE_SUCCESS, new GetMypageResDto(user_id)), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Profile"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/zatch/zatchserver/dto/GetMypageResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.zatch.zatchserver.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class GetMypageResDto {
private String user_mypage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
@AllArgsConstructor
public class GetProfileResDto {
private String nickname;
private String user_profile;
// 별점
// 한 줄 후기 리스트
// 나의 재치 현황 리스트
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,17 @@ public String insertToken(Long userId, String token) {
}
}

@Override
public List<Map<String, Object>> getMypage(Long userId) {
try {
String sql = "SELECT user.user_id, user.nickname, COUNT(*) AS zatch_count, (SELECT COUNT(zatch_like.zatch_id) AS zatch_like_count FROM zatch.zatch_like WHERE user_id = 6) AS zatch_like_count " +
"FROM zatch.zatch AS A LEFT JOIN zatch.user on user.user_id = A.user_id WHERE user.user_id = ?;";
Object[] params = {userId};
System.out.println("User's My Page SQL select");
return jdbcTemplate.queryForList(sql, params);
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User My Page Not Found");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface UserRepository {
String townInsert(Long userId, String town);

String insertToken(Long userId, String token);

List<Map<String, Object>> getMypage(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface UserService {
String town(Long userId, String town);

String token(Long userId, String token);
String mypage(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public String town(Long userId, String town) {
public String token(Long userId, String token) {
return userRepository.insertToken(userId, token);
}

@Override
public String mypage(Long userId) {
return String.valueOf(userRepository.getMypage(userId));
}
}

0 comments on commit 08f27cc

Please sign in to comment.