Skip to content

Commit

Permalink
Merge pull request #143 from tukcomCD2024/Dev-backend
Browse files Browse the repository at this point in the history
Dev backend
  • Loading branch information
yeonjy authored Jun 17, 2024
2 parents 63a880b + 826ced8 commit 0e1a3ad
Show file tree
Hide file tree
Showing 27 changed files with 668 additions and 224 deletions.
1 change: 1 addition & 0 deletions backend/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'io.rest-assured:rest-assured:5.1.1'
}

tasks.named('bootBuildImage') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
public class MemberController implements MemberApi{
private final MemberService memberService;

@PostMapping("")
public ResponseEntity<HttpStatus> updateMember(@LoginMemberEmail String email,
@RequestBody MemberUpdateDto memberUpdateDto) {
MemberServiceDto memberServiceDto = memberUpdateDto.toServiceDto(email);

if (memberService.isDuplicatedNickname(memberServiceDto)) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
memberService.update(memberServiceDto);

return ResponseEntity.status(HttpStatus.OK).build();
}

@ResponseStatus(HttpStatus.OK)
@GetMapping("")
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rollthedice.backend.domain.member.service;

import com.rollthedice.backend.domain.member.dto.MemberServiceDto;
import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.domain.member.dto.response.MemberResponse;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.exception.MemberNotFoundException;
Expand All @@ -11,9 +12,11 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@RequiredArgsConstructor
@Service
public class MemberService {
Expand All @@ -27,8 +30,9 @@ public boolean isDuplicatedNickname(MemberServiceDto memberServiceDto) {
}

@Transactional
public void update(MemberServiceDto memberServiceDto) {
findByEmail(memberServiceDto.getEmail()).update(memberServiceDto);
public void update(MemberUpdateDto memberUpdateDto) {
Member loginMember = authService.getMember();
loginMember.signUp(memberUpdateDto.getNickname());
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.rollthedice.backend.domain.news.api;

import com.rollthedice.backend.domain.crawling.NewsCrawlingService;
import com.rollthedice.backend.domain.news.dto.response.NewsDetailResponse;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.dto.response.ReadNewsResponse;
Expand All @@ -19,7 +18,6 @@
public class NewsController implements NewsApi {
private final NewsService newsService;
private final ReadNewsService readNewsService;
private final NewsCrawlingService crawlingService;

@ResponseStatus(HttpStatus.OK)
@GetMapping("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.rollthedice.backend.global.config.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.ColumnDefault;

Expand All @@ -31,9 +28,14 @@ public class News extends BaseTimeEntity {
private long views;

@Builder
public News(String url, String thumbnailUrl) {
public News(Long id, String url, String thumbnailUrl, String title, String content, String category, String postDate) {
this.id = id;
this.url = url;
this.thumbnailUrl = thumbnailUrl;
this.title = title;
this.content = content;
this.category = category;
this.postDate = postDate;
}

public void addNewsBody(String title, String content, String category, String postDate) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public enum ErrorCode {


private final HttpStatus status;
private final String message;
private final String errorMessage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
import lombok.Getter;
import org.springframework.http.HttpStatus;

import java.util.Collections;

@Getter
public class ErrorResponse {
private HttpStatus status;
private String message;
private final HttpStatus status;
private final String errorMessage;

public ErrorResponse(HttpStatus status, String message) {
public ErrorResponse(HttpStatus status, String errorMessage) {
this.status = status;
this.message = message;
this.errorMessage = errorMessage;
}

public static ErrorResponse create(final ErrorCode errorCode) {
return new ErrorResponse(
errorCode.getStatus(),
errorCode.getMessage()
errorCode.getErrorMessage()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected ResponseEntity<ErrorResponse> handleRuntimeException(BusinessException
return ResponseEntity
.status(errorCode.getStatus())
.body(new ErrorResponse(errorCode.getStatus(),
errorCode.getMessage()));
errorCode.getErrorMessage()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class BusinessException extends RuntimeException{
private final ErrorCode errorCode;

public BusinessException(ErrorCode errorCode) {
super(errorCode.getMessage());
super(errorCode.getErrorMessage());
this.errorCode = errorCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Member toEntity(SocialType socialType, OAuth2UserInfo oauth2UserInfo) {
.email(oauth2UserInfo.getEmail())
.nickname(oauth2UserInfo.getNickname())
.imageUrl(oauth2UserInfo.getImageUrl())
.role(Role.GUEST)
.role(Role.USER)
.status(Status.ACTIVE)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package com.rollthedice.backend.global.oauth2.controller;

import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.domain.member.service.MemberService;
import com.rollthedice.backend.global.annotation.LoginMemberEmail;
import com.rollthedice.backend.global.oauth2.dto.LoginRequest;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;
private final MemberService memberService;

@PostMapping("/login")
public ResponseEntity<HttpStatus> login(@RequestBody LoginRequest request, HttpServletResponse response) {
authService.authenticateOrRegisterUser(request, response);
return new ResponseEntity<>(HttpStatus.OK);
}

@PostMapping("/oauth2/sign-up")
public ResponseEntity<HttpStatus> updateMember(@LoginMemberEmail String email,
@RequestBody MemberUpdateDto memberUpdateDto) {
memberService.update(memberUpdateDto);

return ResponseEntity.status(HttpStatus.OK).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) {
Member member = Member.builder()
.socialType(socialType)
.oauthId(userInfo.getId())
.email(UUID.randomUUID() + "@socialUser.com")
.nickname(String.valueOf(UUID.randomUUID()))
.email(userInfo.getEmail())
.nickname(userInfo.getNickname())
.imageUrl(userInfo.getImageUrl())
.role(Role.USER)
.build();
Expand All @@ -51,10 +51,9 @@ private Member registerMember(SocialType socialType, OAuth2UserInfo userInfo) {
}

public Member getMember() {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
return memberRepository.findByEmail(userDetails.getUsername()).orElseThrow(MemberNotFoundException::new);
String username = authentication.getName();
return memberRepository.findByEmail(username).orElseThrow(MemberNotFoundException::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void sendAccessAndRefreshToken(HttpServletResponse response, String email
log.info("Access Token, Refresh Token 헤더 설정 완료");
}

private String createAccessToken(String email) {
public String createAccessToken(String email) {
Date now = new Date();
return JWT.create()
.withSubject(ACCESS_TOKEN_SUBJECT)
Expand Down

This file was deleted.

Loading

0 comments on commit 0e1a3ad

Please sign in to comment.