Skip to content

Commit

Permalink
Merge pull request #21 from Team-UMC/feature/#18/sign-up-api
Browse files Browse the repository at this point in the history
[FEAT] ํšŒ์›๊ฐ€์ž… API ๊ตฌํ˜„
  • Loading branch information
junseokkim authored Jan 18, 2024
2 parents ebbb81f + 2576ab7 commit 6317f68
Show file tree
Hide file tree
Showing 43 changed files with 727 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.httpBasic(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((authorizeRequests) ->
authorizeRequests
.requestMatchers("/staff/**").hasAnyRole("STAFF", "CENTERSTAFF", "BRANCHSTAFF", "CAMPUSSTAFF", "ADMIN")
.requestMatchers("/staff/**").hasAnyRole("STAFF", "TOTAL_STAFF", "CENTER_STAFF", "BRANCH_STAFF", "CAMPUS_STAFF", "ADMIN")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().permitAll()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.umc.networkingService.global.common.exception.RestApiException;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import com.umc.networkingService.global.common.enums.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import com.umc.networkingService.global.common.enums.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.umc.networkingService.domain.branch.entity;

import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Semester;
import com.umc.networkingService.global.common.enums.Semester;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.UuidGenerator;

Expand All @@ -14,6 +12,8 @@

@Getter
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor(access= AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
public class Branch extends BaseEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.base.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.UuidGenerator;

import java.util.UUID;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
public class BranchUniversity extends BaseEntity {
Expand All @@ -21,6 +21,10 @@ public class BranchUniversity extends BaseEntity {
@Column(name = "branch_university_id")
private UUID id;

// ํ˜„์žฌ ๊ธฐ์ˆ˜์ธ์ง€ ์—ฌ๋ถ€
@Column(nullable = false)
private Boolean isActive;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private Branch branch;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.networkingService.domain.branch.repository;

import com.umc.networkingService.domain.branch.entity.Branch;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.UUID;

public interface BranchRepository extends JpaRepository<Branch, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.umc.networkingService.domain.branch.repository;

import com.umc.networkingService.domain.branch.entity.BranchUniversity;
import com.umc.networkingService.domain.university.entity.University;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import java.util.UUID;

public interface BranchUniversityRepository extends JpaRepository<BranchUniversity, UUID> {

Optional<BranchUniversity> findByUniversityAndIsActive(University university, Boolean isActive);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.networkingService.domain.branch.service;

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.global.common.base.EntityLoader;

import java.util.UUID;

public interface BranchService extends EntityLoader<Branch, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.umc.networkingService.domain.branch.service;

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.branch.repository.BranchRepository;
import com.umc.networkingService.global.common.exception.ErrorCode;
import com.umc.networkingService.global.common.exception.RestApiException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
@RequiredArgsConstructor
public class BranchServiceImpl implements BranchService{

private final BranchRepository branchRepository;

@Override
public Branch loadEntity(UUID id) {
return branchRepository.findById(id)
.orElseThrow(() -> new RestApiException(ErrorCode.EMPTY_BRANCH));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.umc.networkingService.domain.branch.service;

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.university.entity.University;

public interface BranchUniversityService {
Branch findBranchByUniversity(University university);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.umc.networkingService.domain.branch.service;

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.branch.repository.BranchUniversityRepository;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.exception.ErrorCode;
import com.umc.networkingService.global.common.exception.RestApiException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class BranchUniversityServiceImpl implements BranchUniversityService {

private final BranchUniversityRepository branchUniversityRepository;

@Override
public Branch findBranchByUniversity(University university) {

return branchUniversityRepository.findByUniversityAndIsActive(university, Boolean.TRUE)
.orElseThrow(() -> new RestApiException(ErrorCode.EMPTY_BRANCH))
.getBranch();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Role;
import com.umc.networkingService.global.common.enums.Role;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.umc.networkingService.domain.member.controller;

import com.umc.networkingService.config.security.auth.CurrentMember;
import com.umc.networkingService.config.security.jwt.JwtTokenProvider;
import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest;
import com.umc.networkingService.domain.member.dto.response.MemberSignUpResponse;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.SocialType;
import com.umc.networkingService.domain.member.repository.MemberRepository;
import com.umc.networkingService.domain.member.service.MemberService;
import com.umc.networkingService.global.common.base.BaseResponse;
import com.umc.networkingService.global.common.enums.Role;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
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;

@Tag(name = "๋ฉค๋ฒ„ API", description = "๋ฉค๋ฒ„ ๊ด€๋ จ API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/members")
public class MemberController {

private final MemberService memberService;
@Operation(summary = "ํšŒ์›๊ฐ€์ž… API", description = "์ตœ์ดˆ ๋ฉค๋ฒ„ ์ •๋ณด๋ฅผ ๋“ฑ๋กํ•˜๋Š” API์ž…๋‹ˆ๋‹ค.")
@ApiResponses( value = {
@ApiResponse(responseCode = "COMMON200", description = "์„ฑ๊ณต"),
@ApiResponse(responseCode = "UNIVERSITY001", description = "๋Œ€ํ•™๊ต๋ช…์„ ์ž˜๋ชป ์ž…๋ ฅํ•˜์˜€์„ ๊ฒฝ์šฐ ๋ฐœ์ƒ"),
@ApiResponse(responseCode = "BRANCH001", description = "๋Œ€ํ•™๊ต๊ฐ€ ์ง€๋ถ€๋ž‘ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋ฐœ์ƒ")
})
@PostMapping
public BaseResponse<MemberSignUpResponse> signUp(@CurrentMember Member member,
@Valid @RequestBody MemberSignUpRequest request) {
return BaseResponse.onSuccess(memberService.signUp(member, request));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.umc.networkingService.domain.member.dto.request;

import com.umc.networkingService.global.common.enums.Part;
import com.umc.networkingService.global.common.enums.Semester;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MemberSignUpRequest {
@NotBlank(message = "์ด๋ฆ„์€ ํ•„์ˆ˜ ์ž…๋ ฅ๊ฐ’์ž…๋‹ˆ๋‹ค.")
private String name;
@NotBlank(message = "๋‹‰๋„ค์ž„์€ ํ•„์ˆ˜ ์ž…๋ ฅ๊ฐ’์ž…๋‹ˆ๋‹ค.")
private String nickname;
@Size(min = 1, message = "์ตœ์†Œ 1๊ฐœ์˜ ํŒŒํŠธ๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private List<Part> parts;
@Size(min = 1, message = "์ตœ์†Œ 1๊ฐœ์˜ ๊ธฐ์ˆ˜๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")
private List<Semester> semesters;
private String universityName;
private List<String> campusPositions;
private List<String> centerPositions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.networkingService.domain.member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.UUID;

@Getter
@AllArgsConstructor
public class MemberSignUpResponse {
private UUID memberId;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.umc.networkingService.domain.member.entity;

import com.umc.networkingService.domain.branch.entity.Branch;
import com.umc.networkingService.domain.member.dto.request.MemberSignUpRequest;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.base.BaseEntity;
import com.umc.networkingService.global.common.Part;
import com.umc.networkingService.global.common.Role;
import com.umc.networkingService.global.common.Semester;
import com.umc.networkingService.global.common.enums.Part;
import com.umc.networkingService.global.common.enums.Role;
import com.umc.networkingService.global.common.enums.Semester;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.UuidGenerator;

Expand All @@ -22,8 +20,11 @@

@Getter
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLRestriction("deleted_at is null")
@DynamicInsert
public class Member extends BaseEntity {
@Id
@UuidGenerator
Expand All @@ -33,23 +34,20 @@ public class Member extends BaseEntity {
private String clientId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name = "university_id")
@JoinColumn(name = "university_id")
private University university;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name = "branch_id")
@JoinColumn(name = "branch_id")
private Branch branch;

private String profileImage;

@Column(nullable = false)
@ColumnDefault("0")
private Long remainPoint;

@Column(nullable = false)
private String nickname;

@Column(nullable = false)
private String name;

private String statusMessage;
Expand All @@ -58,23 +56,31 @@ public class Member extends BaseEntity {
private SocialType socialType;

@Enumerated(EnumType.STRING)
@Builder.Default
@CollectionTable(name = "member_part", joinColumns = @JoinColumn(name = "member_id"))
@ElementCollection(fetch = FetchType.LAZY)
private List<Part> part = new ArrayList<>();

@Enumerated(EnumType.STRING)
@Builder.Default
@CollectionTable(name = "member_semester", joinColumns = @JoinColumn(name = "member_id"))
@ElementCollection(fetch = FetchType.LAZY)
private List<Semester> semester=new ArrayList<>();
private List<Semester> semester = new ArrayList<>();

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Role role;

@Enumerated(EnumType.STRING)
private Position position;

private String gitNickname;

private String notionLink;

public void setMemberInfo(MemberSignUpRequest request, Role role, University university, Branch branch) {
this.name = request.getName();
this.nickname = request.getNickname();
this.role = role;
this.university = university;
this.branch = branch;
this.part.addAll(request.getParts());
this.semester.addAll(request.getSemesters());
}
}
Loading

0 comments on commit 6317f68

Please sign in to comment.