Skip to content

Commit

Permalink
Merge pull request #10 from Da2om/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
heunseoRyu authored Oct 3, 2024
2 parents f6af784 + 9f9e3f8 commit 4d8dd39
Show file tree
Hide file tree
Showing 147 changed files with 3,650 additions and 8 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bin/
out/
!**/src/main/**/out/
!**/src/test/**/out/
application.yml

### NetBeans ###
/nbproject/private/
Expand Down
4 changes: 2 additions & 2 deletions Dasom-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

implementation 'org.springframework:spring-tx:6.0.6'
implementation 'org.springframework:spring-tx'
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
package com.project.dasomapi.auth.handler;

import com.project.dasomapi.auth.usecase.AuthUseCase;
import com.project.dasomapi.auth.usecase.req.LoginReq;
import com.project.dasomapi.auth.usecase.req.ReissueReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.auth.application.dto.Token;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth")
public class AuthController {
private final AuthUseCase authUseCase;

@PostMapping("/login")
public ResponseData<Token> login(@RequestBody @Valid LoginReq req){
return authUseCase.login(req);
}

@PostMapping("/reissue")
public Response reissue(@RequestBody @Valid ReissueReq req){
return authUseCase.reissue(req);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
package com.project.dasomapi.auth.usecase;

import com.project.dasomapi.auth.usecase.req.LoginReq;
import com.project.dasomapi.auth.usecase.req.ReissueReq;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.auth.application.PasswordEncoder;
import com.project.dasomcore.auth.application.dto.Token;
import com.project.dasomcore.auth.application.dto.res.ReissueRes;
import com.project.dasomcore.auth.domain.exception.ReissueTokenException;
import com.project.dasomcore.member.application.MemberService;
import com.project.dasomcore.member.domain.entity.Member;
import com.project.dasomcore.member.domain.exception.WrongPasswordException;
import com.project.dasominfra.token.TokenExtractor;
import com.project.dasominfra.token.TokenIssuer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class AuthUseCase {
private final PasswordEncoder encoder;
private final MemberService memberService;
private final TokenIssuer tokenIssuer;
private final TokenExtractor tokenExtractor;

public ResponseData<Token> login(LoginReq req){
Member member = memberService.getByUsername(req.username());
verifyPw(req.pw(),member.getPw());
Token token = tokenIssuer.issueToken(req.username(), member.getRole());
return ResponseData.ok("로그인 성공", token);
}

public ResponseData<ReissueRes> reissue(ReissueReq req){
try{
String username = tokenExtractor.getSubjectFromRefreshToken(req.refreshToken());
Member member = memberService.getByUsername(username);
final String accessToken = tokenIssuer.issueAccessToken(username, member.getRole());
return ResponseData.ok("토큰 재발급 성공",new ReissueRes(accessToken));
}catch(Exception e){
throw new ReissueTokenException();
}
}

private void verifyPw(String pw, String encodePw){
if (!encoder.matches(pw, encodePw)) throw new WrongPasswordException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.project.dasomapi.auth.usecase.req;

public record LoginReq(
String username,
String pw
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.project.dasomapi.auth.usecase.req;

public record ReissueReq(
String refreshToken
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.project.dasomapi.chat.handler;

import com.project.dasomapi.chat.usecase.ChatMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ChatController {

private final SimpMessageSendingOperations messagingTemplate;

@MessageMapping("/sendMessage") // 클라이언트가 "/app/sendMessage"로 메시지를 보내면 호출됨.
// @SendTo("/topic/public") // 해당 채널을 구독한 클라이언트에게 메시지 전송
public void sendMessage(ChatMessage message) {
messagingTemplate.convertAndSend("/topic/chat/room/" + message.getRoomId(), message);
// /topic/chat/room/{roomId} + payload 데이터(message) 를 해당 채널을 구독하 클라이언트에게 메시지 전송
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.dasomapi.chat.usecase;

import lombok.Data;

@Data
public class ChatMessage {
private String roomId;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.project.dasomapi.child.handler;

import com.project.dasomapi.child.usecase.ChildUseCase;
import com.project.dasomapi.child.usecase.req.ChildModifyReq;
import com.project.dasomapi.child.usecase.req.ChildRegisterReq;
import com.project.dasomapi.child.usecase.req.UploadChildImageReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.child.application.response.ChildRes;
import com.project.dasomcore.child.application.response.MyChildInfoRes;
import com.project.dasomapi.common.dto.PageRequest;
import com.project.dasomcore.child.application.response.UploadChildImageRes;
import com.project.dasomcore.member.domain.consts.MemberClass;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/child")
public class ChildController {
private final ChildUseCase childUseCase;

@PostMapping("/image")
public ResponseData<UploadChildImageRes> uploadChildImage(@RequestBody UploadChildImageReq req) {
return childUseCase.uploadImage(req);
}

@PostMapping
public Response register(@RequestBody @Valid ChildRegisterReq req){
return childUseCase.register(req);
}

@PatchMapping
public Response modify(@RequestBody @Valid ChildModifyReq req){
return childUseCase.modify(req);
}

@GetMapping("/my")
public ResponseData<List<MyChildInfoRes>> getMyChild(){
return childUseCase.getMyChild();
}

@GetMapping
public ResponseData<List<ChildRes>> getList(
@ModelAttribute PageRequest pageRequest
){
return childUseCase.getChildList(pageRequest);
}

@GetMapping("/class-list")
public ResponseData<List<ChildRes>> getListByClass(
@ModelAttribute PageRequest pageRequest,
@RequestParam MemberClass cls){
return childUseCase.getListByClass(pageRequest,cls);
}

@GetMapping("/search")
public ResponseData<List<ChildRes>> searchChild(
@ModelAttribute PageRequest pageRequest,
@RequestParam String name){
return childUseCase.searchChild(pageRequest,name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.project.dasomapi.child.usecase;

import com.project.dasomapi.child.usecase.req.ChildModifyReq;
import com.project.dasomapi.child.usecase.req.ChildRegisterReq;
import com.project.dasomapi.child.usecase.req.UploadChildImageReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.child.application.response.ChildRes;
import com.project.dasomcore.child.application.ChildService;
import com.project.dasomcore.child.application.response.MyChildInfoRes;
import com.project.dasomcore.child.application.response.UploadChildImageRes;
import com.project.dasomcore.child.domain.entity.Child;
import com.project.dasomapi.common.dto.PageRequest;
import com.project.dasomcore.member.application.MemberSessionHolder;
import com.project.dasomcore.member.domain.consts.MemberClass;
import com.project.dasomcore.member.domain.entity.Member;
import com.project.dasomcore.notice.application.service.AwsS3Service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class ChildUseCase {
private final ChildService childService;
private final MemberSessionHolder sessionHolder;
private final AwsS3Service awsS3Service;

public ResponseData<UploadChildImageRes> uploadImage(UploadChildImageReq req) {
String url = awsS3Service.upload(req.file(),"child_image");
UploadChildImageRes res = UploadChildImageRes.of(url);
return ResponseData.created("아이 사진 업로드 성공",res);
}

public Response register(ChildRegisterReq req){
childService.save(req.toEntity(sessionHolder.current()));
return Response.created("아이 등록 성공");
}

public Response modify(ChildModifyReq req){
Child child = childService.getById(req.id());
child.modify(req.toEntity());
childService.save(child);
return Response.created("아이 수정 성공");
}

public ResponseData<List<MyChildInfoRes>> getMyChild(){
Member member = sessionHolder.current();
List<MyChildInfoRes> childList = childService.getMyChildList(member);
return ResponseData.ok("내 아이 조회 성공", childList);
}

public ResponseData<List<ChildRes>> getChildList(PageRequest pageRequest){
pageRequest.validate();
List<ChildRes> res = childService.getChildResList(pageRequest.page(),pageRequest.size());
return ResponseData.ok("원아 전체리스트 조회 성공", res);
}

public ResponseData<List<ChildRes>> getListByClass(PageRequest pageRequest, MemberClass cls) {
pageRequest.validate();
List<ChildRes> res = childService.getChildResListByClass(pageRequest.page(),pageRequest.size(),cls);
return ResponseData.ok("반에 따른 원아 리스트 조회 성공",res);
}

public ResponseData<List<ChildRes>> searchChild(PageRequest pageRequest,String name) {
pageRequest.validate();
List<ChildRes> res = childService.getChildResListByName(pageRequest.page(),pageRequest.size(),name);
return ResponseData.ok("이름으로 원아 조회 성공",res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.project.dasomapi.child.usecase.req;

import com.project.dasomapi.common.util.DateUtil;
import com.project.dasomcore.child.domain.consts.BloodType;
import com.project.dasomcore.child.domain.consts.Gender;
import com.project.dasomcore.child.domain.entity.Child;

import java.time.LocalDate;

public record ChildModifyReq(
Long id,
String name,
String cls,
String gender,
LocalDate birthDt,
String bloodType,
Boolean isDisease,
String emergencyContactNumber,
String imageUrl
) {
public Child toEntity(){
return Child.builder()
.childName(name)
.birthDt(birthDt)
.cls(cls)
.gender(Gender.of(gender))
.bloodType(BloodType.of(bloodType))
.age(DateUtil.DtToYear(birthDt))
.isDisease(isDisease)
.emergencyContactNumber(emergencyContactNumber)
.imageUrl(imageUrl)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.project.dasomapi.child.usecase.req;

import com.project.dasomapi.common.util.DateUtil;
import com.project.dasomcore.child.domain.consts.BloodType;
import com.project.dasomcore.child.domain.consts.Gender;
import com.project.dasomcore.child.domain.entity.Child;
import com.project.dasomcore.member.domain.entity.Member;

import java.time.LocalDate;

public record ChildRegisterReq(
String name,
String cls,
String gender,
LocalDate birthDt,
String bloodType,
Boolean isDisease,
String emergencyContactNumber,
String imageUrl
) {
public Child toEntity(Member member){
return Child.builder()
.childName(name)
.birthDt(birthDt)
.cls(cls)
.gender(Gender.of(gender))
.bloodType(BloodType.of(bloodType))
.age(DateUtil.DtToYear(birthDt))
.isDisease(isDisease)
.emergencyContactNumber(emergencyContactNumber)
.imageUrl(imageUrl)
.member(member)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.project.dasomapi.child.usecase.req;

import org.springframework.web.multipart.MultipartFile;

public record UploadChildImageReq(MultipartFile file) {
}
29 changes: 29 additions & 0 deletions Dasom-api/src/main/java/com/project/dasomapi/common/Response.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.project.dasomapi.common;

import lombok.Builder;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@Builder
public class Response {

private int status;
private String message;

public static Response of(HttpStatus status, String message) {
return new Response(status.value(), message);
}

public static Response ok(String message) {
return new Response(HttpStatus.OK.value(), message);
}

public static Response created(String message) {
return new Response(HttpStatus.CREATED.value(), message);
}

public static Response noContent(String message) {
return new Response(HttpStatus.NO_CONTENT.value(), message);
}
}
Loading

0 comments on commit 4d8dd39

Please sign in to comment.