Skip to content

Commit

Permalink
Merge pull request #50 from kakao-tech-campus-2nd-step3/week9
Browse files Browse the repository at this point in the history
weekly: 9주차 작업 중간 병합
  • Loading branch information
5win authored Oct 30, 2024
2 parents cbf6965 + 674ff15 commit dddbd18
Show file tree
Hide file tree
Showing 58 changed files with 1,264 additions and 343 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/prod-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Prod-CI

on:
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build with Gradle Wrapper
run: ./gradlew build

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

run: |
aws s3 sync build s3://gamja-bongsa
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

Expand All @@ -34,6 +33,11 @@ dependencies {
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'
implementation 'org.hibernate.validator:hibernate-validator'

// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.12.6'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/gamsa/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@ConfigurationPropertiesScan
@EnableJpaAuditing
@SpringBootApplication
public class Application {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/gamsa/activity/constant/Category.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gamsa.activity.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -15,4 +17,28 @@ public enum Category {
OTHER_ACTIVITIES("기타 활동");

private final String name;

@JsonCreator
public static Category fromValues(String value) {
for (Category category : Category.values()) {
if (category.getName().equals(value)) {
return category;
}
}
throw new IllegalArgumentException("Unknown value: " + value);
}

public static Category fromValuesForSlice(String value) {
for (Category category : Category.values()) {
if (category.getName().equals(value)) {
return category;
}
}
return null; // QueryDSL 에서는 null일 경우 필터링에서 제외하므로 null 반환 허용
}

@JsonValue
public String toValue() {
return this.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class ActivityController {

@GetMapping
public Slice<ActivityFindSliceResponse> findSlice(
@RequestParam(required = false) Category category,
@RequestParam(required = false) String category,
@RequestParam(required = false) Integer sidoGunguCode,
@RequestParam(required = false) Integer sidoCode,
@RequestParam(defaultValue = "false") boolean teenPossibleOnly,
@RequestParam(defaultValue = "false") boolean beforeDeadlineOnly,
Pageable pageable) {

ActivityFilterRequest request = ActivityFilterRequest.builder()
.category(category)
.category(Category.fromValuesForSlice(category))
.sidoGunguCode(sidoGunguCode)
.sidoCode(sidoCode)
.teenPossibleOnly(teenPossibleOnly)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gamsa.activity.controller;

import com.gamsa.activity.constant.Category;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/activities/categories")
public class CategoryController {

@GetMapping
public List<Category> findAllCategories() {
return List.of(Category.values());
}
}
49 changes: 25 additions & 24 deletions src/main/java/com/gamsa/activity/dto/ActivitySaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import com.gamsa.activity.domain.Activity;
import com.gamsa.activity.domain.District;
import com.gamsa.activity.domain.Institute;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;

@Getter
@Builder
@RequiredArgsConstructor
Expand Down Expand Up @@ -38,27 +39,27 @@ public class ActivitySaveRequest {

public Activity toModel(Institute institute, District sidoGungu) {
return Activity.builder()
.actId(actId)
.actTitle(actTitle)
.actLocation(actLocation)
.description(description)
.noticeStartDate(noticeStartDate)
.noticeEndDate(noticeEndDate)
.actStartDate(actStartDate)
.actEndDate(actEndDate)
.actStartTime(actStartTime)
.actEndTime(actEndTime)
.recruitTotalNum(recruitTotalNum)
.adultPossible(adultPossible)
.teenPossible(teenPossible)
.groupPossible(groupPossible)
.actWeek(actWeek)
.actManager(actManager)
.actPhone(actPhone)
.url(url)
.category(category)
.institute(institute)
.sidoGungu(sidoGungu)
.build();
.actId(actId)
.actTitle(actTitle)
.actLocation(actLocation)
.description(description)
.noticeStartDate(noticeStartDate)
.noticeEndDate(noticeEndDate)
.actStartDate(actStartDate)
.actEndDate(actEndDate)
.actStartTime(actStartTime)
.actEndTime(actEndTime)
.recruitTotalNum(recruitTotalNum)
.adultPossible(adultPossible)
.teenPossible(teenPossible)
.groupPossible(groupPossible)
.actWeek(actWeek)
.actManager(actManager)
.actPhone(actPhone)
.url(url)
.category(category)
.institute(institute)
.sidoGungu(sidoGungu)
.build();
}
}
}
27 changes: 0 additions & 27 deletions src/main/java/com/gamsa/auth/SecurityConfig.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/java/com/gamsa/avatar/constant/AgeRange.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gamsa.avatar.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -11,4 +13,19 @@ public enum AgeRange {
ADULT("성인");

private final String name;

@JsonCreator
public static AgeRange fromValue(String value) {
for (AgeRange ageRange : AgeRange.values()) {
if (ageRange.name.equals(value)) {
return ageRange;
}
}
throw new IllegalArgumentException("Unknown value: " + value);
}

@JsonValue
public String toValue() {
return this.name;
}
}
19 changes: 18 additions & 1 deletion src/main/java/com/gamsa/avatar/constant/Experienced.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package com.gamsa.avatar.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Experienced {
NOVICE("초심자"),
INTERMIDIATE("중급자"),
INTERMEDIATE("중급자"),
EXPERT("상급자");

private final String name;

@JsonCreator
public static Experienced fromValue(String value) {
for (Experienced level : Experienced.values()) {
if (level.name.equals(value)) {
return level;
}
}
throw new IllegalArgumentException("Unknown value: " + value);
}

@JsonValue
public String toValue() {
return this.name;
}
}
42 changes: 29 additions & 13 deletions src/main/java/com/gamsa/avatar/controller/AvatarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,54 @@
import com.gamsa.avatar.dto.AvatarFindResponse;
import com.gamsa.avatar.dto.AvatarSaveRequest;
import com.gamsa.avatar.service.AvatarService;
import com.gamsa.common.utils.ExtractUserIdFromJwt;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/avatar")
@RequestMapping("/api/v1/avatars")
public class AvatarController {

private final AvatarService avatarService;

@PostMapping
public ResponseEntity<String> saveAvatar(@RequestBody AvatarSaveRequest saveRequest) {
avatarService.save(saveRequest);
public ResponseEntity<String> saveAvatar(@RequestBody AvatarSaveRequest saveRequest,
HttpServletRequest request) {

Long userId = ExtractUserIdFromJwt.extract(request);
avatarService.save(saveRequest, userId);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping("{avatar-id}")
public AvatarFindResponse getAvatar(@PathVariable Long avatarId) {
return avatarService.findById(avatarId);
@GetMapping
public AvatarFindResponse getAvatar(HttpServletRequest request) {

Long userId = ExtractUserIdFromJwt.extract(request);
return avatarService.findByUserId(userId);
}

@PutMapping("{avatar-id}")
public ResponseEntity<String> updateAvatar(@PathVariable Long avatarId, @RequestBody AvatarSaveRequest saveRequest) {
avatarService.update(avatarId, saveRequest);
@PutMapping
public ResponseEntity<String> updateAvatar(@RequestBody AvatarSaveRequest saveRequest,
HttpServletRequest request) {
Long userId = ExtractUserIdFromJwt.extract(request);
avatarService.update(saveRequest, userId);
return new ResponseEntity<>(HttpStatus.OK);
}

@DeleteMapping("{avatar-Id}")
public ResponseEntity<String> deleteAvatar(@PathVariable Long avatarId) {
avatarService.delete(avatarId);
@DeleteMapping
public ResponseEntity<String> deleteAvatar(HttpServletRequest request) {
Long userId = ExtractUserIdFromJwt.extract(request);
avatarService.delete(userId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/gamsa/avatar/domain/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gamsa.avatar.constant.AgeRange;
import com.gamsa.avatar.constant.Experienced;
import com.gamsa.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,6 +12,7 @@
@AllArgsConstructor
public class Avatar {
private Long avatarId;
private User user;
private Long avatarExp;
private Long avatarLevel;
private String nickname;
Expand Down
Loading

0 comments on commit dddbd18

Please sign in to comment.