Skip to content

Commit

Permalink
Merge pull request #215 from grooteogi/develop
Browse files Browse the repository at this point in the history
release v1.0.0
  • Loading branch information
jongwooo authored Jun 10, 2022
2 parents 618bd3e + 303d5e7 commit 065fb0a
Show file tree
Hide file tree
Showing 27 changed files with 277 additions and 137 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'grooteogi'
version = '0.6.2'
version = '1.0.0'

repositories {
mavenCentral()
Expand Down
3 changes: 1 addition & 2 deletions api/src/main/java/grooteogi/config/UserInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
String result = mapper.writeValueAsString(refreshResponse);
response.getWriter().write(result);
} else {
System.out.println("refresh is Null");
throw new ApiException(ApiExceptionEnum.EXPIRED_TOKEN_EXCEPTION);
throw new ApiException(ApiExceptionEnum.EXPIRED_REFRESH_TOKEN_EXCEPTION);
}
}
return flag;
Expand Down
24 changes: 16 additions & 8 deletions api/src/main/java/grooteogi/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import grooteogi.enums.LoginType;
import grooteogi.exception.ApiException;
import grooteogi.exception.ApiExceptionEnum;
import grooteogi.mapper.UserMapper;
import grooteogi.response.BasicResponse;
import grooteogi.service.AuthService;
import grooteogi.service.UserService;
import grooteogi.utils.OauthClient;
import grooteogi.utils.Session;
import java.net.URI;
import java.net.URISyntaxException;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
Expand All @@ -39,6 +41,9 @@ public class AuthController {
private final AuthService authService;
private final OauthClient oauthClient;

@Value("${custom.oauth2.redirect.front}")
private String redirectUrl;

@PostMapping("/auth/login")
public ResponseEntity<BasicResponse> login(@RequestBody AuthDto.Request request) {

Expand Down Expand Up @@ -102,8 +107,7 @@ public ResponseEntity<BasicResponse> checkVerifyEmail(

@GetMapping("/oauth/{type}")
public ResponseEntity<BasicResponse> oauth(
@PathVariable String type, @RequestParam("code") String code) {

@PathVariable String type, @RequestParam("code") String code) throws URISyntaxException {
OauthDto oauthDto;

if (type.equalsIgnoreCase(LoginType.GOOGLE.name())) {
Expand All @@ -117,13 +121,17 @@ public ResponseEntity<BasicResponse> oauth(
User user = authService.oauth(oauthDto);
Token token = authService.generateToken(user.getId(), user.getEmail());

AuthDto.Response response = UserMapper.INSTANCE.toResponseDto(user, user.getUserInfo());

URI redirectUri = new URI(redirectUrl + "/auth/oauth?token=" + token.getAccessToken());
HttpHeaders responseHeaders = setHeader(token, true);

responseHeaders.setLocation(redirectUri);
return new ResponseEntity<>(BasicResponse.builder()
.message("oauth success").data(response).build(),
responseHeaders, HttpStatus.OK);
.message("oauth success").build(),
responseHeaders, HttpStatus.SEE_OTHER);
}

@GetMapping("/oauth/google/request")
public void oauthGoogleRequest() {
oauthClient.googleRequest();
}

private HttpHeaders setHeader(Token token, boolean isRefresh) {
Expand Down
14 changes: 9 additions & 5 deletions api/src/main/java/grooteogi/controller/PostController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package grooteogi.controller;

import static org.yaml.snakeyaml.util.UriEncoder.decode;

import grooteogi.dto.HashtagDto;
import grooteogi.dto.LikeDto;
import grooteogi.dto.PostDto;
import grooteogi.dto.ReviewDto;
import grooteogi.dto.ScheduleDto;
Expand Down Expand Up @@ -39,10 +42,11 @@ public ResponseEntity<BasicResponse> search(
@RequestParam(name = "keyword", required = false) String keyword,
@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "filter", required = false) String filter,
@RequestParam(name = "hashtag", required = false) String hashtag,
@RequestParam(name = "region") String region) {

PostDto.SearchResponse searchResponse = postService.search(keyword, filter,
PageRequest.of(page - 1, 12, Sort.by("id").descending()), region);
PageRequest.of(page - 1, 12, Sort.by("id").descending()), hashtag, decode(region));
return ResponseEntity.ok(
BasicResponse.builder().message("search post success").data(searchResponse).build());
}
Expand All @@ -56,14 +60,14 @@ public ResponseEntity<BasicResponse> getPostResponse(
BasicResponse.builder().message("get post success").data(post).build());
}

@GetMapping("/{postId}/schedules")
@GetMapping("/schedules/{postId}")
public ResponseEntity<BasicResponse> getSchedulesResponse(@PathVariable int postId) {
List<ScheduleDto.Response> schedulesResponse = postService.getSchedulesResponse(postId);
return ResponseEntity.ok(
BasicResponse.builder().message("get schedules success").data(schedulesResponse).build());
}

@GetMapping("/{postId}/reviews")
@GetMapping("/reviews/{postId}")
public ResponseEntity<BasicResponse> getReviewsResponse(@PathVariable int postId) {
List<ReviewDto.Response> reviewResponses = postService.getReviewsResponse(postId);
return ResponseEntity.ok(
Expand All @@ -75,9 +79,9 @@ public ResponseEntity<BasicResponse> createHeart(@PathVariable Integer postId) {
Session session = (Session) SecurityContextHolder.getContext().getAuthentication()
.getPrincipal();

postService.modifyHeart(postId, session.getId());
LikeDto.Response response = postService.modifyHeart(postId, session.getId());
return ResponseEntity.ok(
BasicResponse.builder().message("heart success").build());
BasicResponse.builder().message("heart success").data(response).build());
}

@GetMapping("/{postId}/hashtags")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grooteogi.controller;

import grooteogi.dto.ReservationDto;
import grooteogi.dto.ReservationDto.SendSmsResponse;
import grooteogi.response.BasicResponse;
import grooteogi.service.ReservationService;
import grooteogi.utils.Session;
Expand Down Expand Up @@ -81,15 +80,18 @@ public ResponseEntity<BasicResponse> modifyStatus(@PathVariable Integer reservat

@PostMapping("/sms/send")
public ResponseEntity<BasicResponse> sendSms(@RequestParam String phoneNumber) {
SendSmsResponse response = this.reservationService.sendSms(phoneNumber);
this.reservationService.sendSms(phoneNumber);
return ResponseEntity.ok(BasicResponse.builder()
.message("send sms code success").data(response).build());
.message("send sms code success").build());
}

@PostMapping("/sms/check")
public ResponseEntity<BasicResponse> checkSms(
@RequestBody ReservationDto.CheckSmsRequest request) {
reservationService.checkSms(request);
Session session = (Session) SecurityContextHolder.getContext().getAuthentication()
.getPrincipal();

reservationService.checkSms(request, session.getId());

return ResponseEntity.ok(
BasicResponse.builder().message("check sms success").build());
Expand Down
6 changes: 5 additions & 1 deletion api/src/main/java/grooteogi/dto/HashtagDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public Request(String name) {
@Builder
public static class Response {

private int hashtagId;
private String name;

@JsonCreator
public Response(String name) {
this.name = name;
}
}
}
2 changes: 1 addition & 1 deletion api/src/main/java/grooteogi/dto/PostDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class SearchResult {
private String title;
private String content;
private String imageUrl;
private List<String> hashtags;
private String[] hashtags;
}

@Data
Expand Down
8 changes: 0 additions & 8 deletions api/src/main/java/grooteogi/dto/ReservationDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static class DetailResponse {
private int postId;
private String imageUrl;
private Boolean isCanceled;
private String hostPhone;
private String applyPhone;
private String applyNickname;
private String text;
Expand All @@ -47,13 +46,6 @@ public static class Response {
private int reservationId;
}

@Data
@Builder
public static class SendSmsResponse {

private String code;
}

@Data
@Builder
public static class CheckSmsRequest {
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/grooteogi/exception/ApiExceptionEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public enum ApiExceptionEnum {
EMAIL_DUPLICATION_EXCEPTION(HttpStatus.CONFLICT, "이미 존재하는 이메일입니다."),
PASSWORD_VALUE_EXCEPTION(HttpStatus.BAD_REQUEST, "비밀번호는 영문과 특수문자 숫자를 포함하며 8자 이상이어야 합니다."),
PASSWORD_DISCORD_EXCEPTION(HttpStatus.NOT_FOUND, "현재 비밀번호가 일치하지 않습니다."),
PASSWORD_DUPLICATE_EXCEPTION(HttpStatus.CONFLICT, "같은 비밀번호는 사용할 수 없습니다."),
// Token Exception
EXPIRED_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "만료된 토큰입니다."),
EXPIRED_REFRESH_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, "만료된 토큰입니다. 회원가입을 다시 시도하십시오."),
NO_EXPIRED_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, "만료되지 않은 토큰입니다."),
MALFORED_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, "위조된 토큰입니다."),
NOT_FOUND_TOKEN_EXCEPTION(HttpStatus.NOT_FOUND, "비어있는 토큰입니다."),
// S3 Exception
S3_UPLOAD_FAIL_EXCEPTION(HttpStatus.BAD_REQUEST, "파일 업로드에 실패했습니다."),
INVALID_FILE_FORMAT_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 파일 형식입니다."),
Expand Down
2 changes: 0 additions & 2 deletions api/src/main/java/grooteogi/mapper/HashtagMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public interface HashtagMapper extends BasicMapper<HashtagDto, Hashtag> {
Hashtag toEntity(String name);

@Mappings({
@Mapping(source = "hashtag.id", target = "hashtagId"),
@Mapping(source = "hashtag.name", target = "name")
})
HashtagDto.Response toResponseDto(Hashtag hashtag);

@Mappings({
@Mapping(source = "postHashtag.id", target = "hashtagId"),
@Mapping(source = "hashtag.name", target = "name")
})
HashtagDto.Response toPostResponseDto(PostHashtag postHashtag, Hashtag hashtag);
Expand Down
23 changes: 13 additions & 10 deletions api/src/main/java/grooteogi/mapper/PostMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ Post toEntity(Request dto, User user, List<Schedule> schedules,
@Mapping(source = "schedules.place", target = "place")
ScheduleDto.Response toScheduleResponses(Schedule schedules);

@Mapping(source = "dto.title", target = "title")
@Mapping(source = "dto.content", target = "content")
@Mapping(source = "dto.creditType", target = "credit")
@Mapping(source = "dto.imageUrl", target = "imageUrl")
@Mapping(source = "schedules", target = "schedules")
@Mapping(source = "post.id", target = "id")
Post toModify(Post post, PostDto.Request dto, List<Schedule> schedules);

@Mapping(source = "user.id", target = "userId")
@Mapping(source = "user.nickname", target = "nickname")
@Mapping(source = "userInfo.imageUrl", target = "imageUrl", defaultValue = "")
UserDto.Response toUserResponse(User user, UserInfo userInfo);

default String asStringRegion(RegionType type) {
return type != null ? type.toString() : null;
}
Expand Down Expand Up @@ -119,15 +132,5 @@ default Time adTime(String time) {
}
}

@Mapping(source = "dto.title", target = "title")
@Mapping(source = "dto.content", target = "content")
@Mapping(source = "dto.creditType", target = "credit")
@Mapping(source = "dto.imageUrl", target = "imageUrl")
@Mapping(source = "post.schedules", target = "schedules", ignore = true)
Post toModify(Post post, PostDto.Request dto);

@Mapping(source = "user.id", target = "userId")
@Mapping(source = "user.nickname", target = "nickname")
@Mapping(source = "userInfo.imageUrl", target = "imageUrl", defaultValue = "")
UserDto.Response toUserResponse(User user, UserInfo userInfo);
}
3 changes: 1 addition & 2 deletions api/src/main/java/grooteogi/mapper/ReservationMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Reservation toEntity(Request dto, User user,
@Mapping(target = "startTime", dateFormat = "HH:mm:ss"),
@Mapping(target = "endTime", dateFormat = "HH:mm:ss"),
@Mapping(target = "postId", source = "post.id"),
@Mapping(target = "hostPhone", source = "hostPhone"),
@Mapping(target = "applyPhone", source = "applyPhone"),
@Mapping(target = "isCanceled", source = "reservation.isCanceled"),
@Mapping(target = "applyNickname", source = "applyNickname"),
Expand All @@ -50,7 +49,7 @@ Reservation toEntity(Request dto, User user,
})
ReservationDto.DetailResponse toDetailResponseDto(Reservation reservation,
Post post, Schedule schedule, Review review,
String hostPhone, String applyPhone, String applyNickname);
String applyPhone, String applyNickname);

@Mapping(source = "isCanceled", target = "isCanceled")
Reservation toModifyIsCanceled(Reservation reservation, boolean isCanceled);
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/grooteogi/mapper/UserInfoMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import grooteogi.domain.User;
import grooteogi.domain.UserInfo;
import grooteogi.dto.ProfileDto;
import grooteogi.dto.ProfileDto.Request;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
Expand All @@ -29,8 +30,8 @@ public interface UserInfoMapper extends BasicMapper<ProfileDto, UserInfo> {
@Mapping(source = "dto.imageUrl", target = "imageUrl"),
@Mapping(source = "dto.address", target = "address"),
@Mapping(source = "dto.phone", target = "contact"),
@Mapping(target = "id", ignore = true)
@Mapping(target = "id", source = "userInfo.id")
})
UserInfo toEntity(ProfileDto.Request dto);
UserInfo toEntity(Request dto, UserInfo userInfo);

}
3 changes: 0 additions & 3 deletions api/src/main/java/grooteogi/repository/PostRepository.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package grooteogi.repository;

import grooteogi.domain.Post;
import grooteogi.domain.User;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PostRepository extends JpaRepository<Post, Integer> {

Boolean existsByUser(User user);

Page<Post> findAllByTitleContainingOrContentContaining(String title,
String content, Pageable pageable);

Expand Down
18 changes: 10 additions & 8 deletions api/src/main/java/grooteogi/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ private User registerDto(OauthDto oauthDto) {
User user = new User();
BeanUtils.copyProperties(oauthDto, user);

return userRepository.save(user);
User registerUser = userRepository.save(user);
UserInfo userInfo = userInfoRepository.save(new UserInfo());

User modifiedUser = UserMapper.INSTANCE.toModify(registerUser,
registerUser.getNickname(), userInfo);

return userRepository.save(modifiedUser);
}

public void withdrawal(int userId) {
Expand Down Expand Up @@ -116,13 +122,9 @@ public void checkVerifyEmail(AuthDto.CheckEmailRequest request) {
}

public User oauth(OauthDto oauthDto) {
Optional<User> userEmail = userRepository.findByEmail(oauthDto.getEmail());
User user;
if (userEmail.isEmpty()) {
user = registerDto(oauthDto);
} else {
user = userEmail.get();
}
Optional<User> filteredUser = userRepository.findByEmail(oauthDto.getEmail());
User user = filteredUser.isEmpty()
? registerDto(oauthDto) : userRepository.save(filteredUser.get());

if (!user.getType().equals(oauthDto.getType())) {
throw new ApiException(ApiExceptionEnum.LOGIN_FAIL_EXCEPTION);
Expand Down
Loading

0 comments on commit 065fb0a

Please sign in to comment.