Skip to content

Commit

Permalink
Feat: 일반 로그인, 소셜로그인, 브랜드 조회
Browse files Browse the repository at this point in the history
Feat: 일반 로그인, 소셜로그인, 브랜드 조회
  • Loading branch information
tokyj515 committed Jul 31, 2023
2 parents 7a5185a + 6d3faaf commit 7324aeb
Show file tree
Hide file tree
Showing 55 changed files with 1,754 additions and 136 deletions.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[\U0001F331Feat] 이슈 설명"
labels: "\U0001F527Feature"
assignees: ''

---

## 🛠️기능 설명 or 브랜치 생성 목적
> 홈화면 & 자체 로그인 기능
## ✅To-do list🗒️
- [ ]
- [ ]
- [ ]
- [ ]
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ dependencies {
// gson
implementation 'com.google.code.gson:gson:2.9.0'

//implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.3.5'
//implementation 'org.springframework.cloud:spring-cloud-start-aws:2.0.1.RELEASE'
//implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'


implementation 'org.json:json:20200518'


Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/example/neoul/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.example.neoul.controller;

import com.example.neoul.dto.TokenRes;
import com.example.neoul.dto.UserReq;
import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.global.entity.BaseEntity;
import com.example.neoul.global.exception.BadRequestException;
import com.example.neoul.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags={"01.user"})
@RequestMapping("/oauth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;


/**
* 카카오 소셜로그인
* https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=abf4119e38a436ab64718033228aad2d&redirect_uri=http://localhost:8080/oauth/kakao
* */
@ApiOperation(value = "인가코드 캐치를 위한 api, 사용x, 백엔드 터미널로 반환중",
notes = "https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=abf4119e38a436ab64718033228aad2d&redirect_uri=http://localhost:8080/oauth/kakao" +
"원래는 프론트엔드가 첫 회원가입 링크로 들어가서 code를 받고, 그 받은 코드로 이 api에 접근해서" +
"카카오의 access_token을 반환 후" +
"access_token을 /kakao/login의 요청에 넣어서 우리 사이트의 로그인하고 그 결과를 얻음")
@GetMapping("/kakao")
public ApiResponse<String> getAccessTokenKakao(@RequestParam String code) {
String accessToken=authService.getKakaoAccessToken(code);
System.out.println("code for kakaoServer : " + code);
System.out.println("for /oauth/kakao : " + accessToken);

return new ApiResponse<>(accessToken);
}

@ApiOperation(value = "카카오 로그인", notes = "카카오 로그인")
@PostMapping("/kakao/login")
public TokenRes kakaoSignupOrLogin(@RequestBody UserReq.SocialReq socialReq) {
TokenRes tokenRes = authService.createAndLoginKakaoUser(socialReq);

if(tokenRes == null)
throw new BadRequestException("사용자 정보가 없습니다");
return tokenRes;
}



}
31 changes: 31 additions & 0 deletions src/main/java/com/example/neoul/controller/BrandController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.neoul.controller;

import com.example.neoul.dto.brand.BrandRes;
import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.service.BrandService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(tags={"02.brand"})
@RequestMapping("/brand")
public class BrandController {
private final BrandService brandService;

// 브랜드 list
@GetMapping("/list")
public ApiResponse<List<BrandRes.BrandListRes>> list(){
return new ApiResponse(brandService.list());
}

// 브랜드 상세조회
@GetMapping("/{brandId}")
public ApiResponse<BrandRes.BrandInfoRes> brandInfo(@PathVariable("brandId") Long brandId){
return new ApiResponse<>(brandService.info(brandId));
}

}
34 changes: 34 additions & 0 deletions src/main/java/com/example/neoul/controller/StoryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.neoul.controller;

import com.example.neoul.dto.Story.StoryRes;
import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.service.StoryService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(tags={"03.story"})
@RequestMapping("/story")
public class StoryController {
private final StoryService storyService;

// 스토리 list
@GetMapping("/list")
public ApiResponse<List<StoryRes.StoryListRes>> list(){
return new ApiResponse(storyService.list());
}

// 스토리 상세조회
@GetMapping("/{storyId}")
public ApiResponse<StoryRes.StoryInfoRes> storyInfo(@PathVariable("storyId") Long storyId){
return new ApiResponse<>(storyService.info(storyId));
}
}

20 changes: 19 additions & 1 deletion src/main/java/com/example/neoul/controller/TestController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
package com.example.neoul.controller;

import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.global.exception.BadRequestException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags={"00.test"})
@RequestMapping("/test")
public class TestController {
@GetMapping("/testapi")
public ResponseEntity test(){
log.info("test api 수신");
log.error("test api 수신");
return new ResponseEntity("test ok",HttpStatus.OK);
}


@ApiOperation(value = "API 응답 반환 형식 예", notes = "API 응답 반환 형식 예")
@GetMapping("")
public ApiResponse<String> test2(@RequestParam(required = false) String s){

if("null".equals(s))
throw new BadRequestException("오류 던지기");

return new ApiResponse<>("데이터가 들어갈 자리(문자열, 객체 등");
}

}
69 changes: 69 additions & 0 deletions src/main/java/com/example/neoul/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.neoul.controller;


import com.example.neoul.dto.TokenRes;
import com.example.neoul.dto.UserReq;
import com.example.neoul.dto.UserRes;
import com.example.neoul.entity.user.User;
import com.example.neoul.global.entity.ApiResponse;
import com.example.neoul.global.exception.BadRequestException;
import com.example.neoul.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RequiredArgsConstructor
@RestController
@Api(tags={"01.user"})
@RequestMapping("/user")
public class UserController {

private final UserService userService;


@ApiOperation(value = "현재 로그인 유저", notes = "현재 로그인 유저")
@GetMapping("/now")
public ApiResponse<User> now(){
return new ApiResponse<>(userService.findNowLoginUser());
}


@ApiOperation(value = "회원가입", notes = "회원가입")
@PostMapping("/signup")
public ApiResponse<UserRes.UserDetailDto> signup(@RequestBody UserReq.SignupUserDto signupUserDto) {
//이메일 형식 체크
if(userService.validationEmail(signupUserDto.getUsername()))
throw new BadRequestException("이메일 형식으로 입력해주세요");

//비밀번호 형식 체크
if(signupUserDto.getPassword().length() < 6)
throw new BadRequestException("비밀번호를 6자리 이상 입력해주세요");


return new ApiResponse<>(userService.signup(signupUserDto));
}




@ApiOperation(value = "로그인", notes = "로그인")
@PostMapping("/login")
public ApiResponse<TokenRes> signup(@RequestBody UserReq.LoginUserDto loginUserDto) {
return new ApiResponse<>(userService.login(loginUserDto));
}

//
// @ApiOperation(value = "회원 탈퇴", notes = "회원 탈퇴")
// @GetMapping("/withdrawal")
// public BaseResponse<String> withdrawal() {
// if(userService.withdrawal() != null)
// return BaseResponse.ok(SUCCESS, userService.withdrawal());
//
// return BaseResponse.ok(USER_FAILED_TO_WITHDRAWAL);
// }



}
41 changes: 41 additions & 0 deletions src/main/java/com/example/neoul/dto/Story/StoryRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.neoul.dto.Story;

import com.example.neoul.dto.brand.BrandRes;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;

public class StoryRes {

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
// content와 content/상세 - 브랜드 후원 이야기
public static class StoryListRes {
private Long sid; //후원 이야기 id
private String categoryVName; // 후원 카테고리 이름
private String preImg; //후원글 프리뷰 이미지
private String title; //후원글 제목
private LocalDateTime createdAt; //후원글 작성 일시
}

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
// content와 content/상세 - 브랜드 후원 이야기
public static class StoryInfoRes {
private Long sid; //후원 이야기 id
// private Long bid; //브랜드 id
private String categoryVName; // 후원 브랜드 이름
private String preImg; //후원글 프리뷰 이미지
private String title; //후원글 제목
private String content; //후원글 내용
private LocalDateTime createdAt; //후원글 작성 일시
private List<BrandRes.BrandListRes> brandListRes; // 브랜드 별 물품 리스트
}
}
1 change: 1 addition & 0 deletions src/main/java/com/example/neoul/dto/TokenRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Getter
public class TokenRes {
private String username;
private boolean firstLogin;
private String accessToken;
private String refreshToken;
}
12 changes: 5 additions & 7 deletions src/main/java/com/example/neoul/dto/UserReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UserReq {
@AllArgsConstructor
@Setter
@Getter
public static class LoginUserReq {
public static class LoginUserDto {
@ApiModelProperty(example = "[email protected]")
private String username;
@ApiModelProperty(example = "test1234")
Expand All @@ -22,7 +22,7 @@ public static class LoginUserReq {
@AllArgsConstructor
@Setter
@Getter
public static class SocialLoginUserReq {
public static class SocialLoginUserDto {
@ApiModelProperty(example = "[email protected]")
private String username;
@ApiModelProperty(example = "kakao")
Expand All @@ -37,14 +37,12 @@ public static class SocialLoginUserReq {
@AllArgsConstructor
@Setter
@Getter
public static class SignupUserReq {
public static class SignupUserDto {
private String username;
private String password;
private String name;
private String phone;
private String imageUrl;

@ApiModelProperty(example = "true or false")
private boolean emailVerified;
}


Expand All @@ -53,7 +51,7 @@ public static class SignupUserReq {
@AllArgsConstructor
@Setter
@Getter
public static class EmailAuthReq {
public static class EmailAuthDto {
private String email;
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/example/neoul/dto/UserRes.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.neoul.dto;

import com.example.neoul.entity.user.User;
import lombok.*;

public class UserRes {
Expand All @@ -16,6 +17,31 @@ public static class SignupUserRes {
}


@Builder
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public static class UserDetailDto {
private String username;
private String name;
private String phone;
private String imageUrl;
private String social;
private boolean firstLogin;

public static UserDetailDto toDto(User user){
return UserDetailDto.builder()
.username(user.getUsername())
.name(user.getName())
.phone(user.getPhone())
.imageUrl(user.getImageUrl())
.social(user.getSocial())
.firstLogin(user.isFirstLogin())
.build();
}
}



@Builder
Expand Down
Loading

0 comments on commit 7324aeb

Please sign in to comment.