Skip to content

Commit

Permalink
Conflict: git 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hejin8307 committed May 7, 2024
2 parents bbaec8a + ad38c92 commit 53d1d36
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
28 changes: 14 additions & 14 deletions src/main/java/com/hanaro/starbucks/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.csrf((auth) -> auth.disable())
.cors((cors) -> cors.configurationSource(corsConfigurationSource()))

.authorizeHttpRequests((auth) -> auth
// 로그인과 회원가입은 모든 사용자에게 허용한다.
.requestMatchers(
new AntPathRequestMatcher("/login"),
new AntPathRequestMatcher("/signup")
).permitAll() // 권한이 있든 말든 모두 접근 가능
// admin일 경우에만 /admin에 대한 요청에서 접근을 허용한다.
.requestMatchers("/admin").hasRole("ADMIN")
// 그 외 모든 요청은 인증된 사용자에게만 허용한다.
.anyRequest().authenticated()
)
// .authorizeHttpRequests((auth) -> auth
// // 로그인과 회원가입은 모든 사용자에게 허용한다.
// .requestMatchers(
// new AntPathRequestMatcher("/login"),
// new AntPathRequestMatcher("/signup")
// ).permitAll() // 권한이 있든 말든 모두 접근 가능
// // admin일 경우에만 /admin에 대한 요청에서 접근을 허용한다.
// .requestMatchers("/admin").hasRole("ADMIN")
// // 그 외 모든 요청은 인증된 사용자에게만 허용한다.
// .anyRequest().authenticated()
// )
// .formLogin((formLogin) -> formLogin
// .loginProcessingUrl("/login")
// .successHandler(((request, response, authentication) -> {
Expand All @@ -47,9 +47,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// .permitAll()
// );

// .authorizeHttpRequests( (auth) -> auth
// .requestMatchers( new AntPathRequestMatcher("/**") )
// .permitAll())
.authorizeHttpRequests( (auth) -> auth
.requestMatchers( new AntPathRequestMatcher("/**") )
.permitAll())

.sessionManagement(sessionManagement ->
sessionManagement.sessionCreationPolicy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hanaro.starbucks.dto.member.LoginReqDto;
import com.hanaro.starbucks.dto.member.MemberResDto;
import com.hanaro.starbucks.dto.member.SignupReqDto;
import com.hanaro.starbucks.dto.member.MemberUpdateReqDto;
import com.hanaro.starbucks.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -17,22 +18,26 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1/users")
public class MemberController {
private final MemberService userService;
private final MemberService memberService;
private final JwtUtil jwtUtil;

@GetMapping("")
public List<MemberResDto> getUsers(){
return userService.getUsers();
return memberService.getUsers();
}
@GetMapping("/{userIdx}")
public MemberResDto getUser(@PathVariable int userIdx){
return memberService.getUser(userIdx);
}

@PostMapping("/signup")
@ResponseBody
public ResponseEntity<?> signup(@RequestBody SignupReqDto user) {
System.out.println(user);
boolean findUser = userService.findUserByUserId(user.getUserId());
boolean findUser = memberService.findUserByUserId(user.getUserId());
System.out.println(findUser);
if (!findUser) {
MemberResDto newUser = userService.createUser(user);
MemberResDto newUser = memberService.createUser(user);
return ResponseEntity.ok(newUser.getUserId());
}
return ResponseEntity.status(HttpStatus.CONFLICT).body("이미 존재하는 사용자입니다.");
Expand All @@ -41,7 +46,7 @@ public ResponseEntity<?> signup(@RequestBody SignupReqDto user) {
@PostMapping("/login")
@ResponseBody
public ResponseEntity<?> login(@RequestBody LoginReqDto user) {
MemberResDto findUser = userService.findUserByUserIdAndUserPw(user.getUserId(), user.getUserPw());
MemberResDto findUser = memberService.findUserByUserIdAndUserPw(user.getUserId(), user.getUserPw());
if (findUser != null) {
String token = jwtUtil.createToken(findUser.getUserId(), Arrays.asList(findUser.getUserRole()));
return ResponseEntity.ok(token);
Expand All @@ -50,4 +55,14 @@ public ResponseEntity<?> login(@RequestBody LoginReqDto user) {
}
}

@PutMapping("/admin/{userIdx}")
public void updateUser(@PathVariable int userIdx, @RequestBody MemberUpdateReqDto user){
memberService.updateUser(userIdx, user);
}

@DeleteMapping("/admin/{userIdx}")
public void deleteUser(@PathVariable int userIdx){
memberService.deleteUser(userIdx);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hanaro.starbucks.dto.member;

import lombok.Getter;

import java.time.LocalDate;

@Getter
public class MemberUpdateReqDto {
private String userId;
private String userPw;
private String userNickname;
private String userRole;
private Integer userPoint;
private LocalDate userJoinDate;
}
11 changes: 9 additions & 2 deletions src/main/java/com/hanaro/starbucks/entity/Member.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.hanaro.starbucks.entity;

import com.hanaro.starbucks.dto.member.MemberUpdateReqDto;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.cglib.core.Local;

import java.time.LocalDate;
import java.util.Date;

@Entity
@Getter
Expand Down Expand Up @@ -45,6 +44,14 @@ public Member(String userId, String userPw, String userNickname) {
this.userNickname = userNickname;
this.userRole = "USER";
this.userPoint = 0;
}

public void update(MemberUpdateReqDto dto) {
this.userId = dto.getUserId();
this.userNickname=dto.getUserNickname();
this.userPw = dto.getUserPw();
this.userRole = dto.getUserRole();
this.userPoint = dto.getUserPoint();
this.userJoinDate = LocalDate.now();
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/hanaro/starbucks/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hanaro.starbucks.dto.member.MemberResDto;
import com.hanaro.starbucks.dto.member.SignupReqDto;
import com.hanaro.starbucks.dto.member.MemberUpdateReqDto;
import com.hanaro.starbucks.entity.Member;
import com.hanaro.starbucks.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,6 +26,16 @@ public List<MemberResDto> getUsers(){
return memberRepository.findAll().stream().map(MemberResDto::new).collect(Collectors.toList());
}

@Transactional
public MemberResDto getUser(int idx){

Optional<Member> optionalMember = memberRepository.findById(idx);
if(optionalMember.isEmpty()){
throw new IllegalArgumentException("존재하지 않는 회원입니다.");
}
return new MemberResDto(optionalMember.get());
}

@Transactional
public boolean findUserByUserId(String userId) {
return memberRepository.existsByUserId(userId);
Expand Down Expand Up @@ -57,4 +68,17 @@ public MemberResDto findUserByUserIdAndUserPw(String userId, String userPw) {
}
}

public void updateUser(int userIdx, MemberUpdateReqDto user){
Optional<Member> optional = memberRepository.findById(userIdx);
if(optional.isEmpty()){
throw new IllegalArgumentException("존재하지 않는 회원입니다.");
}
Member member = optional.get();
member.update(user);
memberRepository.save(member);
}

public void deleteUser(int userIdx){
memberRepository.deleteById(userIdx);
}
}

0 comments on commit 53d1d36

Please sign in to comment.