Skip to content

Commit

Permalink
shit
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh committed Nov 25, 2023
2 parents 2d7bb5c + a11c7cf commit 9801d1e
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 8 deletions.

This file was deleted.

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

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.sopt.sopkerton.common.exception.ProgramSuccess;
import org.sopt.sopkerton.program.domain.exception.ProgramSuccess;
import org.sopt.sopkerton.common.response.ApiResponse;
import org.sopt.sopkerton.program.dto.response.ProgramListResponse;
import org.sopt.sopkerton.program.service.ProgramService;
Expand Down Expand Up @@ -37,4 +37,16 @@ public ResponseEntity<ApiResponse<List<ProgramListResponse>>> programListViewByS
ApiResponse.success(ProgramSuccess.PROGRAM_LIST_VIEW_SUCCESS, programListByStatus)
);
}

@GetMapping("/detail")
public ResponseEntity<ApiResponse> orderProgramDetail(
@RequestParam("programId") Long programId
) {
Object programDetail = programService.getProgramDetail(1L, programId);
return ResponseEntity
.status(ProgramSuccess.PROGRAM_DETAIL_VIEW_SUCCESS.getHttpStatus())
.body(
ApiResponse.success(ProgramSuccess.PROGRAM_DETAIL_VIEW_SUCCESS, programDetail)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sopt.sopkerton.program.domain.exception;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.ErrorBase;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
public enum ProgramError implements ErrorBase {
PROGRAM_NOT_FOUND(HttpStatus.NOT_FOUND, "Can not found Program."),

;

private final HttpStatus status;
private final String errorMessage;
@Override
public int getHttpStatusCode() {
return this.status.value();
}

@Override
public HttpStatus getHttpStatus() {
return this.status;
}

@Override
public String getErrorMessage() {
return this.errorMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.sopkerton.program.domain.exception;

import org.sopt.sopkerton.common.exception.base.ExceptionBase;

public class ProgramException extends ExceptionBase {
public ProgramException(ProgramError errorBase) {
super(errorBase);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.sopt.sopkerton.common.exception;
package org.sopt.sopkerton.program.domain.exception;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.SuccessBase;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
public enum ProgramSuccess implements SuccessBase {
PROGRAM_LIST_VIEW_SUCCESS(HttpStatus.OK, "Get Program List View Data Successful.")
PROGRAM_LIST_VIEW_SUCCESS(HttpStatus.OK, "Get Program List View Data Successful."),
PROGRAM_DETAIL_VIEW_SUCCESS(HttpStatus.OK, "Get Program Detail View Data Successful.")
;

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.sopt.sopkerton.program.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;

public abstract class ProgramDetailResponse {

public record VolunteerDetail(
@JsonProperty("imageUrl")
String imageUrl,
@JsonProperty("content")
String content,
@JsonProperty("organizationName")
String organizationName,
@JsonProperty("registerAt")
String registerAt,
@JsonProperty("hour")
int hour,
@JsonProperty("isApply")
boolean isApply
) {
}

public record EmploymentDetail(
@JsonProperty("imageUrl")
String imageUrl,
@JsonProperty("content")
String content,
@JsonProperty("organizationName")
String organizationName,
@JsonProperty("registerAt")
String registerAt,
@JsonProperty("salary")
int salary,
@JsonProperty("isApply")
boolean isApply
) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.sopkerton.program.infrastructure;

import java.util.List;

import org.sopt.sopkerton.program.domain.Program;
import org.sopt.sopkerton.program.domain.Status;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -13,4 +14,5 @@ public interface ProgramRepository extends JpaRepository<Program, Long> {
List<Program> findAllByProgramType(@Param("type")String programType);

List<Program> findAllByStatus(Status status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@
import lombok.RequiredArgsConstructor;
import org.sopt.sopkerton.program.domain.Program;
import org.sopt.sopkerton.program.domain.Status;
import org.sopt.sopkerton.program.domain.exception.ProgramError;
import org.sopt.sopkerton.program.domain.exception.ProgramException;
import org.sopt.sopkerton.program.dto.response.ProgramDetailResponse;
import org.sopt.sopkerton.program.dto.response.ProgramListResponse;
import org.sopt.sopkerton.program.infrastructure.ProgramRepository;
import org.sopt.sopkerton.user.domain.Apply;
import org.sopt.sopkerton.user.domain.enums.ApplyStatus;
import org.sopt.sopkerton.user.infrastructure.ApplyRepository;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProgramService {
private static final String VOLUNTEER_TYPE = "VOLUNTEERING";
private static final String EMPLOYMENT_TYPE = "EMPLOYMENT";

private final ProgramRepository programRepository;
private final ApplyRepository applyRepository;

public List<ProgramListResponse> getProgramListByProgramType(String programType) {
List<Program> programs = programRepository.findAllByProgramType(programType);
Expand Down Expand Up @@ -48,10 +58,40 @@ public List<ProgramListResponse> getStatusDoneProgramList() {
return programListResponses;
}

public Object getProgramDetail(Long userId, Long programId) {
Program program = programRepository.findById(programId)
.orElseThrow(() -> new ProgramException(ProgramError.PROGRAM_NOT_FOUND));
Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId).get();
boolean isApply = convertToIsApply(apply.getIsApply());
if (program.getType().equals(VOLUNTEER_TYPE)) {
return new ProgramDetailResponse.VolunteerDetail(
program.getImageUrl(),
program.getContent(),
program.getOrganizationName(),
formatToLocalDate(program.getRegisterAt()),
program.getVolunteerHours(),
isApply
);
}
if (program.getType().equals(EMPLOYMENT_TYPE)){
return new ProgramDetailResponse.EmploymentDetail(
program.getImageUrl(),
program.getContent(),
program.getOrganizationName(),
formatToLocalDate(program.getRegisterAt()),
program.getSalary(),
isApply
);
}
return null;
}

private String formatToLocalDate(LocalDateTime localDateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM월 dd일");
return localDateTime.format(formatter);
}


private boolean convertToIsApply(ApplyStatus status) {
return status.equals(ApplyStatus.APPLY);
}
}
29 changes: 29 additions & 0 deletions src/main/java/org/sopt/sopkerton/user/domain/Apply.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sopt.sopkerton.user.domain;

import jakarta.persistence.*;
import lombok.*;
import org.sopt.sopkerton.common.domain.BaseEntity;
import org.sopt.sopkerton.user.domain.enums.ApplyStatus;

@Getter
@Entity
@Table(schema = "skt-t1-app", name = "applies")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
public class Apply extends BaseEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@Column(name = "user_id", nullable = false)
Long userId;

@Column(name = "program_id", nullable = false)
Long programId;

@Column(name = "is_apply", nullable = false)
@Enumerated(value = EnumType.STRING)
ApplyStatus isApply;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.sopkerton.user.domain.enums;

public enum ApplyStatus {

APPLY, UNAPPLY

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.sopkerton.user.infrastructure;

import org.sopt.sopkerton.user.domain.Apply;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface ApplyRepository extends JpaRepository<Apply, Long> {

Optional<Apply> findByUserIdAndProgramId(Long userId, Long programId);
}

0 comments on commit 9801d1e

Please sign in to comment.