Skip to content

Commit

Permalink
Merge pull request #16 from pagh2322/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pagh2322 authored Apr 18, 2024
2 parents 078a3e3 + 461a08a commit 49e3fdc
Show file tree
Hide file tree
Showing 175 changed files with 4,122 additions and 2,389 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
enabled = true
enabled = false

limit {
counter = 'BRANCH'
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.mockInvestment.auth.controller;
package org.mockInvestment.auth.api;

import org.mockInvestment.auth.dto.AuthInfo;
import org.mockInvestment.support.auth.Login;
import org.mockInvestment.global.auth.Login;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/oauth")
public class AuthController {
public class AuthApi {

@GetMapping("/loginInfo")
public ResponseEntity<AuthInfo> oauthLoginInfo(@Login AuthInfo authInfo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mockInvestment.auth.service;
package org.mockInvestment.auth.application;

import lombok.RequiredArgsConstructor;
import org.mockInvestment.member.domain.Member;
import org.mockInvestment.member.repository.MemberRepository;
import org.mockInvestment.auth.dto.AuthInfo;
Expand All @@ -11,19 +12,18 @@
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
@RequiredArgsConstructor
public class AuthService extends DefaultOAuth2UserService {

private final MemberRepository memberRepository;


public AuthService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oAuth2User = super.loadUser(userRequest);
Expand All @@ -40,19 +40,17 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
}

private Member getOrCreateMember(OAuth2UserAttributes oAuth2UserAttributes) {
Optional<Member> member = memberRepository.findByUsername(oAuth2UserAttributes.getUsername());
if (member.isEmpty()) {
Member newMember = Member.builder()
.name(oAuth2UserAttributes.getName())
.email(oAuth2UserAttributes.getEmail())
.role("ROLE_USER")
.username(oAuth2UserAttributes.getUsername())
.build();
return memberRepository.save(newMember);
}
member.get().setEmail(oAuth2UserAttributes.getEmail());
member.get().setName(oAuth2UserAttributes.getName());
return member.get();
Member member = memberRepository.findByUsername(oAuth2UserAttributes.getUsername())
.orElseGet(() -> {
Member newMember = Member.builder()
.role("ROLE_USER")
.username(oAuth2UserAttributes.getUsername())
.build();
return memberRepository.save(newMember);
});
member.updateEMail(oAuth2UserAttributes.getEmail());
member.updateName(oAuth2UserAttributes.getName());
return member;
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.mockInvestment.balance.controller;
package org.mockInvestment.balance.api;

import lombok.RequiredArgsConstructor;
import org.mockInvestment.auth.dto.AuthInfo;
import org.mockInvestment.balance.dto.CurrentBalanceResponse;
import org.mockInvestment.balance.service.BalanceService;
import org.mockInvestment.support.auth.Login;
import org.mockInvestment.balance.application.BalanceService;
import org.mockInvestment.global.auth.Login;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BalanceController {
@RequiredArgsConstructor
public class BalanceApi {

private final BalanceService balanceService;


public BalanceController(BalanceService balanceService) {
this.balanceService = balanceService;
}

@GetMapping("/balance/me")
public ResponseEntity<CurrentBalanceResponse> findBalance(@Login AuthInfo authInfo) {
CurrentBalanceResponse response = balanceService.findBalance(authInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mockInvestment.balance.service;
package org.mockInvestment.balance.application;

import org.mockInvestment.advice.exception.MemberNotFoundException;
import lombok.RequiredArgsConstructor;
import org.mockInvestment.member.exception.MemberNotFoundException;
import org.mockInvestment.auth.dto.AuthInfo;
import org.mockInvestment.balance.dto.CurrentBalanceResponse;
import org.mockInvestment.member.domain.Member;
Expand All @@ -10,15 +11,12 @@

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class BalanceService {

private final MemberRepository memberRepository;


public BalanceService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

public CurrentBalanceResponse findBalance(AuthInfo authInfo) {
Member member = memberRepository.findById(authInfo.getId())
.orElseThrow(MemberNotFoundException::new);
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/org/mockInvestment/balance/domain/Balance.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.mockInvestment.balance.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.mockInvestment.advice.exception.PaymentFailureException;
import org.mockInvestment.balance.exception.PaymentFailureException;
import org.mockInvestment.member.domain.Member;

@Entity
@NoArgsConstructor
@Table(name = "balance")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Balance {

@Id
Expand All @@ -26,19 +28,23 @@ public Balance(Member member) {
balance = 1000000.0;
}

public void purchase(Double price) {
if (balance - price < 0) {
public void pay(Double price) {
if (balance - price < 0)
throw new PaymentFailureException();
}

balance -= price;
}

public void cancelPayment(Double price) {
public void receive(Double price) {
balance += price;
}

public double getBalance() {
return balance;
}

public void reset() {
balance = 1000000.0;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.mockInvestment.advice.exception;
package org.mockInvestment.balance.exception;

import org.mockInvestment.advice.exception.general.BadRequestException;
import org.mockInvestment.global.error.exception.general.BadRequestException;

public class PaymentFailureException extends BadRequestException {

Expand Down
87 changes: 87 additions & 0 deletions src/main/java/org/mockInvestment/comment/api/CommentApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.mockInvestment.comment.api;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.mockInvestment.auth.dto.AuthInfo;
import org.mockInvestment.comment.application.*;
import org.mockInvestment.comment.dto.request.CommentUpdateRequest;
import org.mockInvestment.comment.dto.request.NewCommentReportRequest;
import org.mockInvestment.comment.dto.request.NewCommentRequest;
import org.mockInvestment.comment.dto.response.CommentLikeToggleResponse;
import org.mockInvestment.comment.dto.response.CommentsResponse;
import org.mockInvestment.global.auth.Login;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class CommentApi {

private final CommentFindService commentFindService;

private final CommentCreateService commentCreateService;

private final CommentReportCreateService commentReportCreateService;

private final CommentUpdateService commentUpdateService;

private final CommentDeleteService commentDeleteService;

private final CommentLikeToggleService commentLikeToggleService;


@GetMapping("/stocks/{code}/comments")
public ResponseEntity<CommentsResponse> findComments(@PathVariable("code") String stockCode,
@Login AuthInfo authInfo) {
CommentsResponse response = commentFindService.findCommentsByCode(authInfo, stockCode);
return ResponseEntity.ok(response);
}

@PostMapping("/stocks/{code}/comments")
public ResponseEntity<Void> addComment(@Login AuthInfo authInfo,
@PathVariable("code") String stockCode,
@RequestBody NewCommentRequest request) {
commentCreateService.addComment(authInfo, stockCode, request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PostMapping("/comments/{id}/report")
public ResponseEntity<Void> reportComment(@PathVariable("id") Long commentId,
@Valid @RequestBody NewCommentReportRequest request,
@Login AuthInfo authInfo) {
commentReportCreateService.reportComment(commentId, request, authInfo);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PostMapping("/comments/{id}/reply")
public ResponseEntity<Void> addReply(@PathVariable("id") Long commentId,
@RequestBody NewCommentRequest request,
@Login AuthInfo authInfo) {
commentCreateService.addReply(authInfo, commentId, request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PutMapping("/comments/{id}")
public ResponseEntity<Void> updateComment(@PathVariable("id") Long commentId,
@Valid @RequestBody CommentUpdateRequest request,
@Login AuthInfo authInfo) {
commentUpdateService.updateComment(commentId, request, authInfo);
return ResponseEntity.noContent().build();
}

@DeleteMapping("/comments/{id}")
public ResponseEntity<Void> deleteComment(@PathVariable("id") Long commentId,
@Login AuthInfo authInfo) {
commentDeleteService.deleteComment(authInfo, commentId);
return ResponseEntity.noContent().build();
}

@PutMapping("/comments/{id}/like")
public ResponseEntity<CommentLikeToggleResponse> toggleCommentLike(@PathVariable("id") Long commentId,
@Login AuthInfo authInfo) {
CommentLikeToggleResponse response = commentLikeToggleService.toggleCommentLike(authInfo, commentId);
return ResponseEntity.ok(response);
}

}
Loading

0 comments on commit 49e3fdc

Please sign in to comment.