Skip to content

Commit

Permalink
Merge pull request #7 from Kusitms-28th-Hackathon-D/feat/qogustj
Browse files Browse the repository at this point in the history
feat : aws 버킷에 파일 업로드
  • Loading branch information
eckrin authored Oct 7, 2023
2 parents 5929793 + bc306fd commit ba80b06
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/groupD/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@EnableJpaAuditing
@SpringBootApplication
public class ServerApplication {
static {
System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true");
}
//12
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/swagger-ui/**",
"/swagger/**",
"/error",
"/auth/**"
"/auth/**",
"/image"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public void signUp(@Valid @RequestBody SignUpRequestDto dto) {
public SignInResponseDto signIn(@Valid @RequestBody SignInRequestDto dto) {
return authService.signIn(dto.getEmail(), dto.getPassword());
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/groupD/server/controller/GroupController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.groupD.server.controller;

import com.groupD.server.domain.dto.GroupRequest;
import com.groupD.server.service.GroupService;
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;

@RequiredArgsConstructor
@RequestMapping("/group")
@RestController
public class GroupController {

private final GroupService groupService;
@PostMapping("/write")
public void write(@RequestBody GroupRequest request) {
groupService.write(request);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/groupD/server/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.groupD.server.controller;

import com.groupD.server.domain.dto.GroupRequest;
import com.groupD.server.domain.dto.GroupResponse;
import com.groupD.server.domain.entity.Group;
import com.groupD.server.security.Auth;
import com.groupD.server.security.AuthInfo;
import com.groupD.server.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping("/members")
public class MemberController {
private final MemberService memberService;


@GetMapping("/groups")
public List<GroupResponse> getGroupsByMemberId(@Auth AuthInfo authInfo) {
List<GroupResponse> groups = memberService.getGroupsByAuthInfo(authInfo);
return groups;
}
}

30 changes: 30 additions & 0 deletions src/main/java/com/groupD/server/controller/S3Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.groupD.server.controller;

import com.groupD.server.domain.dto.SignUpRequestDto;
import com.groupD.server.security.Auth;
import com.groupD.server.security.AuthInfo;
import com.groupD.server.service.S3Uploader;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@RestController
public class S3Controller {
private final S3Uploader s3Uploader;

@PostMapping("/image")
public ResponseEntity<SignUpRequestDto> updateUserImage(@Auth AuthInfo authInfo, @RequestPart("file") MultipartFile multipartFile) {
try {
s3Uploader.uploadFiles(multipartFile, "static");
} catch (Exception e) {
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@RequiredArgsConstructor
@RequestMapping("/api/sample")
@RestController

public class SampleController {
private final SampleService sampleService;

Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/groupD/server/domain/dto/GroupRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.groupD.server.domain.dto;


import com.groupD.server.domain.PreferJob;
import com.groupD.server.domain.entity.Group;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class GroupRequest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;
private String content;
private String manage;
private String date;
@Enumerated(EnumType.STRING)
private PreferJob category;
private String code;

public GroupRequest(Group group) {
this.id=group.getId();
this.category=group.getCategory();
this.code=group.getCode();
this.date=group.getDate();
this.manage=group.getManage();
this.content=group.getContent();
this.title=group.getTitle();
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/groupD/server/domain/dto/GroupResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.groupD.server.domain.dto;

import com.groupD.server.domain.PreferJob;
import com.groupD.server.domain.entity.Group;

import javax.persistence.*;

public class GroupResponse {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;
private String content;
private String manage;
private String date;
@Enumerated(EnumType.STRING)
private PreferJob category;
private String code;

public GroupResponse(Group group) {
this.id=group.getId();
this.category=group.getCategory();
this.code=group.getCode();
this.date=group.getDate();
this.manage=group.getManage();
this.content=group.getContent();
this.title=group.getTitle();
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/groupD/server/domain/entity/Group.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.groupD.server.domain.entity;

import com.groupD.server.domain.PreferJob;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "groups")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Group{
@Id
@Column(name ="group_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotBlank
private String title;
@NotBlank
private String content;
@NotBlank
private String manage;
@NotBlank
private String date;
@Enumerated(EnumType.STRING)
private PreferJob category;
@NotBlank
private String code;


}
1 change: 1 addition & 0 deletions src/main/java/com/groupD/server/domain/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@NoArgsConstructor
public class Member extends DateEntity {
@Id
@Column(name ="member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/groupD/server/domain/entity/MemberGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.groupD.server.domain.entity;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;

@Table(name = "member_group")
@Entity
@Getter
@Setter
public class MemberGroup {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_group_id")
private Long id;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne
@JoinColumn(name = "group_id")
private Group group;


// Getter, Setter, Constructor
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -21,7 +22,7 @@ public class S3Config {
private String secretKey = "JXb54LrFR8mnBStkh592ZJY4CONnEB0xyw7QwHLH";
private String region = "ap-northeast-2";

@Bean
@Autowired
public AmazonS3 amazonS3() {
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);
return AmazonS3ClientBuilder
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/groupD/server/repository/GroupRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.groupD.server.repository;

import com.groupD.server.domain.entity.Group;
import com.groupD.server.domain.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface GroupRepository extends JpaRepository<Group, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.groupD.server.repository;

import com.groupD.server.domain.entity.Member;
import com.groupD.server.domain.entity.MemberGroup;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface MemberGroupRepository extends JpaRepository<MemberGroup, Long> {
public List<MemberGroup> findAllByMember(Member member);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.groupD.server.repository;

import com.groupD.server.domain.dto.GroupRequest;
import com.groupD.server.domain.entity.Group;
import com.groupD.server.domain.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByEmail(String email);
//List<Group> findByEmail(String email);
Optional<Member> findByEmail(String email);
Optional<Member> findById(Long id);

}
2 changes: 2 additions & 0 deletions src/main/java/com/groupD/server/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ public SignInResponseDto signIn(String email, String password) {
return new SignInResponseDto(
member.getId(), member.getEmail(), member.getImageUrl(), member.getRole(), accessToken.getToken(), refreshToken.getToken(), accessToken.getExpireTime(), refreshToken.getExpireTime()
);


}
}
28 changes: 28 additions & 0 deletions src/main/java/com/groupD/server/service/GroupService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.groupD.server.service;

import com.groupD.server.domain.dto.GroupRequest;
import com.groupD.server.domain.entity.Group;
import com.groupD.server.repository.GroupRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class GroupService {
private final GroupRepository groupRepository;
public void write(GroupRequest request){
Group group = Group.builder()
.id(request.getId())
.code(request.getCode())
.title(request.getTitle())
.date(request.getDate())
.category(request.getCategory())
.manage(request.getManage())
.content(request.getContent())
.build();
groupRepository.save(group);
}
}
Loading

0 comments on commit ba80b06

Please sign in to comment.