SKE-60 getCompetition method

This commit is contained in:
Przemysław Stawujak 2019-01-02 12:41:26 +01:00
parent cca78cdcc8
commit 3b82ed8111
8 changed files with 259 additions and 3 deletions

View File

@ -1 +1,3 @@
<div id="competition-detail-area">
<p>Szczegóły konkursu</p> <p>Szczegóły konkursu</p>
</div>

View File

@ -3,6 +3,9 @@ import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/app-component-base'; import { AppComponentBase } from '@shared/app-component-base';
import { Subscription } from 'rxjs/Rx'; import { Subscription } from 'rxjs/Rx';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { mergeMap } from 'rxjs/operators';
import { finalize } from 'rxjs/operators';
import { CompetitionServiceProxy, CompetitionDto } from '@shared/service-proxies/service-proxies';
@Component({ @Component({
templateUrl: './competition-detail.component.html', templateUrl: './competition-detail.component.html',
@ -14,19 +17,35 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn
private paramSubscription: Subscription; private paramSubscription: Subscription;
public competitionId: number; public competitionId: number;
public competition: CompetitionDto = null;
public competitionDetailAreaId: string = 'competition-detail-area';
constructor( constructor(
injector: Injector, injector: Injector,
private route: ActivatedRoute, private route: ActivatedRoute,
private _competitionService: CompetitionServiceProxy,
) { ) {
super(injector); super(injector);
} }
public ngOnInit() { public ngOnInit() {
this.competition = new CompetitionDto();
this.getCompetition();
}
private getCompetition(): void {
this.paramSubscription = this.route.params this.paramSubscription = this.route.params
.subscribe(params => { .pipe(mergeMap(params => {
this.competitionId = +params['id']; this.competitionId = +params['id'];
console.log('competitionId: ' + this.competitionId) console.log('competitionId: ' + this.competitionId);
this.setBusy(this.competitionDetailAreaId);
const competitionDetailStream = this._competitionService
.getCompetition(this.competitionId)
.pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); }))
return competitionDetailStream
})).subscribe((result: CompetitionDto) => {
this.competition = result;
console.log(this.competition);
}); });
} }

View File

@ -273,6 +273,61 @@ export class CompetitionServiceProxy {
} }
return _observableOf<number>(<any>null); return _observableOf<number>(<any>null);
} }
/**
* @competitionId (optional)
* @return Success
*/
getCompetition(competitionId: number | null | undefined): Observable<CompetitionDto> {
let url_ = this.baseUrl + "/api/services/app/Competition/GetCompetition?";
if (competitionId !== undefined)
url_ += "competitionId=" + encodeURIComponent("" + competitionId) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processGetCompetition(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processGetCompetition(<any>response_);
} catch (e) {
return <Observable<CompetitionDto>><any>_observableThrow(e);
}
} else
return <Observable<CompetitionDto>><any>_observableThrow(response_);
}));
}
protected processGetCompetition(response: HttpResponseBase): Observable<CompetitionDto> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(<any>response).error instanceof Blob ? (<any>response).error : undefined;
let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }};
if (status === 200) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? CompetitionDto.fromJS(resultData200) : new CompetitionDto();
return _observableOf(result200);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf<CompetitionDto>(<any>null);
}
} }
@Injectable() @Injectable()
@ -2195,6 +2250,7 @@ export class CompetitionDto implements ICompetitionDto {
maxClass: number | undefined; maxClass: number | undefined;
creationTime: moment.Moment | undefined; creationTime: moment.Moment | undefined;
creatorName: string | undefined; creatorName: string | undefined;
questions: QuestionDto[] | undefined;
id: number | undefined; id: number | undefined;
constructor(data?: ICompetitionDto) { constructor(data?: ICompetitionDto) {
@ -2217,6 +2273,11 @@ export class CompetitionDto implements ICompetitionDto {
this.maxClass = data["maxClass"]; this.maxClass = data["maxClass"];
this.creationTime = data["creationTime"] ? moment(data["creationTime"].toString()) : <any>undefined; this.creationTime = data["creationTime"] ? moment(data["creationTime"].toString()) : <any>undefined;
this.creatorName = data["creatorName"]; this.creatorName = data["creatorName"];
if (data["questions"] && data["questions"].constructor === Array) {
this.questions = [];
for (let item of data["questions"])
this.questions.push(QuestionDto.fromJS(item));
}
this.id = data["id"]; this.id = data["id"];
} }
} }
@ -2239,6 +2300,11 @@ export class CompetitionDto implements ICompetitionDto {
data["maxClass"] = this.maxClass; data["maxClass"] = this.maxClass;
data["creationTime"] = this.creationTime ? this.creationTime.toISOString() : <any>undefined; data["creationTime"] = this.creationTime ? this.creationTime.toISOString() : <any>undefined;
data["creatorName"] = this.creatorName; data["creatorName"] = this.creatorName;
if (this.questions && this.questions.constructor === Array) {
data["questions"] = [];
for (let item of this.questions)
data["questions"].push(item.toJSON());
}
data["id"] = this.id; data["id"] = this.id;
return data; return data;
} }
@ -2261,6 +2327,125 @@ export interface ICompetitionDto {
maxClass: number | undefined; maxClass: number | undefined;
creationTime: moment.Moment | undefined; creationTime: moment.Moment | undefined;
creatorName: string | undefined; creatorName: string | undefined;
questions: QuestionDto[] | undefined;
id: number | undefined;
}
export class QuestionDto implements IQuestionDto {
name: string | undefined;
competitionId: number | undefined;
questionOptions: QuestionOptionDto[] | undefined;
id: number | undefined;
constructor(data?: IQuestionDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(data?: any) {
if (data) {
this.name = data["name"];
this.competitionId = data["competitionId"];
if (data["questionOptions"] && data["questionOptions"].constructor === Array) {
this.questionOptions = [];
for (let item of data["questionOptions"])
this.questionOptions.push(QuestionOptionDto.fromJS(item));
}
this.id = data["id"];
}
}
static fromJS(data: any): QuestionDto {
data = typeof data === 'object' ? data : {};
let result = new QuestionDto();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["name"] = this.name;
data["competitionId"] = this.competitionId;
if (this.questionOptions && this.questionOptions.constructor === Array) {
data["questionOptions"] = [];
for (let item of this.questionOptions)
data["questionOptions"].push(item.toJSON());
}
data["id"] = this.id;
return data;
}
clone(): QuestionDto {
const json = this.toJSON();
let result = new QuestionDto();
result.init(json);
return result;
}
}
export interface IQuestionDto {
name: string | undefined;
competitionId: number | undefined;
questionOptions: QuestionOptionDto[] | undefined;
id: number | undefined;
}
export class QuestionOptionDto implements IQuestionOptionDto {
name: string | undefined;
questionId: number | undefined;
isAnswer: boolean | undefined;
id: number | undefined;
constructor(data?: IQuestionOptionDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(data?: any) {
if (data) {
this.name = data["name"];
this.questionId = data["questionId"];
this.isAnswer = data["isAnswer"];
this.id = data["id"];
}
}
static fromJS(data: any): QuestionOptionDto {
data = typeof data === 'object' ? data : {};
let result = new QuestionOptionDto();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["name"] = this.name;
data["questionId"] = this.questionId;
data["isAnswer"] = this.isAnswer;
data["id"] = this.id;
return data;
}
clone(): QuestionOptionDto {
const json = this.toJSON();
let result = new QuestionOptionDto();
result.init(json);
return result;
}
}
export interface IQuestionOptionDto {
name: string | undefined;
questionId: number | undefined;
isAnswer: boolean | undefined;
id: number | undefined; id: number | undefined;
} }

View File

@ -1,7 +1,9 @@
using Abp.Authorization; using Abp.Authorization;
using Abp.Domain.Repositories; using Abp.Domain.Repositories;
using Abp.Domain.Uow; using Abp.Domain.Uow;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using SystemKonkursow.Competition.CompetitionCategory.Dto; using SystemKonkursow.Competition.CompetitionCategory.Dto;
@ -91,5 +93,20 @@ namespace SystemKonkursow.Competition.CompetitionCategory
return newCompetitionId; return newCompetitionId;
} }
[AbpAuthorize]
public CompetitionDto GetCompetition(int competitionId)
{
var competition = _competitionRepository.GetAll()
.Include(t => t.Creator)
.Include(t => t.Questions)
.ThenInclude(t => t.QuestionOptions)
.FirstOrDefault(t => t.Id == competitionId);
var mappedObject = ObjectMapper.Map<CompetitionDto>(competition);
return mappedObject;
}
} }
} }

View File

@ -19,6 +19,9 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName)); .ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName));
CreateMap<CreateCompetitionDto, Domain.Competition>(); CreateMap<CreateCompetitionDto, Domain.Competition>();
CreateMap<Domain.Competition, CompetitionDto>()
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Creator.UserName));
} }
} }
} }

View File

@ -1,5 +1,6 @@
using Abp.Application.Services.Dto; using Abp.Application.Services.Dto;
using System; using System;
using System.Collections.Generic;
namespace SystemKonkursow.Competition.CompetitionCategory.Dto namespace SystemKonkursow.Competition.CompetitionCategory.Dto
{ {
@ -22,5 +23,7 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto
public DateTime CreationTime { get; set; } public DateTime CreationTime { get; set; }
public string CreatorName { get; set; } public string CreatorName { get; set; }
public List<QuestionDto> Questions { get; set; }
} }
} }

View File

@ -0,0 +1,14 @@
using Abp.Application.Services.Dto;
using System.Collections.Generic;
namespace SystemKonkursow.Competition.CompetitionCategory.Dto
{
public class QuestionDto : EntityDto<int>
{
public string Name { get; set; }
public long CompetitionId { get; set; }
public List<QuestionOptionDto> QuestionOptions { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using Abp.Application.Services.Dto;
namespace SystemKonkursow.Competition.CompetitionCategory.Dto
{
public class QuestionOptionDto : EntityDto<int>
{
public string Name { get; set; }
public int QuestionId { get; set; }
public bool IsAnswer { get; set; }
}
}