-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Da2om/develop
Develop
- Loading branch information
Showing
147 changed files
with
3,650 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Dasom-api/src/main/java/com/project/dasomapi/auth/handler/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Dasom-api/src/main/java/com/project/dasomapi/auth/usecase/AuthUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Dasom-api/src/main/java/com/project/dasomapi/auth/usecase/req/LoginReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
Dasom-api/src/main/java/com/project/dasomapi/auth/usecase/req/ReissueReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
21 changes: 21 additions & 0 deletions
21
Dasom-api/src/main/java/com/project/dasomapi/chat/handler/ChatController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) 를 해당 채널을 구독하 클라이언트에게 메시지 전송 | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Dasom-api/src/main/java/com/project/dasomapi/chat/usecase/ChatMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
67 changes: 67 additions & 0 deletions
67
Dasom-api/src/main/java/com/project/dasomapi/child/handler/ChildController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
Dasom-api/src/main/java/com/project/dasomapi/child/usecase/ChildUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Dasom-api/src/main/java/com/project/dasomapi/child/usecase/req/ChildModifyReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Dasom-api/src/main/java/com/project/dasomapi/child/usecase/req/ChildRegisterReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Dasom-api/src/main/java/com/project/dasomapi/child/usecase/req/UploadChildImageReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
Dasom-api/src/main/java/com/project/dasomapi/common/Response.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.