Skip to content

Commit

Permalink
Merge pull request #55 from Zatch-Team/Feature/ViewNearZatch
Browse files Browse the repository at this point in the history
feat: 대표 동네 변경 API 추가 #19
  • Loading branch information
plum-king authored Jun 10, 2023
2 parents 6fbcc72 + 35f6367 commit 4325e66
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/zatch/zatchserver/ResponseMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ResponseMessage {
public static final String DELETE_USER = "회원 탈퇴 성공";
public static final String LOGOUT_SUCCESS = "로그아웃 성공";
public static final String USER_TOWN_SUCCESS = "회원 동네 설정 성공";
public static final String USER_TOWN_EDIT_SUCCESS = "회원 동네 변경 성공";

public static final String MY_PROFILE_SUCCESS = "내 프로필 불러오기 성공";
public static final String MYPAGE_SUCCESS = "마이페이지 불러오기 성공";
public static final String PROFILE_IMAGE_UPLOAD_SUCCESS = "프로필 업로드 성공";
Expand Down
37 changes: 26 additions & 11 deletions src/main/java/com/zatch/zatchserver/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS
String isSignup = userService.loginOrSignup(postUserReqDto.getEmail());

// 회원가입
if (isSignup.equals("signup")){
if (isSignup.equals("signup")) {
List<String> adjectives = Arrays.asList("귀여운", "당황한", "어리둥절", "깜찍한", "동글동글", "초롱초롱", "배고픈", "의아한", "놀라운", "어여쁜", "차분한", "한가한", "화려한", "깨끗한",
"정직한", "활발한", "긍정적인", "낙천적인", "다정한", "단호한", "겸손한", "매력적인", "발랄한", "민첩한", "상냥한", "솔직한", "신중한", "용감한", "수줍은", "소중한");
List<String> animals = Arrays.asList("강아지", "거북이", "고래", "고양이", "공작", "기린", "까치", "낙타", "너구리", "늑대", "다람쥐", "부엉이", "사슴", "사자", "새우", "수달", "순록",
List<String> animals = Arrays.asList("강아지", "거북이", "고래", "고양이", "공작", "기린", "까치", "낙타", "너구리", "늑대", "다람쥐", "부엉이", "사슴", "사자", "새우", "수달", "순록",
"악어", "여우", "오리", "올빼미", "청설모", "치타", "코끼리", "토끼", "팬더", "펭귄", "표범", "햄스터", "호랑이");
Collections.shuffle(adjectives);
Collections.shuffle(animals);
Expand Down Expand Up @@ -89,13 +89,13 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS
}

@GetMapping("/logout")
@ApiOperation(value="로그아웃", notes = "로그아웃 API")
public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) throws Exception{
@ApiOperation(value = "로그아웃", notes = "로그아웃 API")
public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
HttpSession session = request.getSession();
session.invalidate();
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_NICKNAME_EDIT_SUCCESS, "Success Logout"), HttpStatus.OK);
} catch (Exception e){
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Logout"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand All @@ -106,13 +106,13 @@ public ResponseEntity logout(HttpServletRequest request, HttpServletResponse res
})
@PatchMapping("/{userId}/nickname")
@ApiOperation(value = "회원 닉네임 수정", notes = "회원 닉네임 수정 API")
public ResponseEntity patchNickname(@PathVariable("userId") Long userId , @RequestBody PatchUserNicknameReqDto pathUserNicknameReqDto) {
public ResponseEntity patchNickname(@PathVariable("userId") Long userId, @RequestBody PatchUserNicknameReqDto pathUserNicknameReqDto) {
try {
String newNickname = pathUserNicknameReqDto.getNewNickname();
Long idOfModifiedUser = userId;
userService.modifyNickname(idOfModifiedUser, newNickname);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_NICKNAME_EDIT_SUCCESS, new PatchUserNicknameResDto(newNickname)), HttpStatus.OK);
} catch (Exception e){
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Modify Nickname"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand Down Expand Up @@ -150,6 +150,21 @@ public ResponseEntity postAddress(@PathVariable("userId") Long userId, @RequestB
}
}

@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = PostUserAddressEditReqDto.class,
examples = @Example(@ExampleProperty(value = "{'property1': 'value1'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
})
@PostMapping("/{userId}/edit_address")
@ApiOperation(value = "회원 동네 변경", notes = "회원 동네 변경 API")
public ResponseEntity editAddress(@PathVariable("userId") Long userId, @RequestBody PostUserAddressEditReqDto postUserAddressEditReqDto) {
try {
int addressNum = postUserAddressEditReqDto.getAddress_num();
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_TOWN_EDIT_SUCCESS, new PostUserAddressEditReqDto(addressNum)), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error User Town Edit"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = GetMypageResDto.class,
examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
Expand All @@ -172,9 +187,9 @@ public ResponseEntity getMypage(@PathVariable("userId") Long userId) {
})
@PostMapping("/{userId}/upload_profile")
@ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) {
public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value = "image") MultipartFile image) {
try {
System.out.println("param_image : "+image);
System.out.println("param_image : " + image);
userService.uploadProfile(userId, image);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK);
} catch (Exception e) {
Expand All @@ -188,9 +203,9 @@ public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @Reques
})
@PatchMapping("/{userId}/patch_profile")
@ApiOperation(value = "회원 프로필 이미지 수정", notes = "회원 프로필 이미지 수정 API")
public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) {
public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value = "image") MultipartFile image) {
try {
System.out.println("param_image : "+image);
System.out.println("param_image : " + image);
userService.patchProfile(userId, image);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK);
} catch (Exception e) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/zatch/zatchserver/domain/Address.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.zatch.zatchserver.domain;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Address {
private String addr_name;
private String addr_x;
private String addr_y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.zatch.zatchserver.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostUserAddressEditReqDto {
int address_num;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.zatch.zatchserver.repository;

import com.zatch.zatchserver.domain.Address;
import com.zatch.zatchserver.domain.User;
import com.zatch.zatchserver.service.S3Uploader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -140,7 +144,7 @@ public List<Map<String, Object>> profile(Long userId) {
}
}

// 동네 설정
// 동네 설정 -> 초기 설정은 addr_name_1 이 대표 동네
@Override
public String addressInsert(Long userId, String addr_name, String addr_x, String addr_y) {
try {
Expand All @@ -167,6 +171,72 @@ public String addressInsert(Long userId, String addr_name, String addr_x, String
}
}

//대표 동네 변경 -> 대표 동네 변경할 때에는 main_addr_name에 덮어쓰기
@Override
public String editAddress(Long userId, int addressNum) {
try {
List<Address> results = null;
if (addressNum == 1) {
String sql = "SELECT addr_name_1, addr_x_1, addr_y_1 FROM address WHERE user_id = ?";
Object[] params = new Object[]{userId};

results = jdbcTemplate.query(sql, params, new RowMapper<Address>() {
@Override
public Address mapRow(ResultSet rs, int rowNum) throws SQLException {
// Map the result set to your object
Address obj = new Address();
obj.setAddr_name(rs.getString("addr_name_1"));
obj.setAddr_x(rs.getString("addr_x_1"));
obj.setAddr_y(rs.getString("addr_y_1"));

return obj;
}
});
System.out.println(results.get(0));
}
else if(addressNum == 2){
String sql = "SELECT addr_name_2, addr_x_2, addr_y_2 FROM address WHERE user_id = ?";
Object[] params = new Object[]{userId};

results = jdbcTemplate.query(sql, params, new RowMapper<Address>() {
@Override
public Address mapRow(ResultSet rs, int rowNum) throws SQLException {
// Map the result set to your object
Address obj = new Address();
obj.setAddr_name(rs.getString("addr_name_2"));
obj.setAddr_x(rs.getString("addr_x_2"));
obj.setAddr_y(rs.getString("addr_y_2"));

return obj;
}
});
System.out.println(results.get(0));

}
else if(addressNum == 3){
String sql = "SELECT addr_name_3, addr_x_3, addr_y_3 FROM address WHERE user_id = ?";
Object[] params = new Object[]{userId};

results = jdbcTemplate.query(sql, params, new RowMapper<Address>() {
@Override
public Address mapRow(ResultSet rs, int rowNum) throws SQLException {
// Map the result set to your object
Address obj = new Address();
obj.setAddr_name(rs.getString("addr_name_3"));
obj.setAddr_x(rs.getString("addr_x_3"));
obj.setAddr_y(rs.getString("addr_y_3"));

return obj;
}
});
}
jdbcTemplate.update("UPDATE user SET main_addr_name = ?, main_addr_x = ?, main_addr_y = ? WHERE user_id = ? ", results.get(0).getAddr_name(), results.get(0).getAddr_x(), results.get(0).getAddr_y(), userId);
return results.get(0).getAddr_name();
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Address Edit Error");
}
}

// 토큰
@Override
public String insertToken(Long userId, String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface UserRepository {

String addressInsert(Long userId, String addr_name, String addr_x, String addr_y);

String editAddress(Long userId, int addressNum);

String insertToken(Long userId, String token);

List<Map<String, Object>> getMypage(Long userId);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/zatch/zatchserver/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface UserService {

String address(Long userId, String addr_name, String addr_x, String addr_y);

String modAddress(Long userId, int addressNum);

String token(Long userId, String token);

String mypage(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.transaction.Transactional;
import java.io.IOException;
import java.util.List;

@RequiredArgsConstructor
Expand Down Expand Up @@ -66,6 +64,11 @@ public String address(Long userId, String addr_name, String addr_x, String addr_
return userRepository.addressInsert(userId, addr_name, addr_x, addr_y);
}

@Override
public String modAddress(Long userId, int addressNum){
return userRepository.editAddress(userId, addressNum);
}

@Override
public String token(Long userId, String token) {
return userRepository.insertToken(userId, token);
Expand Down

0 comments on commit 4325e66

Please sign in to comment.