Skip to content

Commit

Permalink
Merge pull request #97 from tukcomCD2024/Dev-backend
Browse files Browse the repository at this point in the history
Dev backend
  • Loading branch information
yeonjy authored Apr 30, 2024
2 parents 9d1c348 + 5a81b46 commit 140e629
Show file tree
Hide file tree
Showing 38 changed files with 655 additions and 343 deletions.
8 changes: 8 additions & 0 deletions backend/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ repositories {
}

dependencies {
if (isAppleSilicon()) {
runtimeOnly("io.netty:netty-resolver-dns-native-macos:4.1.94.Final:osx-aarch_64")
}
implementation 'com.auth0:java-jwt:4.2.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
Expand All @@ -37,6 +40,7 @@ dependencies {
implementation 'org.jsoup:jsoup:1.15.3'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.3.1.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
Expand All @@ -52,3 +56,7 @@ tasks.named('bootBuildImage') {
tasks.named('test') {
useJUnitPlatform()
}

def boolean isAppleSilicon() {
return System.getProperty("os.name") == "Mac OS X" && System.getProperty("os.arch") == "aarch64"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableJpaAuditing
@EnableScheduling
@SpringBootApplication
public class BackendApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.rollthedice.backend.domain.bookmark.entity.Bookmark;
import com.rollthedice.backend.domain.bookmark.repository.BookmarkRepository;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.query.AuthService;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.domain.news.dto.response.NewsResponse;
import com.rollthedice.backend.domain.news.entity.News;
import com.rollthedice.backend.domain.news.mapper.NewsMapper;
import com.rollthedice.backend.domain.news.repository.NewsRepository;
import com.rollthedice.backend.domain.news.service.NewsService;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.rollthedice.backend.domain.debate.mapper.DebateRoomMapper;
import com.rollthedice.backend.domain.debate.repository.DebateRoomRepository;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.query.AuthService;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
package com.rollthedice.backend.domain.member.controller;

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.service.MemberService;
import com.rollthedice.backend.global.annotation.LoginMemberEmail;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("members")
public class MemberController {
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("")
public MemberResponse getMemberInfo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.rollthedice.backend.domain.member.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class MemberServiceDto {
private String email;
private String nickname;
private String imageUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rollthedice.backend.domain.member.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
@Schema(description = "멤버 업데이트 포맷")
public class MemberUpdateDto {
@Schema(description = "변경할 닉네임")
private String nickname;
@Schema(description = "변경할 이미지 S3 Url")
private String imageUrl;

public MemberServiceDto toServiceDto(String email) {
return MemberServiceDto.builder()
.email(email)
.nickname(this.nickname)
.imageUrl(this.imageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rollthedice.backend.domain.member.entity;

import com.rollthedice.backend.domain.member.dto.MemberServiceDto;
import com.rollthedice.backend.global.config.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;
Expand Down Expand Up @@ -29,10 +30,10 @@ public class Member extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private Status status;

public Member update(String email, String imageUrl) {
this.email = email;
this.imageUrl = imageUrl;
return this;
public void update(MemberServiceDto dto) {
this.email = dto.getEmail();
this.imageUrl = dto.getImageUrl();
this.nickname = dto.getNickname();
}

public void signUp(String nickname) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package com.rollthedice.backend.domain.member.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum SocialType {
APPLE,
KAKAO
APPLE("https://"),
KAKAO("https://kapi.kakao.com/v2/user/me");


private final String providerUrl;

@JsonCreator
public static SocialType from(String s) {
return SocialType.valueOf(s.toUpperCase());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String email);

Optional<Member> findBySocialTypeAndOauthId(SocialType socialType, String oauthId);

boolean existsMemberByNickname(String nickname);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.rollthedice.backend.domain.member.service;

import com.rollthedice.backend.domain.member.dto.MemberServiceDto;
import com.rollthedice.backend.domain.member.dto.SignUpDto;
import com.rollthedice.backend.domain.member.dto.response.MemberResponse;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.query.AuthService;
import com.rollthedice.backend.global.jwt.refresh.service.RefreshTokenService;
import com.rollthedice.backend.global.jwt.service.JwtService;
import com.rollthedice.backend.domain.member.repository.MemberRepository;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.global.security.jwt.refresh.service.RefreshTokenService;
import com.rollthedice.backend.global.security.jwt.service.JwtService;
import jakarta.persistence.EntityNotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,15 +23,22 @@ public class MemberService {
private final JwtService jwtService;
private final HttpServletRequest request;
private final HttpServletResponse response;
private final MemberRepository memberRepository;


@Transactional(readOnly = true)
public boolean isDuplicatedNickname(MemberServiceDto memberServiceDto) {
return memberRepository.existsMemberByNickname(memberServiceDto.getNickname());
}

@Transactional
public void signUp(SignUpDto dto) {
Member member = authService.getMember();
member.signUp(dto.getNickname());
public void update(MemberServiceDto memberServiceDto) {
findByEmail(memberServiceDto.getEmail()).update(memberServiceDto);
}

String refreshToken = jwtService.createRefreshToken();
jwtService.setRefreshTokenHeader(response, refreshToken);
refreshTokenService.updateToken(member.getEmail(), refreshToken);
@Transactional(readOnly = true)
public Member findByEmail(String email) {
return memberRepository.findByEmail(email).orElseThrow(EntityNotFoundException::new);
}

public MemberResponse getMemberInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.rollthedice.backend.domain.bookmark.service.BookmarkService;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.query.AuthService;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.domain.news.contentqueue.ContentProducer;
import com.rollthedice.backend.domain.news.dto.ContentMessageDto;
import com.rollthedice.backend.domain.news.dto.NewsUrlDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.rollthedice.backend.global.advice;

import com.rollthedice.backend.global.jwt.exception.NotFoundTokenException;
import com.rollthedice.backend.global.security.jwt.exception.NotFoundTokenException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rollthedice.backend.global.annotation;

import java.lang.annotation.*;


@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LoginMemberEmail {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.rollthedice.backend.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaAuditingConfig {
}
Loading

0 comments on commit 140e629

Please sign in to comment.