Skip to content

Commit

Permalink
Merge pull request #123 from 0702Yoon/main
Browse files Browse the repository at this point in the history
Swaager member, admin 분리
  • Loading branch information
0702Yoon authored Oct 2, 2024
2 parents fae3a57 + c663a13 commit c95fd16
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@RequiredArgsConstructor
public class AffiliationManger {
public class AffiliationManager {
private final AffiliationRepository affiliationRepository;
private final AffiliationMemberRepository affiliationMemberRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bigbrotherbe.domain.affiliation.service;

import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger;
import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManager;
import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse;
import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode;

Expand All @@ -18,13 +18,13 @@
@RequiredArgsConstructor
public class AffiliationServiceImpl implements AffiliationService {

private final AffiliationManger affiliationManger;
private final AffiliationManager affiliationManager;

private final String CollegeKoreanText = "단과대";

@Override
public boolean checkExistAffiliationById(Long affiliationId) {
return affiliationManger.existsById(affiliationId);
return affiliationManager.existsById(affiliationId);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bigbrotherbe.domain.member.component;

import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger;
import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManager;
import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto;
import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse;
import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse;
Expand Down Expand Up @@ -29,7 +29,7 @@ public class MemberManager {
private final MemberChecker memberChecker;
private final MemberDeleter memberDeleter;
private final MemberSaver memberSaver;
private final AffiliationManger affiliationManger;
private final AffiliationManager affiliationManager;


@Transactional(rollbackFor = Exception.class)
Expand All @@ -38,8 +38,8 @@ public MemberResponse userSignup(SignUpDto signUpDto) {
String encodePassword = passwordEncoder.encode(signUpDto.getPassword());
Member member = signUpDto.toEntity(encodePassword);
Member savedMember = memberSaver.saveMember(member);
AffiliationMember collegeMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getCollege(), Role.ROLE_USER);
AffiliationMember affiliationMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getAffiliation(),Role.ROLE_USER);
AffiliationMember collegeMember = affiliationManager.createAfiiliationMember(savedMember,signUpDto.getCollege(), Role.ROLE_USER);
AffiliationMember affiliationMember = affiliationManager.createAfiiliationMember(savedMember,signUpDto.getAffiliation(),Role.ROLE_USER);

return MemberResponse.form(
savedMember.getId(),
Expand All @@ -60,7 +60,7 @@ public JwtToken signIn(String email, String password) {

public AffiliationListDto getMemberAffiliationRoleList() {
Member member = authUtil.getLoginMember();
return affiliationListToEntity(member.getUsername(), affiliationManger.findAllByMemberId(member.getId()));
return affiliationListToEntity(member.getUsername(), affiliationManager.findAllByMemberId(member.getId()));
}

public Member getLoginMember() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,5 @@ public PasswordEncoder passwordEncoder() {
// BCrypt Encoder 사용
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
public static String getCurrentUserName(){
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication == null || authentication.getName() == null){
throw new RuntimeException("No authentication information");
}
return authentication.getName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,36 @@ public class SwaggerConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("My API")
.version("1.0")
.description("My API Description"))
.servers(List.of(
new Server().url(DOMAIN_URL) // HTTPS로 설정
.description("Production server")
))
.components(new Components()
.addSecuritySchemes("Authorization", new SecurityScheme()
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.name("Authorization")
))
.addSecurityItem(new SecurityRequirement().addList("Authorization"));
.info(apiInfo())
.servers(httpsServer())
.components(createComponents())
.addSecurityItem(createSecurityRequirement());
}

private static SecurityRequirement createSecurityRequirement() {
return new SecurityRequirement().addList("Authorization");
}

private static Components createComponents() {
return new Components()
.addSecuritySchemes("Authorization", new SecurityScheme()
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.name("Authorization")
);
}

private static List<Server> httpsServer() {
return List.of(
new Server().url(DOMAIN_URL) // HTTPS로 설정
.description("Production server")
);
}

private static Info apiInfo() {
return new Info().title("My API")
.version("1.0")
.description("My API Description");
}

@Bean
Expand All @@ -43,4 +59,20 @@ public GroupedOpenApi publicApi() {
.build();
}

@Bean
public GroupedOpenApi memberApi() {
return GroupedOpenApi.builder()
.group("멤버 API")
.pathsToMatch("/api/v1/members/**") // 멤버 관련 엔드포인트만 포함
.build();
}

@Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder()
.group("어드민 API")
.pathsToMatch("/api/v1/admin/**") // 관리자 관련 엔드포인트만 포함
.build();
}

}

0 comments on commit c95fd16

Please sign in to comment.