Skip to content

Commit

Permalink
Merge pull request #10 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
FEAT : updateUser API
  • Loading branch information
femmefatalehaein authored Aug 18, 2024
2 parents efbef0f + 4d91ae4 commit c84e0e5
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI openAPI() {
return new OpenAPI()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.ai_jeju.controller;

import com.example.ai_jeju.domain.Store;
import com.example.ai_jeju.domain.User;
import com.example.ai_jeju.service.MainVIewService;
import com.example.ai_jeju.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

Expand All @@ -14,6 +16,8 @@ public class MainViewController {

@Autowired
private MainVIewService mainViewService;
@Autowired
private UserService userService;

@GetMapping("/detailList")
public Optional<Store> getUserById(@RequestParam Long storeId) {
Expand All @@ -40,6 +44,14 @@ public List<Store> searchByCategory(@RequestParam String keyword, @RequestParam
return mainViewService.searchByCategory(keyword,categoryId);
}

@GetMapping("/rcmd")
public boolean getIfrcmd(@RequestParam Long userId) {

Optional<User> user = userService.findById(userId);
if(user.isPresent())
return user.get().isIfRcmd();
return false;
}

// @GetMapping("/stay/detailList")
// public Stay getStayById(@RequestParam int stayId) {
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/example/ai_jeju/controller/MyPageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Optional;

import static org.springframework.data.jpa.domain.AbstractPersistable_.id;

@RestController
@RequestMapping("/api")
Expand Down Expand Up @@ -73,4 +70,18 @@ public ResponseEntity<String> createPresignedUrl(@RequestBody Map<String, String
return ResponseEntity.ok(presignedUrl);
}


@PutMapping("/mypage/update")
public ResponseEntity<User> updateMyPage (@RequestBody User newUser) {

Long userId = newUser.getId();

try {
User updatedUser = myPageService.updateUser(userId, newUser);
return ResponseEntity.ok(updatedUser);
} catch (RuntimeException e) {
return ResponseEntity.notFound().build();
}

}
}
40 changes: 0 additions & 40 deletions src/main/java/com/example/ai_jeju/domain/Play.java

This file was deleted.

47 changes: 0 additions & 47 deletions src/main/java/com/example/ai_jeju/domain/Restaurant.java

This file was deleted.

41 changes: 0 additions & 41 deletions src/main/java/com/example/ai_jeju/domain/Stay.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ public class Store {
@Column(name = "tel",updatable = false,nullable = true)
String tel;

@Column(name = "noBmk",updatable = false,nullable = true)
String noBmk;

}
3 changes: 3 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class User {
@Column(name="phoneNum", nullable = false)
private String phoneNum;

@Column(name ="ifRcmd", nullable = false)
private boolean ifRcmd;


/*
// Builder pattern
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/example/ai_jeju/dto/SignUpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SignUpRequest {
private String profileImg;
private String provider;
private String phoneNum;
private Boolean ifRcmd;
/**
* 함께 보낼 동반 아동에 대한 정보 -> 여러명일 수도 있으므로 배열 형식으로 받는다.
* private List<Child> child;
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/com/example/ai_jeju/repository/StayRepository.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
Optional<User> findById(Long userId);


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.example.ai_jeju.service;

import com.example.ai_jeju.domain.Restaurant;
import com.example.ai_jeju.domain.Stay;
import com.example.ai_jeju.domain.Store;
import com.example.ai_jeju.repository.RestaurantRepository;
import com.example.ai_jeju.repository.StayRepository;
import com.example.ai_jeju.repository.StoreRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -16,8 +12,7 @@
@Service
public class MainVIewService {

@Autowired
private RestaurantRepository restaurantRepository;

@Autowired
private StoreRepository storeRepository;

Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/example/ai_jeju/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,8 @@ public String getProfileUrl(Long id) {
return user.getProfileImg(); // 프로필 이미지 URL 반환
}

// public void deleteSnsProfile(Long id) {
// Optional<User> userOptional = userRepository.findById(id);
// if (userOptional.isPresent()) {
// User user = userOptional.get();
// user.setSnsprofile(null);
// userRepository.save(user);
// } else {
// throw new NoSuchElementException("not found");
// }
// }



public void deleteProfileImage(Long id) {
Optional<User> userOptional = userRepository.findById(id);
Expand All @@ -67,4 +59,16 @@ public void deleteProfileImage(Long id) {
throw new NoSuchElementException("not found");
}
}

public User updateUser(Long id, User newUserData) {
return userRepository.findById(id)
.map(user -> {
user.setName(newUserData.getName());
user.setNickname(newUserData.getNickname());
user.setProfileImg(newUserData.getProfileImg());
user.setPhoneNum(newUserData.getPhoneNum());
return userRepository.save(user);
})
.orElseThrow(() -> new RuntimeException("User not found"));
}
}
15 changes: 11 additions & 4 deletions src/main/java/com/example/ai_jeju/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public Long registerUser( SignUpRequest signUpRequest, HttpServletRequest reques
.provider(signUpRequest.getProvider())
.rgtDate(date.toString())
.phoneNum(signUpRequest.getPhoneNum())
.ifRcmd(signUpRequest.getIfRcmd())
.build();
/*-------------------------------------------*/

Expand Down Expand Up @@ -122,20 +123,26 @@ public Long registerUser( SignUpRequest signUpRequest, HttpServletRequest reques

return newUser.getId();
}

// public List<Store> getRandomList(){
// List<Store> RandomStores = new ArrayList<Store>();
// StoreRepository.findById(Long.valueOf(1));
// }

public User findByEmail(String email){
return userRepository.findByEmail(email)
.orElseThrow(
()-> new IllegalArgumentException("unexpected user"));
}

public Store findById(Long id){
return storeRepository.findById(id)
.orElseThrow(
()-> new IllegalArgumentException("unexpected user"));
// public Store findStoreById(Long id){
// return storeRepository.findById(id)
// .orElseThrow(
// ()-> new IllegalArgumentException("unexpected store"));
// }

public Optional<User> findById(Long userId){
return userRepository.findById(userId);
}
/**
* withdroaw up flow
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ spring.jpa.open-in-view=false
# MySQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# DB Source URL
spring.datasource.url=jdbc:mysql://localhost:3306/ai_jeju?serverTimezone=UTC
spring.datasource.url=jdbc:mysql://112.219.81.130:3310/ai_jeju?serverTimezone=UTC
# DB username
spring.datasource.username=root
# DB password
spring.datasource.password=root
spring.datasource.password=!@Knp2020!@

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Expand Down

0 comments on commit c84e0e5

Please sign in to comment.