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

Revert 159 feat/#156 ios modifydebatelogic #160

Open
wants to merge 16 commits into
base: DeviOS
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
3879921
feat: ํ† ํฐ ๋ฐ”๋””์— ๋‹ด์•„์„œ ๋ณด๋‚ด๊ธฐ
yeonjy Jun 18, 2024
8105c84
feat: AuthApi ์ถ”๊ฐ€
yeonjy Jun 18, 2024
ab6f665
feat: DebateRoom ์ƒ์„ฑ ์‹œ, ํ† ๋ก ๋ฐฉ ์ •๋ณด ๋ฐ˜ํ™˜
yeonjy Jun 18, 2024
71d3b34
docs: Swagger ์„ค๋ช… ์ถ”๊ฐ€
yeonjy Jun 18, 2024
3c9e32d
fix: @Transactional ์ถ”๊ฐ€
yeonjy Jun 18, 2024
1dae21c
Merge pull request #151 from tukcomCD2024/feat/#150-backend-token-body
yeonjy Jun 18, 2024
a45bc62
fix: registerMember Transactional ์ถ”๊ฐ€
yeonjy Jun 18, 2024
a4f0ff9
fix: @Transactional ์ˆ˜์ •
yeonjy Jun 18, 2024
ec8031e
Merge pull request #152 from tukcomCD2024/Dev-backend
yeonjy Jun 18, 2024
330776f
feat : ์ตœ๊ทผ ์ฝ์€ ๋‰ด์Šค ์กฐํšŒ API ์—ฐ๋™ ์™„๋ฃŒ
yeahzxnn Jun 19, 2024
f69c2b5
fix : ChatGPT๊ฐ€ ์ฑ„ํŒ… ์‹œ์ž‘ํ•˜๋Š” ๋กœ์ง์œผ๋กœ ๋ณ€๊ฒฝ
yeahzxnn Jun 19, 2024
fbfb1eb
feat: ํ† ๋ก  ์ข…๋ฃŒ API ์—ฐ๊ฒฐ ๋ฐ ํ† ๋ก  ์š”์•ฝ ํ™”๋ฉด ๋„˜์–ด๊ฐ€๊ธฐ ๊ตฌํ˜„
yeahzxnn Jun 19, 2024
8b3e2a9
fix : ํ† ๋ก  ์ข…๋ฃŒ ํ›„ ๋‹ค์‹œ ์ด์ „ํ™”๋ฉด์œผ๋กœ ๋Œ์•„์˜ค๋Š” ๊ฒƒ์œผ๋กœ ๋กœ์ง ์ˆ˜์ •
yeahzxnn Jun 19, 2024
0f82def
feat: ์ฑ„ํŒ…๋ฐฉ ์กฐํšŒAPI ์—ฐ๋™ ์™„๋ฃŒ
yeahzxnn Jun 20, 2024
7681269
Merge pull request #159 from tukcomCD2024/Feat/#156_ios_modifydebatelโ€ฆ
yeahzxnn Jun 20, 2024
c30ed98
Revert "Feat/#156 ios modifydebatelogic"
yeahzxnn Jun 20, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rollthedice.backend.domain.bookmark.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -9,6 +10,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "์‚ฌ์šฉ์ž๊ฐ€ ๋ถ๋งˆํฌํ–ˆ๋Š”์ง€ ์—ฌ๋ถ€")
public class BookmarkResponse {
private Long id;
private Boolean isBookmarked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest;
import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -29,7 +30,7 @@ public interface DebateApi {
responseCode = "201",
description = "Created"
)
void saveDebateRoom(@RequestBody DebateRoomRequest request);
DebateRoomSaveResponse saveDebateRoom(@RequestBody DebateRoomRequest request);

@Operation(
summary = "ํ† ๋ก ๋ฐฉ ์ „์ฒด ์กฐํšŒ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest;
import com.rollthedice.backend.domain.debate.dto.response.DebateMessageResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse;
import com.rollthedice.backend.domain.debate.service.DebateMessageService;
import com.rollthedice.backend.domain.debate.service.DebateRoomService;
Expand All @@ -25,8 +26,8 @@ public class DebateController implements DebateApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("")
@Override
public void saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) {
debateRoomService.saveDebateRoom(request);
public DebateRoomSaveResponse saveDebateRoom(@RequestBody @Valid final DebateRoomRequest request) {
return debateRoomService.saveDebateRoom(request);
}

@ResponseStatus(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rollthedice.backend.domain.debate.entity.DebateMessage;
import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import com.rollthedice.backend.domain.debate.entity.SenderType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -12,6 +13,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "ํ† ๋ก  ๋ฉ”์„ธ์ง€ ์ƒ์„ฑ")
public class DebateMessageRequest {
private String message;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.rollthedice.backend.domain.debate.dto.request;

import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,6 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(description = "ํ† ๋ก ๋ฐฉ ์ƒ์„ฑ")
public class DebateRoomRequest {
private String topic;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rollthedice.backend.domain.debate.dto.response;

import com.rollthedice.backend.domain.debate.entity.SenderType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,7 +11,11 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "ํ† ๋ก  ๋‚ด์šฉ ์ €์žฅ")
public class DebateMessageResponse {
@Schema(description = "ํ† ๋ก  ๋ฉ”์„ธ์ง€ ๋‚ด์šฉ")
private String message;

@Schema(description = "์†ก์‹ ์ž์˜ ํƒ€์ž…์ž…๋‹ˆ๋‹ค. (HUMAN, AI)")
private SenderType senderType;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rollthedice.backend.domain.debate.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -9,8 +10,14 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "ํ† ๋ก ๋ฐฉ ์ •๋ณด")
public class DebateRoomResponse {
@Schema(description = "ํ† ๋ก ๋ฐฉ์˜ ID์ž…๋‹ˆ๋‹ค.")
private Long id;

@Schema(description = "ํ† ๋ก  ์ฃผ์ œ์ž…๋‹ˆ๋‹ค.")
private String topic;

@Schema(description = "ํ† ๋ก ์ด ์ข…๋ฃŒ๋˜์—ˆ๋Š”์ง€ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค.")
private Boolean isClosed;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.rollthedice.backend.domain.debate.dto.response;

import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Schema(description = "ํ† ๋ก ๋ฐฉ ์ƒ์„ฑ ๊ฒฐ๊ณผ")
public class DebateRoomSaveResponse {
@Schema(description = "ํ† ๋ก ๋ฐฉ์˜ ID์ž…๋‹ˆ๋‹ค.")
private Long id;

@Schema(description = "ํ† ๋ก  ์ฃผ์ œ์ž…๋‹ˆ๋‹ค.")
private String topic;

@Builder
public DebateRoomSaveResponse(DebateRoom debateRoom) {
this.id = debateRoom.getId();
this.topic = debateRoom.getTopic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "ํ† ๋ก  ์š”์•ฝ ๊ฒฐ๊ณผ")
public class DebateSummaryResponse {
Long roomId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void saveHumanDebateMessage(final Long roomId, DebateMessageRequest reque
debateMessageRepository.save(request.toHumanMessageEntity(getDebateRoom(roomId)));
}

@Transactional
public void saveAIDebateMessage(Long roomId, DebateMessageRequest request) {
debateMessageRepository.save(request.toAIMessageEntity(getDebateRoom(roomId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rollthedice.backend.domain.debate.dto.request.DebateRoomRequest;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateRoomSaveResponse;
import com.rollthedice.backend.domain.debate.dto.response.DebateSummaryResponse;
import com.rollthedice.backend.domain.debate.entity.DebateRoom;
import com.rollthedice.backend.domain.debate.exception.DebateRoomNotFoundException;
Expand All @@ -28,9 +29,11 @@ public class DebateRoomService {


@Transactional
public void saveDebateRoom(DebateRoomRequest request) {
public DebateRoomSaveResponse saveDebateRoom(DebateRoomRequest request) {
final Member member = authService.getMember();
debateRoomRepository.save(debateRoomMapper.toEntity(member, request));
DebateRoom debateRoom = debateRoomRepository
.save(debateRoomMapper.toEntity(member, request));
return DebateRoomSaveResponse.builder().debateRoom(debateRoom).build();
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface StatisticsApi {
summary = "์ตœ๊ทผ ์ผ์ฃผ์ผ ๋‚ ์งœ๋ณ„ ๋‰ด์Šค ์กฐํšŒ์ˆ˜ ์กฐํšŒ",
description = "์ตœ๊ทผ ์ผ์ฃผ์ผ๊ฐ„ ๋‚ ์งœ๋ณ„๋กœ ๋‰ด์Šค ์กฐํšŒ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"Statistics"}
tags = {"ํ†ต๊ณ„"}
)
@ApiResponse(
responseCode = "200",
Expand All @@ -25,7 +25,7 @@ public interface StatisticsApi {
summary = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์กฐํšŒ์ˆ˜ ์กฐํšŒ",
description = "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์กฐํšŒ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"Statistics"}
tags = {"ํ†ต๊ณ„"}
)
@ApiResponse(
responseCode = "200",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.rollthedice.backend.global.oauth2.api;

import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.global.oauth2.dto.LoginRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

public interface AuthApi {
@Operation(
summary = "์†Œ์…œ ๋กœ๊ทธ์ธ",
description = "์†Œ์…œ ๋กœ๊ทธ์ธ์„ ํ•ฉ๋‹ˆ๋‹ค. ํšŒ์›๊ฐ€์ž…์ด ๋˜์–ด์žˆ์ง€ ์•Š์€ ํšŒ์›์ผ ๊ฒฝ์šฐ, ํšŒ์›๊ฐ€์ž…์ด ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"์ธ์ฆ"}
)
@ApiResponse(
responseCode = "201",
description = "Created"
)
ResponseEntity<HttpStatus> login(
@RequestBody LoginRequest request,
HttpServletResponse response
);

@Operation(
summary = "๋‹‰๋„ค์ž„ ์ž…๋ ฅ",
description = "๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๋กœ์ง์ด ์ง„ํ–‰๋˜์–ด์•ผ ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋ฉ๋‹ˆ๋‹ค.",
security = {@SecurityRequirement(name = "access_token")},
tags = {"์ธ์ฆ"}
)
@ApiResponse(
responseCode = "201",
description = "Created"
)
ResponseEntity<HttpStatus> updateMember(
String email,
@RequestBody MemberUpdateDto memberUpdateDto
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rollthedice.backend.global.oauth2.controller;
package com.rollthedice.backend.global.oauth2.api;

import com.rollthedice.backend.domain.member.dto.MemberUpdateDto;
import com.rollthedice.backend.domain.member.service.MemberService;
Expand All @@ -17,17 +17,19 @@
@Slf4j
@RestController
@RequiredArgsConstructor
public class AuthController {
public class AuthController implements AuthApi {
private final AuthService authService;
private final MemberService memberService;

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

@PostMapping("/oauth2/sign-up")
@Override
public ResponseEntity<HttpStatus> updateMember(@LoginMemberEmail String email,
@RequestBody MemberUpdateDto memberUpdateDto) {
memberService.update(memberUpdateDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

Expand All @@ -26,6 +27,7 @@ public class AuthService {
private final OAuth2ProviderService oAuth2ProviderService;
private final JwtService jwtService;

@Transactional
public void authenticateOrRegisterUser(LoginRequest loginRequest, HttpServletResponse response) {
OAuth2UserInfo userInfo = oAuth2ProviderService.getUserInfo(loginRequest);
Member member = findOrElseRegisterMember(userInfo, loginRequest.getSocialType());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.rollthedice.backend.global.security.jwt.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(description = "AccessToken, RefreshToken ๋ฐ˜ํ™˜ ํฌ๋งท")
public class TokenResponse {
private String accessToken;
private String refreshToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rollthedice.backend.domain.member.repository.MemberRepository;
import com.rollthedice.backend.global.security.jwt.dto.TokenResponse;
import com.rollthedice.backend.global.security.jwt.refresh.service.RefreshTokenService;
import com.rollthedice.backend.global.security.jwt.exception.NotFoundEmailException;
import com.rollthedice.backend.global.security.jwt.exception.NotFoundTokenException;
Expand All @@ -15,6 +18,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Date;
import java.util.Optional;

Expand All @@ -30,6 +34,7 @@ public class JwtService {

private final MemberRepository memberRepository;
private final RefreshTokenService refreshTokenService;
private final ObjectMapper objectMapper;

@Value("${jwt.secret-key}")
private String secretKey;
Expand All @@ -43,12 +48,22 @@ public class JwtService {
private String refreshHeader;

public void sendAccessAndRefreshToken(HttpServletResponse response, String email) {
setTokenHeader(response, accessHeader, createAccessToken(email));

String accessToken = createAccessToken(email);
String refreshToken = createRefreshToken();

try {
String token = objectMapper.writeValueAsString(TokenResponse.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build());
response.getWriter().write(token);
} catch (IOException e) {
throw new RuntimeException(e);
}

setTokenHeader(response, accessHeader, accessToken);
setTokenHeader(response, refreshHeader, refreshToken);
refreshTokenService.updateToken(email, refreshToken);
log.info("Access Token, Refresh Token ํ—ค๋” ์„ค์ • ์™„๋ฃŒ");
}

public String createAccessToken(String email) {
Expand Down
Binary file modified iOS/RollTheDice/.DS_Store
Binary file not shown.
Loading