Skip to content

Commit

Permalink
Merge pull request #125 from ghdcksgml1/dev
Browse files Browse the repository at this point in the history
Merge Dev Branch
  • Loading branch information
ghdcksgml1 authored Nov 25, 2023
2 parents 737f801 + f8e77b0 commit 70273b7
Show file tree
Hide file tree
Showing 36 changed files with 1,837 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
// register
.requestMatchers("/auth/register").hasAnyAuthority("UNAUTH")
// Others
.anyRequest().hasAnyAuthority("USER", "CHEMIST", "CENTER")
.anyRequest().hasAnyAuthority("USER")
)
.sessionManagement((sessionManagement) ->
sessionManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication(scanBasePackages = "com.heachi", exclude = SecurityAutoConfiguration.class)
@EnableJpaAuditing // JPA Auditing 기능 활성화 - BaseEntity
public class HeachiHouseworkApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.heachi.housework.api.controller.group.info;

import com.heachi.admin.common.exception.HeachiException;
import com.heachi.admin.common.response.JsonResult;
import com.heachi.external.clients.auth.response.UserInfoResponse;
import com.heachi.housework.api.controller.group.info.request.GroupInfoRegisterRequest;
import com.heachi.housework.api.service.auth.AuthExternalService;
import com.heachi.housework.api.service.group.info.GroupInfoService;
import com.heachi.housework.api.service.group.info.request.GroupInfoUpdateServiceRequest;
import com.heachi.housework.api.service.group.info.response.GroupInfoUserGroupServiceResponse;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -81,4 +83,32 @@ public JsonResult<?> joinGroupRequestHandler(@RequestHeader(name = "Authorizatio

return JsonResult.successOf("그룹 가입 요청을 성공적으로 수행했습니다.");
}

@GetMapping("/update/{groupId}")
public JsonResult<?> updateGroupInfo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId) {

// 유저 인증 & 그룹장인지 권한 확인
authExternalService.userAuthenticateAndGroupLeaderMatch(authorization, groupId);

return JsonResult.successOf(groupInfoService.updateGroupInfoPage(groupId));

}

@PostMapping("/update/{groupId}")
public JsonResult<?> updateGroupInfo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId,
@Valid @RequestBody GroupInfoCreateRequest request) {

try {
// 유저 인증 & 그룹장인지 권한 확인
authExternalService.userAuthenticateAndGroupLeaderMatch(authorization, groupId);
groupInfoService.updateGroupInfo(GroupInfoUpdateServiceRequest.of(request, groupId));

return JsonResult.successOf("GroupInfo Update Success.");
} catch (HeachiException e) {
return JsonResult.failOf(e.getMessage());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import com.heachi.admin.common.exception.HeachiException;
import com.heachi.admin.common.response.JsonResult;
import com.heachi.housework.api.controller.housework.info.request.HouseworkInfoCreateRequest;
import com.heachi.housework.api.controller.housework.info.request.HouseworkInfoDeleteType;
import com.heachi.housework.api.service.auth.AuthExternalService;
import com.heachi.housework.api.service.housework.info.HouseworkInfoService;
import com.heachi.housework.api.service.housework.info.request.HouseworkInfoCreateServiceRequest;
import com.heachi.housework.api.service.housework.info.request.HouseworkInfoDeleteRequest;
import com.heachi.housework.api.service.housework.info.request.HouseworkInfoUpdateServiceRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/housework")
Expand All @@ -35,4 +40,59 @@ public JsonResult<?> createHouseworkInfo(@RequestHeader(name = "Authorization")
return JsonResult.failOf(e.getMessage());
}
}

@PostMapping("/delete/{groupId}")
public JsonResult<?> deleteHouseworkInfo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId,
@RequestParam(name = "date") LocalDate date,
@RequestParam(name = "todoId") Long todoId,
@RequestParam(name = "deleteType") HouseworkInfoDeleteType deleteType) {
try {
// 유저 인증 & 그룹원(ACCEPT)인지 권한 확인
authExternalService.userAuthenticateAndGroupMatch(authorization, groupId);
houseworkInfoService.deleteHouseworkInfo(
HouseworkInfoDeleteRequest.builder()
.groupId(groupId)
.date(date)
.todoId(todoId)
.deleteType(deleteType)
.build());

return JsonResult.successOf("Housework Delete Success.");
} catch (HeachiException e) {
return JsonResult.failOf(e.getMessage());
}

}

@GetMapping("/update/{groupId}")
public JsonResult<?> updateHouseworkInfo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId,
@RequestParam(name = "todoId") Long todoId) {
try {
// 유저 인증 & 그룹원(ACCEPT)인지 권한 확인
authExternalService.userAuthenticateAndGroupMatch(authorization, groupId);

return JsonResult.successOf(houseworkInfoService.updateHouseworkPage(todoId));
} catch (HeachiException e) {
return JsonResult.failOf(e.getMessage());
}
}

@PostMapping("/update/{groupId}")
public JsonResult<?> updateHouseworkInfo(@RequestHeader(name = "Authorization") String authorization,
@PathVariable(name = "groupId") Long groupId,
@RequestParam(name = "date") LocalDate date,
@RequestParam(name = "todoId") Long todoId,
@Valid @RequestBody HouseworkInfoCreateRequest request) {
try {
// 유저 인증 & 그룹원(ACCEPT)인지 권한 확인
authExternalService.userAuthenticateAndGroupMatch(authorization, groupId);
houseworkInfoService.updateHousework(HouseworkInfoUpdateServiceRequest.of(request, groupId, todoId, date));

return JsonResult.successOf("Housework Update Success.");
} catch (HeachiException e) {
return JsonResult.failOf(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.heachi.housework.api.controller.housework.info.request;

public enum HouseworkInfoDeleteType {
ALL, ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,25 @@ public UserInfoResponse userAuthenticateAndGroupMatch(String authorization, Long

return jsonResult.getResObj();
}

// Auth 서버에 인증 요청을 보낸 후 가져온 정보로 해당 그룹의 그룹장인지 판별한다.
public UserInfoResponse userAuthenticateAndGroupLeaderMatch(String authorization, Long groupId) {
JsonResult<UserInfoResponse> jsonResult = authClients.getUserInfo(authorization).block(); // Mono 객체이므로 Block

if (jsonResult.getResCode() != 200) {
log.warn(">>>> 유저 인증에 실패했습니다.");

throw new AuthException(ExceptionMessage.AUTH_SERVER_NOT_RESPOND);
}

// 그룹장인지 확인
if (!groupMemberRepository.isLeaderByUserEmailAndGroupInfoId(
jsonResult.getResObj().getEmail(), groupId)) {
log.warn(">>>> 해당 유저[{}]는 해당 그룹[{}]의 그룹장이 아닙니다.", jsonResult.getResObj().getEmail(), groupId);

throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_ROLE_NOT_ADMIN);
}

return jsonResult.getResObj();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.heachi.admin.common.exception.group.member.GroupMemberException;
import com.heachi.housework.api.controller.group.info.request.GroupInfoRegisterRequest;
import com.heachi.housework.api.controller.group.info.request.GroupInfoRegisterRequestStatusEnum;
import com.heachi.housework.api.service.group.info.request.GroupInfoUpdateServiceRequest;
import com.heachi.housework.api.service.group.info.response.GroupInfoUpdatePageResponse;
import com.heachi.housework.api.service.group.info.response.GroupInfoUserGroupServiceResponse;
import com.heachi.mysql.define.group.info.repository.GroupInfoRepository;
import com.heachi.mysql.define.group.info.repository.response.GroupInfoUserGroupResponse;
Expand All @@ -14,7 +16,6 @@
import com.heachi.admin.common.exception.user.UserException;
import com.heachi.housework.api.service.group.info.request.GroupInfoCreateServiceRequest;
import com.heachi.mysql.define.group.info.GroupInfo;
import com.heachi.mysql.define.group.info.repository.GroupInfoRepository;
import com.heachi.mysql.define.group.member.GroupMember;
import com.heachi.mysql.define.group.member.constant.GroupMemberRole;
import com.heachi.mysql.define.group.member.constant.GroupMemberStatus;
Expand All @@ -31,9 +32,6 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static com.heachi.mysql.define.group.info.QGroupInfo.groupInfo;
import static com.heachi.mysql.define.user.QUser.user;

@Slf4j
@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -200,4 +198,32 @@ public void joinRequestHandler(String adminEmail, GroupInfoRegisterRequest reque
requestGroupMember.refuseJoin();
}
}

public GroupInfoUpdatePageResponse updateGroupInfoPage(Long groupId) {
GroupInfo group = groupInfoRepository.findById(groupId).orElseThrow(() -> {
log.warn(">>>> 그룹 정보를 찾을 수 없습니다.");

throw new GroupInfoException(ExceptionMessage.GROUP_INFO_NOT_FOUND);
});

return GroupInfoUpdatePageResponse.of(group);

}

@Transactional
public void updateGroupInfo(GroupInfoUpdateServiceRequest request) {
Long groupId = request.getGroupId();

GroupInfo group = groupInfoRepository.findById(groupId).orElseThrow(() -> {
log.warn(">>>> 그룹 정보를 찾을 수 없습니다.");

throw new GroupInfoException(ExceptionMessage.GROUP_INFO_NOT_FOUND);
});

group.updateGroupInfo(request.getBgColor(),
request.getColorCode(),
request.getGradient(),
request.getName(),
request.getInfo());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.heachi.housework.api.service.group.info.request;

import com.heachi.housework.api.controller.group.info.request.GroupInfoCreateRequest;
import lombok.Builder;
import lombok.Getter;

@Getter
public class GroupInfoUpdateServiceRequest {
private Long groupId;
private String bgColor;
private String colorCode;
private String gradient;
private String name;
private String info;

@Builder
public GroupInfoUpdateServiceRequest(Long groupId, String bgColor, String colorCode, String gradient, String name, String info) {
this.groupId = groupId;
this.bgColor = bgColor;
this.colorCode = colorCode;
this.gradient = gradient;
this.name = name;
this.info = info;
}

public static GroupInfoUpdateServiceRequest of(GroupInfoCreateRequest request, Long groupId) {
return GroupInfoUpdateServiceRequest.builder()
.groupId(groupId)
.bgColor(request.getBgColor())
.colorCode(request.getColorCode())
.gradient(request.getGradient())
.name(request.getName())
.info(request.getInfo())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.heachi.housework.api.service.group.info.response;

import com.heachi.mysql.define.group.info.GroupInfo;
import jakarta.validation.constraints.NotEmpty;
import lombok.Builder;
import lombok.Getter;
import org.hibernate.validator.constraints.Length;

@Getter
public class GroupInfoUpdatePageResponse {
private String bgColor;
private String colorCode;
private String gradient;
private String name;
private String info;

@Builder
public GroupInfoUpdatePageResponse(String bgColor, String colorCode, String gradient, String name, String info) {
this.bgColor = bgColor;
this.colorCode = colorCode;
this.gradient = gradient;
this.name = name;
this.info = info;
}

public static GroupInfoUpdatePageResponse of(GroupInfo groupInfo) {
return GroupInfoUpdatePageResponse.builder()
.bgColor(groupInfo.getBgColor())
.colorCode(groupInfo.getColorCode())
.gradient(groupInfo.getGradient())
.name(groupInfo.getName())
.info(groupInfo.getInfo())
.build();

}

}
Loading

0 comments on commit 70273b7

Please sign in to comment.