Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev backend #143

Merged
merged 20 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e0818f3
test: Database ๊ด€๋ จ test ์„ค์ •
yeonjy Jun 16, 2024
ce4a330
feat: RepositoryTest
yeonjy Jun 16, 2024
1fbdcd4
test: LoginTest ๊ฐ„์†Œํ™”
yeonjy Jun 16, 2024
5145f6c
chore: restAssured ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€
yeonjy Jun 16, 2024
34f5da9
remove: ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์˜์กด์„ฑ ์‚ญ์ œ
yeonjy Jun 16, 2024
e199d28
feat: News Builder ํ•ญ๋ชฉ ์ถ”๊ฐ€
yeonjy Jun 16, 2024
80e3bc1
remove: AuthTest ์‚ญ์ œ
yeonjy Jun 16, 2024
6131814
rename: message -> errorMessage
yeonjy Jun 16, 2024
2d4c2fd
test: Base Test ๊ตฌํ˜„
yeonjy Jun 16, 2024
5a170b8
refactor: createAccessToken private -> public
yeonjy Jun 16, 2024
279990b
test: NewsControllerTest ๊ตฌํ˜„
yeonjy Jun 16, 2024
2d9d3ed
test: NewsServiceTest ๊ตฌํ˜„
yeonjy Jun 16, 2024
2083652
test: NewsRepository Test ๊ตฌํ˜„
yeonjy Jun 16, 2024
753e4b2
remove: Notification entity ์‚ญ์ œ
yeonjy Jun 16, 2024
184ed5e
feat: test์šฉ application.yml
yeonjy Jun 16, 2024
d82f42b
Merge pull request #140 from tukcomCD2024/test/#54-backend-news
yeonjy Jun 16, 2024
c2596d1
feat: nickname ๋ณ€๊ฒฝ api AuthController๋กœ ์ด๋™
yeonjy Jun 17, 2024
c61f0bd
refactor: member update logic ์ˆ˜์ •
yeonjy Jun 17, 2024
de9d356
fix: user ์ •๋ณด ๋ชจ๋‘ ๋ฐ›๊ธฐ
yeonjy Jun 17, 2024
826ced8
Merge pull request #142 from tukcomCD2024/fix/#141-backend-kakao-login
yeonjy Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading